/*
- * 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,
* 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
#include <yaz/proto.h>
#include <yaz/ccl.h>
#include <yaz/odr.h>
+#include <yaz/yaz-util.h>
#ifdef __cplusplus
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
}
* 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
{
Z_RPNStructure *sz;
const char *cp;
+ int i, attrtype;
sz = (Z_RPNStructure *)odr_malloc (o, sizeof(*sz));
switch (li->query_look)
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,
/*
- * 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
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);
+ };
+}