-// $Id: CQLGenerator.java,v 1.3 2002-11-03 16:49:38 mike Exp $
+// $Id: CQLGenerator.java,v 1.9 2007-07-03 15:41:35 mike Exp $
package org.z3950.zing.cql;
import java.util.Properties;
* the parser of your choice, and check that the XCQL it comes up with
* is the same what you got from your initial rendering.
* <P>
- * This code is based on the grammar in the <TT>Grammar</TT> file of
+ * This code is based on the same grammar as the <TT>CQLParser</TT> class in
* this distribution - there is a <TT>generate_<I>x</I>()</TT> method
* for each grammar element <I>X</I>.
*
- * @version $Id: CQLGenerator.java,v 1.3 2002-11-03 16:49:38 mike Exp $
+ * @version $Id: CQLGenerator.java,v 1.9 2007-07-03 15:41:35 mike Exp $
* @see <A href="http://zing.z3950.org/cql/index.html"
* >http://zing.z3950.org/cql/index.html</A>
*/
* [mandatory] A floating-point number between 0.0 and 1.0,
* indicating the probability for each <TT>search-clause</TT>
* node that it will be expanded into a full sub-query rather
- * than a <TT>[ qualifier relation ] term</TT> triplet.
+ * than an <TT>[ index relation ] term</TT> triplet.
* <P>
* </DD>
* <DT><TT>proxOp</TT></DT>
* method, or decompiled into CQL using its <TT>toCQL</TT>
* method.
*/
- public CQLNode generate() throws ParameterMissingException {
+ public CQLNode generate() throws MissingParameterException {
return generate_cql_query();
}
- private CQLNode generate_cql_query() throws ParameterMissingException {
+ private CQLNode generate_cql_query() throws MissingParameterException {
if (!maybe("complexQuery")) {
return generate_search_clause();
}
CQLNode node1 = generate_cql_query();
CQLNode node2 = generate_search_clause();
+ // ### should generate prefix-mapping nodes
if (maybe("proxOp")) {
// ### generate proximity nodes
} else {
switch (rnd.nextInt(3)) {
- case 0: return new CQLAndNode(node1, node2);
- case 1: return new CQLOrNode(node1, node2);
- case 2: return new CQLNotNode(node1, node2);
+ case 0: return new CQLAndNode(node1, node2, new ModifierSet("and"));
+ case 1: return new CQLOrNode (node1, node2, new ModifierSet("or"));
+ case 2: return new CQLNotNode(node1, node2, new ModifierSet("not"));
}
}
return generate_search_clause();
}
- private CQLNode generate_search_clause() throws ParameterMissingException {
+ private CQLNode generate_search_clause() throws MissingParameterException {
if (maybe("complexClause")) {
return generate_cql_query();
}
- // ### Should sometimes generate qualifier/relation-free terms
- String qualifier = generate_qualifier();
+ // ### Should sometimes generate index/relation-free terms
+ String index = generate_index();
CQLRelation relation = generate_relation();
String term = generate_term();
- return new CQLTermNode(qualifier, relation, term);
+ return new CQLTermNode(index, relation, term);
}
// ### Should probably be more configurable
- private String generate_qualifier() {
- String qualifier = ""; // shut up compiler warning
+ private String generate_index() {
+ String index = ""; // shut up compiler warning
if (rnd.nextInt(2) == 0) {
switch (rnd.nextInt(3)) {
- case 0: qualifier = "dc.author"; break;
- case 1: qualifier = "dc.title"; break;
- case 2: qualifier = "dc.subject"; break;
+ case 0: index = "dc.author"; break;
+ case 1: index = "dc.title"; break;
+ case 2: index = "dc.subject"; break;
}
} else {
switch (rnd.nextInt(4)) {
- case 0: qualifier = "bath.author"; break;
- case 1: qualifier = "bath.title"; break;
- case 2: qualifier = "bath.subject"; break;
- case 3: qualifier = "foo>bar"; break;
+ case 0: index = "bath.author"; break;
+ case 1: index = "bath.title"; break;
+ case 2: index = "bath.subject"; break;
+ case 3: index = "foo>bar"; break;
}
}
- return qualifier;
+ return index;
}
- private CQLRelation generate_relation() throws ParameterMissingException {
+ private CQLRelation generate_relation() throws MissingParameterException {
String base = generate_base_relation();
CQLRelation rel = new CQLRelation(base);
// ### should generate modifiers too
return rel;
}
- private String generate_base_relation() throws ParameterMissingException {
+ private String generate_base_relation() throws MissingParameterException {
if (maybe("equalsRelation")) {
return "=";
} else if (maybe("numericRelation")) {
return ""; // shut up compiler warning
}
- boolean maybe(String param) throws ParameterMissingException {
+ boolean maybe(String param) throws MissingParameterException {
String probability = params.getProperty(param);
if (probability == null)
- throw new ParameterMissingException(param);
+ throw new MissingParameterException(param);
double dice = rnd.nextDouble();
double threshhold = new Double(probability).doubleValue();
String configFile = args[0];
InputStream f = new FileInputStream(configFile);
if (f == null)
- throw new FileNotFoundException("getResourceAsStream(" +
- configFile + ")");
+ throw new FileNotFoundException(configFile);
Properties params = new Properties();
params.load(f);