/* CCL find (to rpn conversion)
* Europagate, 1995
*
- * $Id: cclfind.c,v 1.3 2004-08-11 20:13:36 adam Exp $
+ * $Id: cclfind.c,v 1.4 2004-09-29 20:37:50 adam Exp $
*
* Old Europagate log:
*
case CCL_RPN_PROX:
ccl_rpn_delete (rpn->u.p[0]);
ccl_rpn_delete (rpn->u.p[1]);
+ ccl_rpn_delete (rpn->u.p[2]);
break;
}
xfree (rpn);
return search_term_x(cclp, qa, list, 0);
}
-static struct ccl_rpn_node *qualifiers2 (CCL_parser cclp,
- struct ccl_rpn_attr **ap)
+static
+struct ccl_rpn_node *qualifiers_order (CCL_parser cclp,
+ struct ccl_rpn_attr **ap, char *attset)
{
- char *attset;
- int rel;
+ int rel = 0;
+ struct ccl_rpn_node *p;
- if (!qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_ORDER, &attset))
- {
- /* unordered relation */
- struct ccl_rpn_node *p;
- if (KIND != CCL_TOK_EQ)
- {
- cclp->error_code = CCL_ERR_EQ_EXPECTED;
- return NULL;
- }
- ADVANCE;
- if (KIND == CCL_TOK_LP)
- {
- ADVANCE;
- if (!(p = find_spec (cclp, ap)))
- {
- return NULL;
- }
- if (KIND != CCL_TOK_RP)
- {
- cclp->error_code = CCL_ERR_RP_EXPECTED;
- ccl_rpn_delete (p);
- return NULL;
- }
- ADVANCE;
- }
- else
- p = search_terms (cclp, ap);
- return p;
- }
- /* ordered relation ... */
- rel = 0;
if (cclp->look_token->len == 1)
{
if (cclp->look_token->name[0] == '<')
rel = 6;
}
if (!rel)
+ {
cclp->error_code = CCL_ERR_BAD_RELATION;
- else
+ return NULL;
+ }
+ ADVANCE; /* skip relation */
+ if (rel == 3 &&
+ qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, 0))
{
- struct ccl_rpn_node *p;
+ /* allow - inside term and treat it as range _always_ */
+ /* relation is =. Extract "embedded" - to separate terms */
+ if (KIND == CCL_TOK_TERM)
+ {
+ int i;
+ for (i = 0; i<cclp->look_token->len; i++)
+ {
+ if (cclp->look_token->name[i] == '-')
+ break;
+ }
+
+ if (cclp->look_token->len > 1 && i == 0)
+ { /* -xx*/
+ struct ccl_token *ntoken = ccl_token_add (cclp->look_token);
+
+ ntoken->kind = CCL_TOK_TERM;
+ ntoken->name = cclp->look_token->name + 1;
+ ntoken->len = cclp->look_token->len - 1;
+
+ cclp->look_token->len = 1;
+ cclp->look_token->name = "-";
+ }
+ else if (cclp->look_token->len > 1 && i == cclp->look_token->len-1)
+ { /* xx- */
+ struct ccl_token *ntoken = ccl_token_add (cclp->look_token);
+
+ ntoken->kind = CCL_TOK_TERM;
+ ntoken->name = "-";
+ ntoken->len = 1;
+
+ (cclp->look_token->len)--;
+ }
+ else if (cclp->look_token->len > 2 && i < cclp->look_token->len)
+ { /* xx-yy */
+ struct ccl_token *ntoken1 = ccl_token_add (cclp->look_token);
+ struct ccl_token *ntoken2 = ccl_token_add (ntoken1);
+
+ ntoken1->kind = CCL_TOK_TERM; /* generate - */
+ ntoken1->name = "-";
+ ntoken1->len = 1;
+
+ ntoken2->kind = CCL_TOK_TERM; /* generate yy */
+ ntoken2->name = cclp->look_token->name + (i+1);
+ ntoken2->len = cclp->look_token->len - (i+1);
+
+ cclp->look_token->len = i; /* adjust xx */
+ }
+ else if (i == cclp->look_token->len &&
+ cclp->look_token->next &&
+ cclp->look_token->next->kind == CCL_TOK_TERM &&
+ cclp->look_token->next->len > 1 &&
+ cclp->look_token->next->name[0] == '-')
+
+ { /* xx -yy */
+ /* we _know_ that xx does not have - in it */
+ struct ccl_token *ntoken = ccl_token_add (cclp->look_token);
+
+ ntoken->kind = CCL_TOK_TERM; /* generate - */
+ ntoken->name = "-";
+ ntoken->len = 1;
+
+ (ntoken->next->name)++; /* adjust yy */
+ (ntoken->next->len)--;
+ }
+ }
+ }
- ADVANCE; /* skip relation */
- if (KIND == CCL_TOK_TERM &&
- cclp->look_token->next && cclp->look_token->next->len == 1 &&
- cclp->look_token->next->name[0] == '-')
- {
- struct ccl_rpn_node *p1;
- if (!(p1 = search_term (cclp, ap)))
- return NULL;
- ADVANCE; /* skip '-' */
- if (KIND == CCL_TOK_TERM) /* = term - term ? */
- {
- struct ccl_rpn_node *p2;
-
- if (!(p2 = search_term (cclp, ap)))
- {
- ccl_rpn_delete (p1);
- return NULL;
- }
- p = mk_node (CCL_RPN_AND);
- p->u.p[0] = p1;
- add_attr_numeric (p1, attset, CCL_BIB1_REL, 4);
- p->u.p[1] = p2;
- add_attr_numeric (p2, attset, CCL_BIB1_REL, 2);
- return p;
- }
- else /* = term - */
- {
- add_attr_numeric (p1, attset, CCL_BIB1_REL, 4);
- return p1;
- }
- }
- else if (cclp->look_token->len == 1 &&
- cclp->look_token->name[0] == '-') /* = - term ? */
- {
- ADVANCE;
- if (!(p = search_term (cclp, ap)))
- return NULL;
- add_attr_numeric (p, attset, CCL_BIB1_REL, 2);
- return p;
- }
- else if (KIND == CCL_TOK_LP)
- {
- ADVANCE;
- if (!(p = find_spec (cclp, ap)))
- return NULL;
- if (KIND != CCL_TOK_RP)
- {
- cclp->error_code = CCL_ERR_RP_EXPECTED;
- ccl_rpn_delete (p);
- return NULL;
- }
- ADVANCE;
- return p;
- }
- else
- {
- if (!(p = search_terms (cclp, ap)))
- return NULL;
- add_attr_numeric (p, attset, CCL_BIB1_REL, rel);
- return p;
- }
- cclp->error_code = CCL_ERR_TERM_EXPECTED;
+ if (rel == 3 &&
+ KIND == CCL_TOK_TERM &&
+ cclp->look_token->next && cclp->look_token->next->len == 1 &&
+ cclp->look_token->next->name[0] == '-')
+ {
+ struct ccl_rpn_node *p1;
+ if (!(p1 = search_term (cclp, ap)))
+ return NULL;
+ ADVANCE; /* skip '-' */
+ if (KIND == CCL_TOK_TERM) /* = term - term ? */
+ {
+ struct ccl_rpn_node *p2;
+
+ if (!(p2 = search_term (cclp, ap)))
+ {
+ ccl_rpn_delete (p1);
+ return NULL;
+ }
+ p = mk_node (CCL_RPN_AND);
+ p->u.p[0] = p1;
+ add_attr_numeric (p1, attset, CCL_BIB1_REL, 4);
+ p->u.p[1] = p2;
+ add_attr_numeric (p2, attset, CCL_BIB1_REL, 2);
+ return p;
+ }
+ else /* = term - */
+ {
+ add_attr_numeric (p1, attset, CCL_BIB1_REL, 4);
+ return p1;
+ }
+ }
+ else if (rel == 3 &&
+ cclp->look_token->len == 1 &&
+ cclp->look_token->name[0] == '-') /* = - term ? */
+ {
+ ADVANCE;
+ if (!(p = search_term (cclp, ap)))
+ return NULL;
+ add_attr_numeric (p, attset, CCL_BIB1_REL, 2);
+ return p;
+ }
+ else if (KIND == CCL_TOK_LP)
+ {
+ ADVANCE;
+ if (!(p = find_spec (cclp, ap)))
+ return NULL;
+ if (KIND != CCL_TOK_RP)
+ {
+ cclp->error_code = CCL_ERR_RP_EXPECTED;
+ ccl_rpn_delete (p);
+ return NULL;
+ }
+ ADVANCE;
+ return p;
+ }
+ else
+ {
+ if (!(p = search_terms (cclp, ap)))
+ return NULL;
+ add_attr_numeric (p, attset, CCL_BIB1_REL, rel);
+ return p;
}
+ cclp->error_code = CCL_ERR_TERM_EXPECTED;
return NULL;
}
+static
+struct ccl_rpn_node *qualifiers2 (CCL_parser cclp, struct ccl_rpn_attr **ap)
+{
+ char *attset;
+ struct ccl_rpn_node *p;
+
+ if (qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_ORDER, &attset)
+ || qual_val_type(ap, CCL_BIB1_REL, CCL_BIB1_REL_PORDER, &attset))
+ return qualifiers_order(cclp, ap, attset);
+
+ /* unordered relation */
+ if (KIND != CCL_TOK_EQ)
+ {
+ cclp->error_code = CCL_ERR_EQ_EXPECTED;
+ return NULL;
+ }
+ ADVANCE;
+ if (KIND == CCL_TOK_LP)
+ {
+ ADVANCE;
+ if (!(p = find_spec (cclp, ap)))
+ {
+ return NULL;
+ }
+ if (KIND != CCL_TOK_RP)
+ {
+ cclp->error_code = CCL_ERR_RP_EXPECTED;
+ ccl_rpn_delete (p);
+ return NULL;
+ }
+ ADVANCE;
+ }
+ else
+ p = search_terms (cclp, ap);
+ return p;
+}
+
/*
* qualifiers1: Parse CCL qualifiers and search terms.
* cclp: CCL Parser
{
struct ccl_rpn_node *p;
-
-
cclp->look_token = list;
p = find_spec (cclp, NULL);
if (p && KIND != CCL_TOK_EOL)
/*
- * Copyright (c) 2002-2003, Index Data
+ * Copyright (c) 2002-2004, Index Data
* See the file LICENSE for details.
*
- * $Id: tstccl.c,v 1.3 2004-09-22 11:21:51 adam Exp $
+ * $Id: tstccl.c,v 1.4 2004-09-29 20:37:51 adam Exp $
*/
/* CCL test */
+#include <string.h>
#include <yaz/ccl.h>
struct ccl_tst {
{ "x1 and", 0},
{ "tix=x5", 0},
{ "spid%æserne", "@prox 0 1 0 2 k 2 @attr 4=2 @attr 1=1016 spid @attr 4=2 @attr 1=1016 æserne "},
+ { "date=1980", "@attr 2=3 1980 "},
+ { "date=234-1990", "@and @attr 2=4 234 @attr 2=2 1990 "},
+ { "date=234- 1990", "@and @attr 2=4 234 @attr 2=2 1990 "},
+ { "date=234 -1990", "@and @attr 2=4 234 @attr 2=2 1990 "},
+ { "date=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "},
+ { "date=-1980", "@attr 2=2 1980 "},
+ { "date=- 1980", "@attr 2=2 1980 "},
+ { "x=-1980", "@attr 2=3 -1980 "},
+ { "x=- 1980", "@attr 2=2 1980 "},
+ { "x= -1980", "@attr 2=3 -1980 "},
+ { "x=234-1990", "@attr 2=3 234-1990 "},
+ { "x=234 - 1990", "@and @attr 2=4 234 @attr 2=2 1990 "},
{0, 0}
};
-void tst1(int pass)
+void tst1(int pass, int *number_of_errors)
{
CCL_parser parser = ccl_parser_create ();
CCL_bibset bibset = ccl_qual_mk();
ccl_qual_fitem(bibset, "u=4 s=pw t=l,r", "ti");
ccl_qual_fitem(bibset, "1=1016 s=al,pw", "term");
ccl_qual_fitem(bibset, "1=/my/title", "dc.title");
+ ccl_qual_fitem(bibset, "r=r", "date");
+ ccl_qual_fitem(bibset, "r=o", "x");
break;
case 1:
strcpy(tstline, "ti u=4 s=pw t=l,r");
strcpy(tstline, "dc.title 1=/my/title");
ccl_qual_line(bibset, tstline);
+
+ strcpy(tstline, "date r=r # ordered relation");
+ ccl_qual_line(bibset, tstline);
+
+ strcpy(tstline, "x r=o # ordered relation");
+ ccl_qual_line(bibset, tstline);
break;
case 2:
ccl_qual_buf(bibset, "ti u=4 s=pw t=l,r\n"
"term 1=1016 s=al,pw\r\n"
"\n"
- "dc.title 1=/my/title\n");
+ "dc.title 1=/my/title\n"
+ "date r=r\n"
+ "x r=o\n"
+ );
break;
default:
exit(23);
printf ("Failed %s\n", query_str[i].query);
printf (" got:%s:\n", wrbuf_buf(wrbuf));
printf (" expected failure\n");
- exit(3);
+ (*number_of_errors)++;
}
else if (strcmp(wrbuf_buf(wrbuf), query_str[i].result))
{
printf ("Failed %s\n", query_str[i].query);
printf (" got:%s:\n", wrbuf_buf(wrbuf));
printf (" expected:%s:\n", query_str[i].result);
- exit(2);
+ (*number_of_errors)++;
}
ccl_rpn_delete(rpn);
wrbuf_free(wrbuf, 1);
printf ("Failed %s\n", query_str[i].query);
printf (" got failure\n");
printf (" expected:%s:\n", query_str[i].result);
- exit(4);
+ (*number_of_errors)++;
}
}
ccl_parser_destroy (parser);
int main(int argc, char **argv)
{
- tst1(0);
- tst1(1);
- tst1(2);
+ int number_of_errors = 0;
+ tst1(0, &number_of_errors);
+ if (number_of_errors)
+ exit(1);
+ tst1(1, &number_of_errors);
+ if (number_of_errors)
+ exit(1);
+ tst1(2, &number_of_errors);
+ if (number_of_errors)
+ exit(1);
exit(0);
}