| 1 |
NAME |
| 2 |
CQL::Parser - compiles CQL strings into parse trees of Node subtypes. |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
use CQL::Parser; |
| 6 |
my $parser = CQL::Parser->new(); |
| 7 |
my $root = $parser->parse( $cql ); |
| 8 |
|
| 9 |
DESCRIPTION |
| 10 |
CQL::Parser provides a mechanism to parse Common Query Language (CQL) |
| 11 |
statements. The best description of CQL comes from the CQL homepage at |
| 12 |
the Library of Congress <http://www.loc.gov/z3950/agency/zing/cql/> |
| 13 |
|
| 14 |
CQL is a formal language for representing queries to information |
| 15 |
retrieval systems such as web indexes, bibliographic catalogs and museum |
| 16 |
collection information. The CQL design objective is that queries be |
| 17 |
human readable and human writable, and that the language be intuitive |
| 18 |
while maintaining the expressiveness of more complex languages. |
| 19 |
|
| 20 |
A CQL statement can be as simple as a single keyword, or as complicated |
| 21 |
as a set of compoenents indicating search indexes, relations, relational |
| 22 |
modifiers, proximity clauses and boolean logic. CQL::Parser will parse |
| 23 |
CQL statements and return the root node for a tree of nodes which |
| 24 |
describes the CQL statement. This data structure can then be used by a |
| 25 |
client application to analyze the statement, and possibly turn it into a |
| 26 |
query for a local repository. |
| 27 |
|
| 28 |
Each CQL component in the tree inherits from CQL::Node and can be one of |
| 29 |
the following: CQL::AndNode, CQL::NotNode, CQL::OrNode, CQL::ProxNode, |
| 30 |
CQL::TermNode, CQL::PrefixNode. See the documentation for those modules |
| 31 |
for their respective APIs. |
| 32 |
|
| 33 |
Here are some examples of CQL statements: |
| 34 |
|
| 35 |
* george |
| 36 |
|
| 37 |
* dc.creator=george |
| 38 |
|
| 39 |
* dc.creator="George Clinton" |
| 40 |
|
| 41 |
* clinton and funk |
| 42 |
|
| 43 |
* clinton and parliament and funk |
| 44 |
|
| 45 |
* (clinton or bootsy) and funk |
| 46 |
|
| 47 |
* dc.creator="clinton" and dc.date="1976" |
| 48 |
|
| 49 |
METHODS |
| 50 |
new() |
| 51 |
parse( $query ) |
| 52 |
Pass in a CQL query and you'll get back the root node for the CQL parse |
| 53 |
tree. If the CQL is invalid an exception will be thrown. |
| 54 |
|
| 55 |
parseSafe( $query ) |
| 56 |
Pass in a CQL query and you'll get back the root node for the CQL parse |
| 57 |
tree. If the CQL is invalid, an error code from the SRU Diagnostics List |
| 58 |
will be returned. |
| 59 |
|
| 60 |
XCQL |
| 61 |
CQL has an XML representation which you can generate from a CQL parse |
| 62 |
tree. Just call the toXCQL() method on the root node you get back from a |
| 63 |
call to parse(). |
| 64 |
|
| 65 |
ERRORS AND DIAGNOSTICS |
| 66 |
As mentioned above, a CQL syntax error will result in an exception being |
| 67 |
thrown. So if you have any doubts about the CQL that you are parsing you |
| 68 |
should wrap the call to parse() in an eval block, and check $@ |
| 69 |
afterwards to make sure everything went ok. |
| 70 |
|
| 71 |
eval { |
| 72 |
my $node = $parser->parse( $cql ); |
| 73 |
}; |
| 74 |
if ( $@ ) { |
| 75 |
print "uhoh, exception $@\n"; |
| 76 |
} |
| 77 |
|
| 78 |
If you'd like to see blow by blow details while your CQL is being parsed |
| 79 |
set $CQL::DEBUG equal to 1, and you will get details on STDERR. This is |
| 80 |
useful if the parse tree is incorrect and you want to locate where |
| 81 |
things are going wrong. Hopefully this won't happen, but if it does |
| 82 |
please notify the author. |
| 83 |
|
| 84 |
TODO |
| 85 |
* toYourEngineHere() please feel free to add functionality and send in |
| 86 |
patches! |
| 87 |
|
| 88 |
THANKYOUS |
| 89 |
CQL::Parser is essentially a Perl port of Mike Taylor's cql-java package |
| 90 |
http://zing.z3950.org/cql/java/. Mike and IndexData were kind enough to |
| 91 |
allow the author to write this port, and to make it available under the |
| 92 |
terms of the Artistic License. Thanks Mike! |
| 93 |
|
| 94 |
The CQL::Lexer package relies heavily on Stevan Little's excellent |
| 95 |
String::Tokenizer. Thanks Stevan! |
| 96 |
|
| 97 |
CQL::Parser was developed as a component of the Ockham project, which is |
| 98 |
funded by the National Science Foundation. See http://www.ockham.org for |
| 99 |
more information about Ockham. |
| 100 |
|
| 101 |
AUTHOR |
| 102 |
* Ed Summers - ehs at pobox dot com |
| 103 |
|
| 104 |
* Brian Cassidy - bricas at cpan dot org |
| 105 |
|
| 106 |
* Wilbert Hengst - W.Hengst at uva dot nl |
| 107 |
|
| 108 |
COPYRIGHT AND LICENSE |
| 109 |
Copyright 2004-2009 by Ed Summers |
| 110 |
|
| 111 |
This library is free software; you can redistribute it and/or modify it |
| 112 |
under the same terms as Perl itself. |
| 113 |
|