Implemented ccl_pquery to convert from CCL tree to prefix query.
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 20 Dec 1999 15:20:13 +0000 (15:20 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 20 Dec 1999 15:20:13 +0000 (15:20 +0000)
include/yaz/yaz-ccl.h
zutil/pquery.c
zutil/yaz-ccl.c

index 2ef4fb9..ba80bbb 100644 (file)
@@ -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,
  *
  * 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 $
  * 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
  * Improved installation. Moved header files to include/yaz.
  *
  * Revision 1.8  1997/09/01 08:49:54  adam
@@ -56,6 +59,7 @@
 #include <yaz/proto.h>
 #include <yaz/ccl.h>
 #include <yaz/odr.h>
 #include <yaz/proto.h>
 #include <yaz/ccl.h>
 #include <yaz/odr.h>
+#include <yaz/yaz-util.h>
 
 #ifdef __cplusplus
 extern "C" {
 
 #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 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
 }
 
 #ifdef __cplusplus
 }
index fa3d249..6f35004 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: pquery.c,v $
  * 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
  * 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;
 {
     Z_RPNStructure *sz;
     const char *cp;
+    int i, attrtype;
 
     sz = (Z_RPNStructure *)odr_malloc (o, sizeof(*sz));
     switch (li->query_look)
 
     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;
         }
             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,
         lex (li);
         return
             rpn_structure (li, o, proto, num_attr, max_attr, attr_list,
index c5ba47a..2740396 100644 (file)
@@ -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 $
  * 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
  * 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);
 }
         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);
+    };
+}