From: Adam Dickmeiss Date: Mon, 20 Dec 1999 15:20:13 +0000 (+0000) Subject: Implemented ccl_pquery to convert from CCL tree to prefix query. X-Git-Tag: YAZ.1.8~301 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=e347736dafbae4bbd1eec56e3577353662aee332 Implemented ccl_pquery to convert from CCL tree to prefix query. --- diff --git a/include/yaz/yaz-ccl.h b/include/yaz/yaz-ccl.h index 2ef4fb9..ba80bbb 100644 --- a/include/yaz/yaz-ccl.h +++ b/include/yaz/yaz-ccl.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, Index Data. + * Copyright (c) 1995-1999, Index Data. * * Permission to use, copy, modify, distribute, and sell this software and * its documentation, in whole or in part, for any purpose, is hereby granted, @@ -24,7 +24,10 @@ * OF THIS SOFTWARE. * * $Log: yaz-ccl.h,v $ - * Revision 1.1 1999-11-30 13:47:11 adam + * Revision 1.2 1999-12-20 15:20:13 adam + * Implemented ccl_pquery to convert from CCL tree to prefix query. + * + * Revision 1.1 1999/11/30 13:47:11 adam * Improved installation. Moved header files to include/yaz. * * Revision 1.8 1997/09/01 08:49:54 adam @@ -56,6 +59,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -63,6 +67,7 @@ extern "C" { YAZ_EXPORT Z_RPNQuery *ccl_rpn_query (ODR o, struct ccl_rpn_node *p); YAZ_EXPORT Z_AttributesPlusTerm *ccl_scan_query (ODR o, struct ccl_rpn_node *p); +YAZ_EXPORT void ccl_pquery (WRBUF w, struct ccl_rpn_node *p); #ifdef __cplusplus } diff --git a/zutil/pquery.c b/zutil/pquery.c index fa3d249..6f35004 100644 --- a/zutil/pquery.c +++ b/zutil/pquery.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: pquery.c,v $ - * Revision 1.2 1999-11-30 13:47:12 adam + * Revision 1.3 1999-12-20 15:20:13 adam + * Implemented ccl_pquery to convert from CCL tree to prefix query. + * + * Revision 1.2 1999/11/30 13:47:12 adam * Improved installation. Moved header files to include/yaz. * * Revision 1.1 1999/06/08 10:10:16 adam @@ -399,6 +402,7 @@ static Z_RPNStructure *rpn_structure (struct lex_info *li, ODR o, { Z_RPNStructure *sz; const char *cp; + int i, attrtype; sz = (Z_RPNStructure *)odr_malloc (o, sizeof(*sz)); switch (li->query_look) @@ -445,9 +449,19 @@ static Z_RPNStructure *rpn_structure (struct lex_info *li, ODR o, else attr_set[num_attr] = VAL_NONE; } - attr_list[2*num_attr] = atoi (li->lex_buf); - attr_list[2*num_attr+1] = atoi (cp+1); - num_attr++; + attrtype = atoi (li->lex_buf); + for (i = 0; i < num_attr; i++) + if (attrtype == attr_list[2*i]) + { + attr_list[2*i+1] = atoi (cp+1); + break; + } + if (i == num_attr) + { + attr_list[2*num_attr] = attrtype; + attr_list[2*num_attr+1] = atoi (cp+1); + num_attr++; + } lex (li); return rpn_structure (li, o, proto, num_attr, max_attr, attr_list, diff --git a/zutil/yaz-ccl.c b/zutil/yaz-ccl.c index c5ba47a..2740396 100644 --- a/zutil/yaz-ccl.c +++ b/zutil/yaz-ccl.c @@ -1,10 +1,13 @@ /* - * Copyright (c) 1996-1998, Index Data. + * Copyright (c) 1996-1999, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: yaz-ccl.c,v $ - * Revision 1.3 1999-11-30 13:47:12 adam + * Revision 1.4 1999-12-20 15:20:13 adam + * Implemented ccl_pquery to convert from CCL tree to prefix query. + * + * Revision 1.3 1999/11/30 13:47:12 adam * Improved installation. Moved header files to include/yaz. * * Revision 1.2 1999/06/16 12:00:08 adam @@ -232,3 +235,59 @@ Z_AttributesPlusTerm *ccl_scan_query (ODR o, struct ccl_rpn_node *p) return NULL; return ccl_rpn_term (o, p); } + +static void ccl_pquery_complex (WRBUF w, struct ccl_rpn_node *p) +{ + switch (p->kind) + { + case CCL_RPN_AND: + wrbuf_puts (w, "@and "); + break; + case CCL_RPN_OR: + wrbuf_puts(w, "@or "); + break; + case CCL_RPN_NOT: + wrbuf_puts(w, "@not "); + break; + case CCL_RPN_PROX: + wrbuf_puts(w, "@prox 0 2 0 1 known 2 "); + break; + default: + assert(0); + }; + ccl_pquery(w, p->u.p[0]); + ccl_pquery(w, p->u.p[1]); +} + +void ccl_pquery (WRBUF w, struct ccl_rpn_node *p) +{ + struct ccl_rpn_attr *att; + + switch (p->kind) + { + case CCL_RPN_AND: + case CCL_RPN_OR: + case CCL_RPN_NOT: + case CCL_RPN_PROX: + ccl_pquery_complex (w, p); + break; + case CCL_RPN_SET: + wrbuf_puts (w, "@set "); + wrbuf_puts (w, p->u.setname); + wrbuf_puts (w, " "); + break; + case CCL_RPN_TERM: + for (att = p->u.t.attr_list; att; att = att->next) + { + char tmpattr[128]; + sprintf(tmpattr, "@attr %d=%d ", att->type, att->value); + wrbuf_puts (w, tmpattr); + } + wrbuf_puts (w, "{"); + wrbuf_puts (w, p->u.t.term); + wrbuf_puts (w, "} "); + break; + default: + assert (0); + }; +}