Giter VIP home page Giter VIP logo

cql-java's Introduction

CQL-Java -- a free CQL parser and related tools, for Java

Introduction

CQL-Java is a Free Software project that provides:

  • A set of classes for representing a CQL parse tree (a base CQLNode class, CQLBooleanNode and its subclasses, CQLTermNode, etc.)
  • A CQLCompiler class (and its lexer) which builds a parse tree given a CQL query as input.
  • A selection of compiler back-ends to render out the parse tree as:
    • XCQL (the standard XML representation)
    • CQL (i.e. decompiling the parse-tree)
    • PQF (Yaz-style Prefix Query Format)
    • BER code for the Z39.50 Type-1 query
  • A random query generator, useful for testing.

CQL is "Common Query Language", a query language designed under the umbrella of the ZING initiative (Z39.59-International Next Generation). The official specification is at http://www.loc.gov/standards/sru/cql/ and there's more (and friendlier) information at http://zing.z3950.org/cql/index.html

XCQL is "XML CQL", a representation of CQL-equivalent queries in XML which is supposed to be easier to parse. The specification is at http://docs.oasis-open.org/search-ws/searchRetrieve/v1.0/os/schemas/xcql.xsd in the form of an XML Schema.

But if you didn't know that, why are you even reading this? :-)

What's What in this Distribution?

  • README.md -- This file
  • Changes -- History of releases
  • LGPL-2.1 -- The GNU lesser GPL (see below)
  • pom.xml -- Maven project file to control compilation.
  • src -- Source-code for the CQL-Java library and tests
  • target -- The compiled library file, cql-java.jar and javadoc
  • bin -- Simple shell-scripts to invoke CQL programs (parser/lexer/generator)
  • util -- Various testing and sanity-checking Perl scripts
  • etc -- Other files: PQF indexes, generator properties, etc.

Compilation and Installation

The build process is controlled by Maven so compilation is the standard:

mvn clean install

which generates build artifacts under target/.

"Installation" of this package would consist of putting the bin directory on your PATH and target/cql-java.jar on your CLASSPATH.

Synopsis

Using the test-harnesses:

$ CQLParser 'title=foo and author=(bar or baz)'
$ CQLParser -c 'title=foo and author=(bar or baz)'
$ CQLParser -p /etc/pqf.properties 'dc.title=foo and dc.author=bar'
$ CQLLexer 'title=foo and author=(bar or baz)'
	(not very interesting unless you're debugging)
$ CQLGenerator etc/generate.properties seed 18

Using the library in your own applications:

import org.z3950.zing.cql.*

// Building a parse-tree by hand
CQLNode n1 = new CQLTermNode("dc.author", new CQLRelation("="),
			     "kernighan");
CQLNode n2 = new CQLTermNode("dc.title", new CQLRelation("all"),
			     "elements style");
CQLNode root = new CQLAndNode(n1, n2);
System.out.println(root.toXCQL(0));

// Parsing a CQL query
CQLParser parser = new CQLParser();
CQLNode root = parser.parse("title=dinosaur");
System.out.print(root.toXCQL(0));
System.out.println(root.toCQL());
System.out.println(root.toPQF(config));
// ... where `config' specifies CQL-qualfier => Z-attr mapping

Description

See the automatically generated class documentation in the "target" subdirectory.

Author

Original code and documentation by Mike Taylor, Index Data [email protected] At present maintained by Jakub Skoczen, Index Data [email protected]

Please email us with bug-reports, wishlist items, patches, deployment stories and, of course, large cash donations.

Licence

The CQL-Java suite is Free Software, which is pretty much legally equivalent -- though not morally equivalent -- to Open Source. See http://www.gnu.org/philosophy/free-software-for-freedom.html for a detailed if somewhat one-sided discussion of the differences, and particularly of why Free Software is an important idea.

CQL-Java is distributed under version 2.1 of the LGPL (GNU LESSER GENERAL PUBLIC LICENSE). A copy of the licence is included in this distribution, as the file LGPL-2.1. This licence does not allow you to restrict the freedom of others to use derived versions of CQL-Java (i.e. you must share your enhancements), but does let you do pretty much anything else with it. In particular, you may deploy CQL-Java as a part of a non-free larger work.

See also

cql-java's People

Contributors

adamdickmeiss avatar dependabot[bot] avatar funkymalc avatar jakub-id avatar julianladisch avatar miketaylor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cql-java's Issues

Unpredictable escape sequences

The line here in the CQLLexer allows certain characters from being escaped:

The CQL spec says:

Double quotes enclosing a sequence of any characters except double quote (unless preceded by backslash ()). Backslash escapes the character following it. The resultant value includes all backslash characters except those releasing a double quote (this allows other systems to interpret the backslash character). The surrounding double quotes are not included.

I'm curious why those specific characters are included and how those characters mean that they release a double quote.

It is actually making it impossible for me to represent a Windows-style file path, for example:

file = some\\path\\in\\windows\.exe

This gets turned into:

file = some\\path\\in\\windows.exe

because the . character is not on that list.

I happen to have a regular expression interpreter following the CQL parse that needs the value to be file = some\\path\\in\\windows\.exe. If I know that the CQL parser is consistently escaping the following character, I could just pass in: file=some\\\\path\\\\in\\\\windows\\.exe or if it consistently ignores it: file=some\\path\\in\\windows\.exe.

Got CQLParseException when pass cql schema

Hello ,
what I need is a parser that starting from DDL (create, alter tables and other instructions) will get info about the schema into a java object.

Trying to use this library I'm getting CQLParseException:

Error parsing cql schema org.z3950.zing.cql.CQLParseException: expected boolean, got '('

Error parsing cql schema org.z3950.zing.cql.CQLParseException: expected index or term, got EOF

This library is suitable for this type of thing?
Thanks in advance

Inconsistent ParseException: foo bar.baz

All these four cql expressions result in the same parse tree when sent to new CQLParser().parse(cql).toXCQL():

foo bar
"foo bar"
cql.serverChoice=foo bar
cql.serverChoice="foo bar"

When sending these other four cql expressions only the two quoted work, the two unquoted result in CQLParseException: expected index or term, got EOF:

foo bar.baz
"foo bar.baz"
cql.serverChoice=foo bar.baz
cql.serverChoice="foo bar.baz"

This is inconsistent. Either accept all unquoted or no unquoted expressions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.