final
[SXSI/XMLTree.git] / XMLTree.h
index 2e9e222..1268cb6 100644 (file)
--- a/XMLTree.h
+++ b/XMLTree.h
@@ -21,7 +21,7 @@
 \r
 #ifndef XMLTREE_H_\r
 #define XMLTREE_H_\r
-#include "TextCollection/TextCollection.h"\r
+#include "TextCollection/TextCollectionBuilder.h"\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include <cstring>\r
@@ -37,6 +37,7 @@
 #include <alphabet_mapper.h>\r
 #include <static_sequence.h>\r
 using SXSI::TextCollection;\r
+using SXSI::TextCollectionBuilder;\r
 \r
 \r
 // this constant is used to efficiently compute the child operation in the tree\r
@@ -88,7 +89,9 @@ class XMLTree {
         uint tags_blen, tags_len;\r
 \r
    /** The texts in the XML document */\r
+   TextCollectionBuilder *TextBuilder;\r
    TextCollection *Text;\r
+\r
    /** The texts in the XML document (cached for faster display) */\r
    vector<string> CachedText;\r
    \r
@@ -125,7 +128,7 @@ public:
         void print_stats();\r
 \r
    /** Data structure constructor */\r
-   XMLTree() {finished = false; initialized = false;}; \r
+   XMLTree() {finished = false; initialized = false; Text = 0; TextBuilder = 0; }; \r
  \r
    /** Data structure destructor */\r
    ~XMLTree();\r
@@ -150,6 +153,9 @@ public:
   \r
    /** IsChild(x,y): returns whether node x is parent of node y. */\r
    bool IsChild(treeNode x, treeNode y);\r
+\r
+   /** IsChild(x,y): returns whether node x is the first child of its parent */\r
+   bool IsFirstChild(treeNode x);\r
    \r
    /** NumChildren(x): number of children of node x. Constant time with the \r
     * data structure of Sadakane. */\r
@@ -188,8 +194,13 @@ public:
     * Very fast in BP. */\r
    treeNode FirstChild(treeNode x);\r
    \r
+   /** LastChild(x): returns the last child of node x. \r
+    * Implemented by Kim naively. */\r
+   treeNode LastChild(treeNode x);\r
+\r
    /** NextSibling(x): returns the next sibling of node x, assuming it \r
     * exists. */\r
+\r
    treeNode NextSibling(treeNode x);\r
    \r
    /** PrevSibling(x): returns the previous sibling of node x, assuming it \r
@@ -207,9 +218,21 @@ public:
     * is none. */\r
    treeNode TaggedDesc(treeNode x, TagType tag);\r
 \r
-   /** TaggedNext(x,tag): returns the first node tagged tag with larger \r
-    * preorder than x. Returns NULT if there is none. */\r
-   treeNode TaggedNext(treeNode x, TagType tag);\r
+\r
+   treeNode TaggedBelow(treeNode x, TagType *childtags, unsigned int ctlen,\r
+                                TagType *desctags, unsigned int dtlen);\r
+   \r
+   treeNode TaggedNext(treeNode x, TagType *childtags, unsigned int ctlen,\r
+                               TagType *folltags, unsigned int flen,treeNode root);\r
+\r
+   treeNode TaggedDescOnly(treeNode x, TagType *desctags, unsigned int dtlen);\r
+   \r
+   treeNode TaggedDescOrFollOnly(treeNode x, TagType *folltags, unsigned int flen,\r
+                          treeNode root);\r
+\r
+   treeNode TaggedFollOnly(treeNode x, TagType *folltags, unsigned int flen,\r
+                          treeNode root);\r
+   \r
 \r
    /** TaggedPrec(x,tag): returns the first node tagged tag with smaller \r
     * preorder than x and not an ancestor of x. Returns NULLT if there \r
@@ -220,6 +243,8 @@ public:
     * preorder than x and not in the subtree of x. Returns NULLT if there \r
     * is none. */\r
    treeNode TaggedFoll(treeNode x, TagType tag);\r
+\r
+   treeNode TaggedFollBelow(treeNode x, TagType tag,treeNode root);     \r
   \r
    /** TaggedFollowingSibling(x,tag) */\r
    treeNode TaggedFollowingSibling(treeNode x, TagType tag);\r
@@ -250,6 +275,7 @@ public:
    \r
    /** ParentNode(d): returns the parent node of document identifier d. */\r
    treeNode ParentNode(DocID d);\r
+   treeNode PrevNode(DocID d);\r
 \r
    /** OpenDocument(empty_texts,sample_rate_text,dtc): initilizes the construction\r
     * of the data structure for the XML document. Parameter empty_texts \r
@@ -316,7 +342,7 @@ public:
    TagType RegisterTag(unsigned char *tagname);\r
 \r
    bool EmptyText(DocID i) {\r
-      return Text->EmptyText(i);\r
+       return Text->EmptyText(i);\r
    }\r
    /** Prefix(s): search for texts prefixed by string s. */\r
    TextCollection::document_result Prefix(uchar const *s) {\r
@@ -371,6 +397,11 @@ public:
    bool IsLessThan(uchar const *s) {\r
       return Text->IsLessThan(s);\r
    }\r
+   \r
+   /** Count(s): Global counting  */\r
+   unsigned Count(uchar const *s) {\r
+      return Text->Count(s);\r
+   }\r
 \r
    /** CountPrefix(s): counting version of Prefix(s). */\r
    unsigned CountPrefix(uchar const *s) {\r
@@ -400,7 +431,7 @@ public:
    /** GetText(d): returns the text corresponding to document with\r
     * id d. */\r
    uchar* GetText(DocID d) {\r
-      return Text->GetText(d);\r
+       return Text->GetText(d);\r
    }\r
 \r
    uchar* GetCachedText(DocID d) {\r