From: Adam Dickmeiss Date: Sun, 6 Jan 2008 13:08:09 +0000 (+0000) Subject: CQL v1.2 functionality except sort. X-Git-Tag: YAZ.3.0.20~19 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=783114bd4cf6e26e1743ce131d3e7f00af63ec50 CQL v1.2 functionality except sort. Modify CQL parser and transform code to become more CQL 1.2 compliant. Default relation is '=' instead 'scr'. Relation for exact is == instead of 'exact'. Work on bug #609: HDCQL. --- diff --git a/etc/pqf.properties b/etc/pqf.properties index 8a700f5..fda24d5 100644 --- a/etc/pqf.properties +++ b/etc/pqf.properties @@ -1,4 +1,4 @@ -# $Id: pqf.properties,v 1.13 2006-09-20 10:12:29 mike Exp $ +# $Id: pqf.properties,v 1.14 2008-01-06 13:08:09 adam Exp $ # # Propeties file to drive org.z3950.zing.cql.CQLNode's toPQF() # back-end and the YAZ CQL-to-PQF converter. This specifies the @@ -12,7 +12,7 @@ # attributes. # Identifiers for prefixes used in this file. (index.*) -set.cql = info:srw/cql-context-set/1/cql-v1.1 +set.cql = info:srw/cql-context-set/1/cql-v1.2 set.rec = info:srw/cql-context-set/2/rec-1.1 set.dc = info:srw/cql-context-set/1/dc-v1.1 set.bath = http://zing.z3950.org/cql/bath/2.0/ diff --git a/src/cql.y b/src/cql.y index 20013cb..8daf2cb 100644 --- a/src/cql.y +++ b/src/cql.y @@ -1,4 +1,4 @@ -/* $Id: cql.y,v 1.15 2007-10-31 21:58:07 adam Exp $ +/* $Id: cql.y,v 1.16 2008-01-06 13:08:09 adam Exp $ Copyright (C) 2002-2006 Index Data ApS @@ -58,14 +58,13 @@ See the file LICENSE. %} %pure_parser -%token TERM AND OR NOT PROX GE LE NE -%expect 9 +%token DOTTERM TERM AND OR NOT PROX GE LE NE EXACT %% top: { $$.rel = cql_node_mk_sc(((CQL_parser) parm)->nmem, - "cql.serverChoice", "scr", 0); + "cql.serverChoice", "=", 0); ((CQL_parser) parm)->top = 0; } cqlQuery1 { cql_node_destroy($$.rel); @@ -80,10 +79,27 @@ cqlQuery1: cqlQuery } ; -cqlQuery: +cqlQuery: + scopedClause + | + '>' searchTerm '=' searchTerm { + $$.rel = $0.rel; + } cqlQuery { + $$.cql = cql_apply_prefix(((CQL_parser) parm)->nmem, + $6.cql, $2.buf, $4.buf); + } +| '>' searchTerm { + $$.rel = $0.rel; + } cqlQuery { + $$.cql = cql_apply_prefix(((CQL_parser) parm)->nmem, + $4.cql, 0, $2.buf); + } +; + +scopedClause: searchClause | - cqlQuery boolean modifiers { + scopedClause boolean modifiers { $$.rel = $0.rel; } searchClause { struct cql_node *cn = cql_node_mk_boolean(((CQL_parser) parm)->nmem, @@ -118,18 +134,6 @@ searchClause: $$.cql = $5.cql; cql_node_destroy($4.rel); } -| '>' searchTerm '=' searchTerm { - $$.rel = $0.rel; - } cqlQuery { - $$.cql = cql_apply_prefix(((CQL_parser) parm)->nmem, - $6.cql, $2.buf, $4.buf); - } -| '>' searchTerm { - $$.rel = $0.rel; - } cqlQuery { - $$.cql = cql_apply_prefix(((CQL_parser) parm)->nmem, - $4.cql, 0, $2.buf); - } ; /* unary NOT search TERM here .. */ @@ -160,6 +164,11 @@ modifiers '/' searchTerm mrelation searchTerm } ; +/* +extraTerms: + extraTerms TERM | ; +*/ + mrelation: '=' | '>' @@ -167,6 +176,7 @@ mrelation: | GE | LE | NE +| EXACT ; relation: @@ -176,7 +186,8 @@ relation: | GE | LE | NE -| TERM +| EXACT +| DOTTERM ; index: @@ -184,6 +195,7 @@ index: searchTerm: TERM +| DOTTERM | AND | OR | NOT @@ -244,7 +256,18 @@ int yylex(YYSTYPE *lval, void *vp) { int c1; putb(lval, cp, c); - if (c == '>') + if (c == '=') + { + c1 = cp->getbyte(cp->client_data); + if (c1 == '=') + { + putb(lval, cp, c1); + return EXACT; + } + else + cp->ungetbyte(c1, cp->client_data); + } + else if (c == '>') { c1 = cp->getbyte(cp->client_data); if (c1 == '=') @@ -287,47 +310,57 @@ int yylex(YYSTYPE *lval, void *vp) putb(lval, cp, c); } putb(lval, cp, 0); + return TERM; } else { - while (c != 0 && !strchr(" \n()=<>/", c)) - { - if (c == '\\') + int relation_like = 0; + while (c != 0 && !strchr(" \n()=<>/", c)) + { + if (c == '.') + relation_like = 1; + if (c == '\\') { putb(lval, cp, c); - c = cp->getbyte(cp->client_data); + c = cp->getbyte(cp->client_data); if (!c) break; } - putb(lval, cp, c); + putb(lval, cp, c); c = cp->getbyte(cp->client_data); - } + } putb(lval, cp, 0); #if YYDEBUG - printf ("got %s\n", lval->buf); + printf ("got %s\n", lval->buf); #endif - if (c != 0) - cp->ungetbyte(c, cp->client_data); - if (!cql_strcmp(lval->buf, "and")) + if (c != 0) + cp->ungetbyte(c, cp->client_data); + if (!cql_strcmp(lval->buf, "and")) { lval->buf = "and"; - return AND; + return AND; } - if (!cql_strcmp(lval->buf, "or")) + if (!cql_strcmp(lval->buf, "or")) { lval->buf = "or"; - return OR; + return OR; } - if (!cql_strcmp(lval->buf, "not")) + if (!cql_strcmp(lval->buf, "not")) { lval->buf = "not"; - return NOT; + return NOT; } - if (!cql_strcmp(lval->buf, "prox")) + if (!cql_strcmp(lval->buf, "prox")) { lval->buf = "prox"; - return PROX; + return PROX; } + if (!cql_strcmp(lval->buf, "all")) + relation_like = 1; + if (!cql_strcmp(lval->buf, "any")) + relation_like = 1; + if (relation_like) + return DOTTERM; } return TERM; } diff --git a/src/cqltransform.c b/src/cqltransform.c index 8411878..fa7da0e 100644 --- a/src/cqltransform.c +++ b/src/cqltransform.c @@ -1,4 +1,4 @@ -/* $Id: cqltransform.c,v 1.30 2007-12-20 22:45:37 adam Exp $ +/* $Id: cqltransform.c,v 1.31 2008-01-06 13:08:09 adam Exp $ Copyright (C) 1995-2007, Index Data ApS Index Data Aps @@ -185,6 +185,18 @@ int cql_pr_attr_uri(cql_transform_t ct, const char *category, { if (!res) res = cql_lookup_property(ct, category, prefix, eval); + /* we have some aliases for some relations unfortunately.. */ + if (!res && !prefix && !strcmp(category, "relation")) + { + if (!strcmp(val, "==")) + res = cql_lookup_property(ct, category, prefix, "exact"); + if (!strcmp(val, "=")) + res = cql_lookup_property(ct, category, prefix, "eq"); + if (!strcmp(val, "<=")) + res = cql_lookup_property(ct, category, prefix, "le"); + if (!strcmp(val, ">=")) + res = cql_lookup_property(ct, category, prefix, "ge"); + } if (!res) res = cql_lookup_property(ct, category, prefix, "*"); } @@ -572,18 +584,7 @@ void cql_transform_r(cql_transform_t ct, } } cql_pr_attr(ct, "always", 0, 0, pr, client_data, 0); - if (cn->u.st.relation && !cql_strcmp(cn->u.st.relation, "=")) - cql_pr_attr(ct, "relation", "eq", "scr", - pr, client_data, 19); - else if (cn->u.st.relation && !cql_strcmp(cn->u.st.relation, "<=")) - cql_pr_attr(ct, "relation", "le", "scr", - pr, client_data, 19); - else if (cn->u.st.relation && !cql_strcmp(cn->u.st.relation, ">=")) - cql_pr_attr(ct, "relation", "ge", "scr", - pr, client_data, 19); - else - cql_pr_attr(ct, "relation", cn->u.st.relation, "eq", - pr, client_data, 19); + cql_pr_attr(ct, "relation", cn->u.st.relation, 0, pr, client_data, 19); cql_pr_attr(ct, "structure", cn->u.st.relation, 0, pr, client_data, 24); if (cn->u.st.relation && !cql_strcmp(cn->u.st.relation, "all")) diff --git a/src/cqlutil.c b/src/cqlutil.c index 7550535..836d840 100644 --- a/src/cqlutil.c +++ b/src/cqlutil.c @@ -1,4 +1,4 @@ -/* $Id: cqlutil.c,v 1.11 2007-01-03 08:42:15 adam Exp $ +/* $Id: cqlutil.c,v 1.12 2008-01-06 13:08:09 adam Exp $ Copyright (C) 1995-2007, Index Data ApS Index Data Aps @@ -86,7 +86,7 @@ struct cql_node *cql_node_mk_boolean(NMEM nmem, const char *op) const char *cql_uri(void) { - return "info:srw/cql-context-set/1/cql-v1.1"; + return "info:srw/cql-context-set/1/cql-v1.2"; } struct cql_node *cql_apply_prefix(NMEM nmem, diff --git a/test/cql/1.1.out b/test/cql/1.1.out index 04e6f3f..48aee99 100644 --- a/test/cql/1.1.out +++ b/test/cql/1.1.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = cat diff --git a/test/cql/1.10.out b/test/cql/1.10.out index a44a871..c5ac7f6 100644 --- a/test/cql/1.10.out +++ b/test/cql/1.10.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = all diff --git a/test/cql/1.11.out b/test/cql/1.11.out index 6aa73cd..88da9eb 100644 --- a/test/cql/1.11.out +++ b/test/cql/1.11.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = prox diff --git a/test/cql/1.2.out b/test/cql/1.2.out index 04e6f3f..48aee99 100644 --- a/test/cql/1.2.out +++ b/test/cql/1.2.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = cat diff --git a/test/cql/1.3.out b/test/cql/1.3.out index 216c15c..af191d3 100644 --- a/test/cql/1.3.out +++ b/test/cql/1.3.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = comp.os.linux diff --git a/test/cql/1.4.out b/test/cql/1.4.out index 9b2ab93..ea3207a 100644 --- a/test/cql/1.4.out +++ b/test/cql/1.4.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = ml:element diff --git a/test/cql/1.5.out b/test/cql/1.5.out index 4ce7bc2..6ec410e 100644 --- a/test/cql/1.5.out +++ b/test/cql/1.5.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = <xml:element> diff --git a/test/cql/1.6.out b/test/cql/1.6.out index d7786cb..da69755 100644 --- a/test/cql/1.6.out +++ b/test/cql/1.6.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = = diff --git a/test/cql/1.7.out b/test/cql/1.7.out index 29742fc..851a5c1 100644 --- a/test/cql/1.7.out +++ b/test/cql/1.7.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = prox/distance<3/unit=word diff --git a/test/cql/1.8.out b/test/cql/1.8.out index 04e6f3f..48aee99 100644 --- a/test/cql/1.8.out +++ b/test/cql/1.8.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = cat diff --git a/test/cql/1.9.out b/test/cql/1.9.out index b8cbb85..d41b39e 100644 --- a/test/cql/1.9.out +++ b/test/cql/1.9.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = dog diff --git a/test/cql/2.12.out b/test/cql/2.12.out index a648cc5..fc3287e 100644 --- a/test/cql/2.12.out +++ b/test/cql/2.12.out @@ -1,7 +1,7 @@ dc.title - scr + = fish frog chicken diff --git a/test/cql/2.2.out b/test/cql/2.2.out index 2b78ddf..fd085e3 100644 --- a/test/cql/2.2.out +++ b/test/cql/2.2.out @@ -1,7 +1,7 @@ title - exact + == fish diff --git a/test/cql/3.1.out b/test/cql/3.1.out index de0acae..fc1b678 100644 --- a/test/cql/3.1.out +++ b/test/cql/3.1.out @@ -6,7 +6,7 @@ cql.serverChoice - scr + = cat @@ -15,7 +15,7 @@ cql.serverChoice - scr + = dog diff --git a/test/cql/3.2.out b/test/cql/3.2.out index f5dba0b..55ae66a 100644 --- a/test/cql/3.2.out +++ b/test/cql/3.2.out @@ -6,7 +6,7 @@ cql.serverChoice - scr + = cat @@ -15,7 +15,7 @@ cql.serverChoice - scr + = fish diff --git a/test/cql/3.3.out b/test/cql/3.3.out index 895ee06..2f4f6c0 100644 --- a/test/cql/3.3.out +++ b/test/cql/3.3.out @@ -6,7 +6,7 @@ cql.serverChoice - scr + = cat @@ -15,7 +15,7 @@ cql.serverChoice - scr + = frog diff --git a/test/cql/3.4.out b/test/cql/3.4.out index 895ee06..2f4f6c0 100644 --- a/test/cql/3.4.out +++ b/test/cql/3.4.out @@ -6,7 +6,7 @@ cql.serverChoice - scr + = cat @@ -15,7 +15,7 @@ cql.serverChoice - scr + = frog diff --git a/test/cql/3.5.out b/test/cql/3.5.out index 4627440..9ad0700 100644 --- a/test/cql/3.5.out +++ b/test/cql/3.5.out @@ -6,7 +6,7 @@ cql.serverChoice - scr + = cat @@ -15,7 +15,7 @@ cql.serverChoice - scr + = fish food diff --git a/test/cql/3.6.out b/test/cql/3.6.out index 049b9d8..7b8dae8 100644 --- a/test/cql/3.6.out +++ b/test/cql/3.6.out @@ -6,7 +6,7 @@ cql.serverChoice - scr + = xml @@ -15,7 +15,7 @@ cql.serverChoice - scr + = prox/// diff --git a/test/cql/3.7.out b/test/cql/3.7.out index 0a62182..5e0076e 100644 --- a/test/cql/3.7.out +++ b/test/cql/3.7.out @@ -6,7 +6,7 @@ cql.serverChoice - scr + = fred @@ -15,7 +15,7 @@ cql.serverChoice - scr + = any diff --git a/test/cql/3.8.out b/test/cql/3.8.out index d971224..f080d4b 100644 --- a/test/cql/3.8.out +++ b/test/cql/3.8.out @@ -6,7 +6,7 @@ cql.serverChoice - scr + = fred @@ -15,7 +15,7 @@ cql.serverChoice - scr + = all diff --git a/test/cql/3.9.out b/test/cql/3.9.out index 9b7f604..4f3ade7 100644 --- a/test/cql/3.9.out +++ b/test/cql/3.9.out @@ -16,7 +16,7 @@ cql.serverChoice - scr + = a @@ -25,7 +25,7 @@ cql.serverChoice - scr + = b @@ -36,7 +36,7 @@ cql.serverChoice - scr + = c @@ -47,7 +47,7 @@ cql.serverChoice - scr + = d diff --git a/test/cql/4.2.out b/test/cql/4.2.out index 682adcd..0dcb869 100644 --- a/test/cql/4.2.out +++ b/test/cql/4.2.out @@ -20,7 +20,7 @@ cql.serverChoice - scr + = and diff --git a/test/cql/5.1.out b/test/cql/5.1.out index b42c733..406d103 100644 --- a/test/cql/5.1.out +++ b/test/cql/5.1.out @@ -6,7 +6,7 @@ cql.serverChoice - scr + = cat @@ -15,7 +15,7 @@ cql.serverChoice - scr + = hat diff --git a/test/cql/5.2.out b/test/cql/5.2.out index 323a671..53fa314 100644 --- a/test/cql/5.2.out +++ b/test/cql/5.2.out @@ -21,7 +21,7 @@ cql.serverChoice - scr + = cat @@ -30,7 +30,7 @@ cql.serverChoice - scr + = hat diff --git a/test/cql/5.3.out b/test/cql/5.3.out index aa8ab2d..25c5377 100644 --- a/test/cql/5.3.out +++ b/test/cql/5.3.out @@ -13,7 +13,7 @@ cql.serverChoice - scr + = cat @@ -22,7 +22,7 @@ cql.serverChoice - scr + = hat diff --git a/test/cql/5.4.out b/test/cql/5.4.out index a08a64e..a6e2198 100644 --- a/test/cql/5.4.out +++ b/test/cql/5.4.out @@ -13,7 +13,7 @@ cql.serverChoice - scr + = fish food @@ -22,7 +22,7 @@ cql.serverChoice - scr + = and diff --git a/test/cql/5.5.out b/test/cql/5.5.out index 9212ca4..a59341f 100644 --- a/test/cql/5.5.out +++ b/test/cql/5.5.out @@ -22,7 +22,7 @@ cql.serverChoice - scr + = exact diff --git a/test/cql/5.6.out b/test/cql/5.6.out index b202f00..b05d320 100644 --- a/test/cql/5.6.out +++ b/test/cql/5.6.out @@ -18,7 +18,7 @@ dc.author - exact + == jones diff --git a/test/cql/5.7.out b/test/cql/5.7.out index 3a1f51b..57f4037 100644 --- a/test/cql/5.7.out +++ b/test/cql/5.7.out @@ -11,7 +11,7 @@ cql.serverChoice - scr + = a @@ -20,7 +20,7 @@ cql.serverChoice - scr + = b diff --git a/test/cql/5.8.out b/test/cql/5.8.out index d406c53..1dc3602 100644 --- a/test/cql/5.8.out +++ b/test/cql/5.8.out @@ -13,7 +13,7 @@ cql.serverChoice - scr + = a @@ -22,7 +22,7 @@ cql.serverChoice - scr + = b diff --git a/test/cql/6.1.out b/test/cql/6.1.out index 6e59421..0dcc5fb 100644 --- a/test/cql/6.1.out +++ b/test/cql/6.1.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = cat^ diff --git a/test/cql/6.2.out b/test/cql/6.2.out index 04e6f3f..48aee99 100644 --- a/test/cql/6.2.out +++ b/test/cql/6.2.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = cat diff --git a/test/cql/6.3.out b/test/cql/6.3.out index b3f98bd..68b2dd5 100644 --- a/test/cql/6.3.out +++ b/test/cql/6.3.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = ^cat says \"fish\" diff --git a/test/cql/6.4.out b/test/cql/6.4.out index 4c5cf95..ee38b0e 100644 --- a/test/cql/6.4.out +++ b/test/cql/6.4.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = cat*fish diff --git a/test/cql/6.5.out b/test/cql/6.5.out index d82b932..dc59539 100644 --- a/test/cql/6.5.out +++ b/test/cql/6.5.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = cat?dog diff --git a/test/cql/6.6.out b/test/cql/6.6.out index 4328f85..2a0cd96 100644 --- a/test/cql/6.6.out +++ b/test/cql/6.6.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = ^cat*fishdog\"horse? diff --git a/test/cql/7.1.out b/test/cql/7.1.out index e9baec9..3338a9f 100644 --- a/test/cql/7.1.out +++ b/test/cql/7.1.out @@ -16,7 +16,7 @@ cql.serverChoice - scr + = cat @@ -25,7 +25,7 @@ cql.serverChoice - scr + = dog @@ -36,7 +36,7 @@ cql.serverChoice - scr + = horse @@ -47,7 +47,7 @@ cql.serverChoice - scr + = frog diff --git a/test/cql/7.2.out b/test/cql/7.2.out index 8df4539..1324889 100644 --- a/test/cql/7.2.out +++ b/test/cql/7.2.out @@ -11,7 +11,7 @@ cql.serverChoice - scr + = cat @@ -20,7 +20,7 @@ cql.serverChoice - scr + = dog @@ -36,7 +36,7 @@ cql.serverChoice - scr + = horse @@ -45,7 +45,7 @@ cql.serverChoice - scr + = frog diff --git a/test/cql/7.3.out b/test/cql/7.3.out index 3a057fd..202af98 100644 --- a/test/cql/7.3.out +++ b/test/cql/7.3.out @@ -11,7 +11,7 @@ cql.serverChoice - scr + = cat @@ -25,7 +25,7 @@ cql.serverChoice - scr + = horse @@ -34,7 +34,7 @@ cql.serverChoice - scr + = frog @@ -47,7 +47,7 @@ cql.serverChoice - scr + = chips diff --git a/test/cql/9.1.out b/test/cql/9.1.out index eac3a28..ff98d6f 100644 --- a/test/cql/9.1.out +++ b/test/cql/9.1.out @@ -16,7 +16,7 @@ cql.serverChoice - scr + = any @@ -25,7 +25,7 @@ cql.serverChoice - scr + = all:stem @@ -36,7 +36,7 @@ all - exact + == any diff --git a/test/cql/9.2.out b/test/cql/9.2.out index eb0d4a9..dd7c8f0 100644 --- a/test/cql/9.2.out +++ b/test/cql/9.2.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = any diff --git a/test/cql/9.3.out b/test/cql/9.3.out index ee798ea..1eeff16 100644 --- a/test/cql/9.3.out +++ b/test/cql/9.3.out @@ -1,7 +1,7 @@ cql.serverChoice - scr + = diff --git a/test/cqlsample b/test/cqlsample index 3fba953..f08ff47 100644 --- a/test/cqlsample +++ b/test/cqlsample @@ -1,4 +1,4 @@ -# $Id: cqlsample,v 1.2 2004-03-10 18:50:56 adam Exp $ +# $Id: cqlsample,v 1.3 2008-01-06 13:08:09 adam Exp $ # CQL queries for testing. # from http://www.loc.gov/z3950/agency/zing/cql/sample-queries.html # Simple Term @@ -18,7 +18,7 @@ prox # Index Relation Term title = "fish" -title exact fish +title == fish title any fish title all fish title > 9 @@ -28,7 +28,7 @@ dc.title any/stem fish dc.fish all/stem/fuzzy "fish chips" (title any frog) ((dc.title any/stem "frog pond")) -dc.title scr "fish frog chicken" +dc.title = "fish frog chicken" dc.title =/rel.algorithm=CORI squid creator any/f.foo/b.bar>1 "sanderson taylor" @@ -56,7 +56,7 @@ cat prox/distance=3/unit=word/ordered hat cat prox/distance<3 hat "fish food" prox/unit=sentence and title all "chips frog" prox/distance<=5 exact -(dc.author exact "jones" prox/distance>5/unit=element title >= "smith") +(dc.author == "jones" prox/distance>5/unit=element title >= "smith") a and/rel.SumOfScores b a and/rel.algorithm=CORI b @@ -83,7 +83,7 @@ cat?dog # Lame Searches -any or all:stem and all exact any prox prox=fuzzy +any or all:stem and all == any prox prox=fuzzy (((((((((any))))))))) "" > any > any = exact any > any