Class CQLGenerator
Why is that useful? Mainly to produce test-cases for CQL parsers
(including the CQLParser class in this package): you can
generate a random search tree, render it to XCQL and remember the
result. Then decompile the tree to CQL, feed the generated CQL to
the parser of your choice, and check that the XCQL it comes up with
is the same what you got from your initial rendering.
This code is based on the same grammar as the CQLParser class in
this distribution - there is a generate_x() method
for each grammar element X.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCQLGenerator(Properties params) Creates a new CQL generator with the specified parameters. -
Method Summary
-
Constructor Details
-
CQLGenerator
Creates a new CQL generator with the specified parameters.- Parameters:
params- APropertiestable containing configuration parameters for the queries to be generated by this generator.Recognised parameters are:
seed-
If specified, this is a
longused to seed the random number generator, so that the CQL generator can be run repeatably, giving the same results each time. If it's omitted, then no seed is explicitly specified, and the results of each run will be different (so long as you don't run it more that 2^32 times :-) complexQuery-
[mandatory] A floating-point number between 0.0 and 1.0,
indicating the probability for each
cql-querynode that it will be expanded into a ``complex query'' (cql-query boolean search-clause) rather than asearch-clause. complexClause-
[mandatory] A floating-point number between 0.0 and 1.0,
indicating the probability for each
search-clausenode that it will be expanded into a full sub-query rather than an[ index relation ] termtriplet. proxOp-
[mandatory] A floating-point number between 0.0 and 1.0,
indicating the probability that each boolean operator will
be chosen to be proximity operation; otherwise, the three
simpler boolean operations (
and,orandnot) are chosen with equal probability. equalsRelation-
[mandatory] A floating-point number between 0.0 and 1.0,
indicating the probability that each relation will be chosen
to be
=- this is treated as a special case, since it's likely to be by far the most common relation in ``real life'' searches. numericRelation- q
[mandatory] A floating-point number between 0.0 and 1.0,
indicating the probability that a relation, having chosen
not to be
=, is instead chosen to be one of the six numeric relations (<,>,<=,>=,<>and=).
-
-
Method Details
-
generate
Generates a single random CQL query.Uses the parameters that were associated with the generator when it was created. You are free to create as many random queries as you wish from a single generator; each of them will use the same parameters.
- Returns:
- A
CQLNodethat is the root of the generated tree. That tree may be rendered in XCQL using itstoXCQL()method, or decompiled into CQL using itstoCQLmethod. - Throws:
MissingParameterException
-
main
A simple test-harness for the generator.It generates a single random query using the parameters specified in a nominated properties file, plus any additional name value pairs provided on the command-line, and decompiles it into CQL which is written to standard output.
For example,
java org.z3950.zing.cql.CQLGenerator etc/generate.properties seed 18398, where the filegenerate.propertiescontains:complexQuery=0.4 complexClause=0.4 equalsRelation=0.5 numericRelation=0.7 proxOp=0.0
yields:((dc.author = "<xml.element>") or (bath.title = cat)) and (dc.subject >= "the complete dinosaur")- Parameters:
configFile- The name of a properties file from which to read the configuration parameters (see above).name- The name of a configuration parameter.value- The value to assign to the configuration parameter named in the immediately preceding command-line argument.- Throws:
Exception
-