added text search functions, fixed the bug when initializing TagName, and some minor...
authordarroyue <darroyue@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Tue, 25 Nov 2008 08:38:27 +0000 (08:38 +0000)
committerdarroyue <darroyue@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Tue, 25 Nov 2008 08:38:27 +0000 (08:38 +0000)
git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@15 3cdefd35-fc62-479d-8e8d-bae585ffb9ca

XMLTree.cpp
XMLTree.h
makefile
test_XML.cpp

index a3fefea..ea12fad 100644 (file)
@@ -1,6 +1,6 @@
 \r
 #include "XMLTree.h"\r
 \r
 #include "XMLTree.h"\r
-#include <cstring>\r
+\r
 // functions to convert tag positions to the corresponding tree node and viceversa. \r
 // These are implemented in order to be able to change the tree and Tags representations, \r
 // without affecting the code so much.\r
 // functions to convert tag positions to the corresponding tree node and viceversa. \r
 // These are implemented in order to be able to change the tree and Tags representations, \r
 // without affecting the code so much.\r
@@ -51,7 +51,7 @@ void XMLTree::Save(unsigned char *filename)
     Tags->save(fp);\r
 \r
     // stores the texts   \r
     Tags->save(fp);\r
 \r
     // stores the texts   \r
-    //Text->Save(fp);\r
+    Text->Save(fp);\r
 \r
     fclose(fp);\r
 \r
 \r
     fclose(fp);\r
 \r
@@ -105,7 +105,7 @@ XMLTree *XMLTree::Load(unsigned char *filename, int sample_rate_text)
     XML_Tree->Tags = static_sequence_wvtree::load(fp);\r
 \r
     // loads the texts   \r
     XML_Tree->Tags = static_sequence_wvtree::load(fp);\r
 \r
     // loads the texts   \r
-    //XML_Tree->Text->Load(fp,sample_rate_text);\r
+    XML_Tree->Text->Load(fp,sample_rate_text);\r
 \r
     fclose(fp);\r
     \r
 \r
     fclose(fp);\r
     \r
@@ -136,9 +136,9 @@ XMLTree::~XMLTree()
     delete Tags;\r
     Tags = NULL;\r
 \r
     delete Tags;\r
     Tags = NULL;\r
 \r
-    //Text->~TextCollection();\r
-   // delete Text;\r
-   // Text = NULL;\r
+    Text->~TextCollection();\r
+    delete Text;\r
+    Text = NULL;\r
 \r
     initialized = false;\r
     finished = false;\r
 \r
     initialized = false;\r
     finished = false;\r
@@ -147,18 +147,31 @@ XMLTree::~XMLTree()
 // root(): returns the tree root.\r
 treeNode XMLTree::Root() \r
  {\r
 // root(): returns the tree root.\r
 treeNode XMLTree::Root() \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
     return root_node(Par);\r
  }\r
 \r
 // SubtreeSize(x): the number of nodes (and attributes) in the subtree of node x.\r
 int XMLTree::SubtreeSize(treeNode x) \r
  {\r
     return root_node(Par);\r
  }\r
 \r
 // SubtreeSize(x): the number of nodes (and attributes) in the subtree of node x.\r
 int XMLTree::SubtreeSize(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
     return subtree_size(Par, x);\r
  }\r
 \r
 // SubtreeTags(x,tag): the number of occurrences of tag within the subtree of node x.\r
 int XMLTree::SubtreeTags(treeNode x, TagType tag) \r
  {\r
     return subtree_size(Par, x);\r
  }\r
 \r
 // SubtreeTags(x,tag): the number of occurrences of tag within the subtree of node x.\r
 int XMLTree::SubtreeTags(treeNode x, TagType tag) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     int s = x + 2*subtree_size(Par, x) - 1;\r
  \r
     return Tags->rank(tag, s) - Tags->rank(tag, node2tagpos(x)-1);\r
     int s = x + 2*subtree_size(Par, x) - 1;\r
  \r
     return Tags->rank(tag, s) - Tags->rank(tag, node2tagpos(x)-1);\r
@@ -174,12 +187,22 @@ bool XMLTree::IsLeaf(treeNode x)
 // IsAncestor(x,y): returns whether node x is ancestor of node y.\r
 bool XMLTree::IsAncestor(treeNode x, treeNode y) \r
  {\r
 // IsAncestor(x,y): returns whether node x is ancestor of node y.\r
 bool XMLTree::IsAncestor(treeNode x, treeNode y) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     return is_ancestor(Par, x, y);\r
  }\r
 \r
 // IsChild(x,y): returns whether node x is parent of node y.\r
 bool XMLTree::IsChild(treeNode x, treeNode y) \r
  {\r
     return is_ancestor(Par, x, y);\r
  }\r
 \r
 // IsChild(x,y): returns whether node x is parent of node y.\r
 bool XMLTree::IsChild(treeNode x, treeNode y) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     if (!is_ancestor(Par, x, y)) return false;\r
     return depth(Par, x) == (depth(Par, y) + 1);\r
  }\r
     if (!is_ancestor(Par, x, y)) return false;\r
     return depth(Par, x) == (depth(Par, y) + 1);\r
  }\r
@@ -188,18 +211,33 @@ bool XMLTree::IsChild(treeNode x, treeNode y)
 // of Sadakane.\r
 int XMLTree::NumChildren(treeNode x) \r
  {\r
 // of Sadakane.\r
 int XMLTree::NumChildren(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     return degree(Par, x);\r
  }\r
 \r
 // ChildNumber(x): returns i if node x is the i-th children of its parent.\r
 int XMLTree::ChildNumber(treeNode x) \r
  {\r
     return degree(Par, x);\r
  }\r
 \r
 // ChildNumber(x): returns i if node x is the i-th children of its parent.\r
 int XMLTree::ChildNumber(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     return child_rank(Par, x);\r
  }\r
 \r
 // Depth(x): depth of node x, a simple binary rank on the parentheses sequence.\r
 int XMLTree::Depth(treeNode x) \r
  {\r
     return child_rank(Par, x);\r
  }\r
 \r
 // Depth(x): depth of node x, a simple binary rank on the parentheses sequence.\r
 int XMLTree::Depth(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     return depth(Par, x);\r
  }\r
 \r
     return depth(Par, x);\r
  }\r
 \r
@@ -207,6 +245,11 @@ int XMLTree::Depth(treeNode x)
 // nodes (i.e., tags, it disregards the texts in the tree).\r
 int XMLTree::Preorder(treeNode x) \r
  {\r
 // nodes (i.e., tags, it disregards the texts in the tree).\r
 int XMLTree::Preorder(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     return preorder_rank(Par, x);\r
  }\r
 \r
     return preorder_rank(Par, x);\r
  }\r
 \r
@@ -214,12 +257,22 @@ int XMLTree::Preorder(treeNode x)
 // nodes (i.e., tags, it disregards the texts in the tree).\r
 int XMLTree::Postorder(treeNode x) \r
  {\r
 // nodes (i.e., tags, it disregards the texts in the tree).\r
 int XMLTree::Postorder(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     return postorder_rank(Par, x);\r
  }\r
 \r
 // Tag(x): returns the tag identifier of node x.\r
 TagType XMLTree::Tag(treeNode x) \r
  {\r
     return postorder_rank(Par, x);\r
  }\r
 \r
 // Tag(x): returns the tag identifier of node x.\r
 TagType XMLTree::Tag(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     return Tags->access(node2tagpos(x));\r
  }\r
 \r
     return Tags->access(node2tagpos(x));\r
  }\r
 \r
@@ -227,6 +280,11 @@ TagType XMLTree::Tag(treeNode x)
 // returns {NULLT, NULLT} when there are no texts descending from x.\r
 range XMLTree::DocIds(treeNode x) \r
  {\r
 // returns {NULLT, NULLT} when there are no texts descending from x.\r
 range XMLTree::DocIds(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     range r;\r
     if (indexing_empty_texts) { // faster, no rank needed\r
        r.min = x;\r
     range r;\r
     if (indexing_empty_texts) { // faster, no rank needed\r
        r.min = x;\r
@@ -250,12 +308,22 @@ range XMLTree::DocIds(treeNode x)
 // Parent(x): returns the parent node of node x.\r
 treeNode XMLTree::Parent(treeNode x) \r
  {\r
 // Parent(x): returns the parent node of node x.\r
 treeNode XMLTree::Parent(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     return parent(Par, x);\r
  }\r
 \r
 // Child(x,i): returns the i-th child of node x, assuming it exists.\r
 treeNode XMLTree::Child(treeNode x, int i) \r
     return parent(Par, x);\r
  }\r
 \r
 // Child(x,i): returns the i-th child of node x, assuming it exists.\r
 treeNode XMLTree::Child(treeNode x, int i) \r
- {\r
+{\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     if (i <= OPTD) return naive_child(Par, x, i);\r
     else return child(Par, x, i);\r
  }\r
     if (i <= OPTD) return naive_child(Par, x, i);\r
     else return child(Par, x, i);\r
  }\r
@@ -263,18 +331,33 @@ treeNode XMLTree::Child(treeNode x, int i)
 // FirstChild(x): returns the first child of node x, assuming it exists. Very fast in BP.\r
 treeNode XMLTree::FirstChild(treeNode x) \r
  {\r
 // FirstChild(x): returns the first child of node x, assuming it exists. Very fast in BP.\r
 treeNode XMLTree::FirstChild(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     return first_child(Par, x);\r
  }\r
 \r
 // NextSibling(x): returns the next sibling of node x, assuming it exists.\r
 treeNode XMLTree::NextSibling(treeNode x) \r
  {\r
     return first_child(Par, x);\r
  }\r
 \r
 // NextSibling(x): returns the next sibling of node x, assuming it exists.\r
 treeNode XMLTree::NextSibling(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     return next_sibling(Par, x);\r
  }\r
 \r
 // PrevSibling(x): returns the previous sibling of node x, assuming it exists.\r
 treeNode XMLTree::PrevSibling(treeNode x) \r
  {\r
     return next_sibling(Par, x);\r
  }\r
 \r
 // PrevSibling(x): returns the previous sibling of node x, assuming it exists.\r
 treeNode XMLTree::PrevSibling(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     return prev_sibling(Par, x);\r
  }\r
 \r
     return prev_sibling(Par, x);\r
  }\r
 \r
@@ -283,6 +366,11 @@ treeNode XMLTree::PrevSibling(treeNode x)
 // efficiently, just iterating among the children of node x until finding the desired child.\r
 treeNode XMLTree::TaggedChild(treeNode x, int i, TagType tag) \r
  {\r
 // efficiently, just iterating among the children of node x until finding the desired child.\r
 treeNode XMLTree::TaggedChild(treeNode x, int i, TagType tag) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     treeNode child;\r
    \r
     child = first_child(Par, x); // starts at first child of node x\r
     treeNode child;\r
    \r
     child = first_child(Par, x); // starts at first child of node x\r
@@ -301,6 +389,11 @@ treeNode XMLTree::TaggedChild(treeNode x, int i, TagType tag)
 // the subtree of x. Returns NULLT if there is none.\r
 treeNode XMLTree::TaggedDesc(treeNode x, TagType tag) \r
  {\r
 // the subtree of x. Returns NULLT if there is none.\r
 treeNode XMLTree::TaggedDesc(treeNode x, TagType tag) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     int r, s;\r
     treeNode y;\r
     r = (int) Tags->rank(tag, node2tagpos(x));\r
     int r, s;\r
     treeNode y;\r
     r = (int) Tags->rank(tag, node2tagpos(x));\r
@@ -315,6 +408,11 @@ treeNode XMLTree::TaggedDesc(treeNode x, TagType tag)
 // ancestor of x. Returns NULLT if there is none.\r
 treeNode XMLTree::TaggedPrec(treeNode x, TagType tag) \r
  {\r
 // ancestor of x. Returns NULLT if there is none.\r
 treeNode XMLTree::TaggedPrec(treeNode x, TagType tag) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+    \r
     int r, s;\r
     treeNode node_s, root;\r
     r = (int)Tags->rank(tag, node2tagpos(x)-1);\r
     int r, s;\r
     treeNode node_s, root;\r
     r = (int)Tags->rank(tag, node2tagpos(x)-1);\r
@@ -335,6 +433,11 @@ treeNode XMLTree::TaggedPrec(treeNode x, TagType tag)
 // the subtree of x. Returns NULLT if there is none.\r
 treeNode XMLTree::TaggedFoll(treeNode x, TagType tag) \r
  {\r
 // the subtree of x. Returns NULLT if there is none.\r
 treeNode XMLTree::TaggedFoll(treeNode x, TagType tag) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     int r, s;\r
     r = (int) Tags->rank(tag, node2tagpos(next_sibling(Par, x))-1);\r
     s = (int) Tags->select(tag, r+1);  // select returns -1 in case that there is no r+1-th tag.\r
     int r, s;\r
     r = (int) Tags->rank(tag, node2tagpos(next_sibling(Par, x))-1);\r
     s = (int) Tags->select(tag, r+1);  // select returns -1 in case that there is no r+1-th tag.\r
@@ -347,6 +450,11 @@ treeNode XMLTree::TaggedFoll(treeNode x, TagType tag)
 // Assumes Doc ids start from 0.\r
 DocID XMLTree::PrevText(treeNode x) \r
  {\r
 // Assumes Doc ids start from 0.\r
 DocID XMLTree::PrevText(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     if (x == Root()) return NULLT;\r
     if (indexing_empty_texts)  // faster, no rank needed\r
        return (DocID)x-1;\r
     if (x == Root()) return NULLT;\r
     if (indexing_empty_texts)  // faster, no rank needed\r
        return (DocID)x-1;\r
@@ -362,6 +470,11 @@ DocID XMLTree::PrevText(treeNode x)
 // of node x, or NULLT if x is the root node. Assumes Doc ids start from 0.\r
 DocID XMLTree::NextText(treeNode x) \r
  {\r
 // of node x, or NULLT if x is the root node. Assumes Doc ids start from 0.\r
 DocID XMLTree::NextText(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     if (x == Root()) return NULLT;\r
     if (indexing_empty_texts)  // faster, no rank needed\r
        return (DocID)x+2*subtree_size(Par, x)-1;\r
     if (x == Root()) return NULLT;\r
     if (indexing_empty_texts)  // faster, no rank needed\r
        return (DocID)x+2*subtree_size(Par, x)-1;\r
@@ -379,6 +492,11 @@ DocID XMLTree::NextText(treeNode x)
 // ids start from 0.\r
 DocID XMLTree::MyText(treeNode x) \r
  {\r
 // ids start from 0.\r
 DocID XMLTree::MyText(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     if (!IsLeaf(x)) return NULLT;\r
     if (indexing_empty_texts) // faster, no rank needed\r
        return (DocID)x;\r
     if (!IsLeaf(x)) return NULLT;\r
     if (indexing_empty_texts) // faster, no rank needed\r
        return (DocID)x;\r
@@ -394,6 +512,11 @@ DocID XMLTree::MyText(treeNode x)
 // all tree nodes and all text nodes. Assumes that the tree root has preorder 1.\r
 int XMLTree::TextXMLId(DocID d) \r
  {\r
 // all tree nodes and all text nodes. Assumes that the tree root has preorder 1.\r
 int XMLTree::TextXMLId(DocID d) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     if (indexing_empty_texts) \r
        return d + rank_open(Par, d)+1; // +1 because root has preorder 1\r
     else { // slower, needs rank and select\r
     if (indexing_empty_texts) \r
        return d + rank_open(Par, d)+1; // +1 because root has preorder 1\r
     else { // slower, needs rank and select\r
@@ -407,6 +530,11 @@ int XMLTree::TextXMLId(DocID d)
 // preorder 0;\r
 int XMLTree::NodeXMLId(treeNode x) \r
  {\r
 // preorder 0;\r
 int XMLTree::NodeXMLId(treeNode x) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     if (indexing_empty_texts)\r
        return x - 1 + rank_open(Par, x);\r
     else {\r
     if (indexing_empty_texts)\r
        return x - 1 + rank_open(Par, x);\r
     else {\r
@@ -419,6 +547,11 @@ int XMLTree::NodeXMLId(treeNode x)
 // ParentNode(d): returns the parent node of document identifier d.\r
 treeNode XMLTree::ParentNode(DocID d) \r
  {\r
 // ParentNode(d): returns the parent node of document identifier d.\r
 treeNode XMLTree::ParentNode(DocID d) \r
  {\r
+    if (!finished) {\r
+       fprintf(stderr, "Error: data structure has not been constructed properly\n");\r
+       exit(1);\r
+    }\r
+\r
     int s;\r
     if (indexing_empty_texts) s = d;\r
     else s = EBVector->select1(d);\r
     int s;\r
     if (indexing_empty_texts) s = d;\r
     else s = EBVector->select1(d);\r
@@ -457,6 +590,8 @@ int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text)
        return NULLT;\r
     }\r
     \r
        return NULLT;\r
     }\r
     \r
+    TagName = NULL;\r
+\r
     if (!indexing_empty_texts) {\r
        empty_texts_aux = (unsigned int *)malloc(sizeof(unsigned int));\r
        if (!empty_texts_aux) {\r
     if (!indexing_empty_texts) {\r
        empty_texts_aux = (unsigned int *)malloc(sizeof(unsigned int));\r
        if (!empty_texts_aux) {\r
@@ -465,7 +600,7 @@ int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text)
        }\r
     }\r
     \r
        }\r
     }\r
     \r
-    //Text = TextCollection::InitTextCollection(sample_rate_text);\r
+    Text = TextCollection::InitTextCollection((unsigned)sample_rate_text);\r
     \r
     return 1;  // indicates success in the initialization of the data structure\r
  }\r
     \r
     return 1;  // indicates success in the initialization of the data structure\r
  }\r
@@ -500,7 +635,7 @@ int XMLTree::CloseDocument()
     Tags = new static_sequence_wvtree((uint *) tags_aux, (uint) npar-1, wtc, bmb, am);\r
 \r
     // makes the text collection static\r
     Tags = new static_sequence_wvtree((uint *) tags_aux, (uint) npar-1, wtc, bmb, am);\r
 \r
     // makes the text collection static\r
-    //Text->MakeStatic();\r
+    Text->MakeStatic();\r
     \r
     // creates the data structure marking the non-empty texts (just in the case it is necessary)\r
     if (!indexing_empty_texts) \r
     \r
     // creates the data structure marking the non-empty texts (just in the case it is necessary)\r
     if (!indexing_empty_texts) \r
@@ -600,8 +735,9 @@ int XMLTree::NewClosingTag(unsigned char *tagname)
        }\r
        \r
        ntagnames++;\r
        }\r
        \r
        ntagnames++;\r
-       TagName[i] = (unsigned char *)malloc(sizeof(char)*(strlen((const char *)tagname)+1));\r
-       strcpy((char *)TagName[i], (const char *)tagname);\r
+       TagName[i] = (unsigned char *)malloc(sizeof(char)*(strlen((const char *)tagname)+2));\r
+       TagName[i][0] = '/';\r
+       strcpy((char *)&(TagName[i][1]), (const char *)tagname);\r
     } \r
 \r
     tags_aux = (TagType *)realloc(tags_aux, sizeof(TagType)*(npar + 1));\r
     } \r
 \r
     tags_aux = (TagType *)realloc(tags_aux, sizeof(TagType)*(npar + 1));\r
@@ -640,7 +776,7 @@ int XMLTree::NewText(unsigned char *s)
        bitset(empty_texts_aux, npar-1);  // marks the non-empty text with a 1 in the bit vector\r
     }\r
     \r
        bitset(empty_texts_aux, npar-1);  // marks the non-empty text with a 1 in the bit vector\r
     }\r
     \r
-    //Text->InsertText(s);\r
+    Text->InsertText(s);\r
     \r
     return 1; // success\r
  }\r
     \r
     return 1; // success\r
  }\r
@@ -667,7 +803,7 @@ int XMLTree::NewEmptyText()
        \r
        bitclean(empty_texts_aux, npar-1);  // marks the empty text with a 0 in the bit vector\r
     }\r
        \r
        bitclean(empty_texts_aux, npar-1);  // marks the empty text with a 0 in the bit vector\r
     }\r
-   // else Text->InsertText(&c); // we insert the empty text just in case we index all the texts\r
+    else Text->InsertText(&c); // we insert the empty text just in case we index all the texts\r
     \r
     return 1; // success    \r
  }\r
     \r
     return 1; // success    \r
  }\r
@@ -698,3 +834,5 @@ unsigned char *XMLTree::GetTagName(TagType tagid)
     return s;\r
  }\r
 \r
     return s;\r
  }\r
 \r
+\r
+\r
index bb1dbbb..319b9a6 100644 (file)
--- a/XMLTree.h
+++ b/XMLTree.h
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include "bp.h"\r
 #include <stdio.h>\r
 #include <stdlib.h>\r
 #include "bp.h"\r
+#include "TextCollection/TextCollection.h"\r
+using SXSI::TextCollection;\r
 #include "libcds/includes/static_bitsequence.h"\r
 #include "libcds/includes/alphabet_mapper.h"\r
 #include "libcds/includes/static_sequence.h"\r
 \r
 #include "libcds/includes/static_bitsequence.h"\r
 #include "libcds/includes/alphabet_mapper.h"\r
 #include "libcds/includes/static_sequence.h"\r
 \r
-//#include "TextCollection/TextCollection.h"\r
-//using SXSI::TextCollection;\r
+\r
 \r
 // this constant is used to efficiently compute the child operation in the tree\r
 #define OPTD 10\r
 \r
 // this constant is used to efficiently compute the child operation in the tree\r
 #define OPTD 10\r
@@ -70,7 +71,7 @@ class XMLTree {
    static_sequence_wvtree *Tags;\r
 \r
    /** The texts in the XML document */\r
    static_sequence_wvtree *Tags;\r
 \r
    /** The texts in the XML document */\r
-   //TextCollection *Text;\r
+   TextCollection *Text;\r
    \r
    /** Flag indicating whether the whole data structure has been constructed or \r
     * not. If the value is true, you cannot add more texts, nodes, etc. */\r
    \r
    /** Flag indicating whether the whole data structure has been constructed or \r
     * not. If the value is true, you cannot add more texts, nodes, etc. */\r
@@ -251,14 +252,41 @@ public:
     * Returns NULL in case that the tag identifier is not valid.*/\r
    unsigned char *GetTagName(TagType tagid);\r
 \r
     * Returns NULL in case that the tag identifier is not valid.*/\r
    unsigned char *GetTagName(TagType tagid);\r
 \r
-   /** saveXMLTree: saves XML tree data structure to file. Every component of \r
-    * the collection is stored in different files (same name, different file \r
-    * extensions). */\r
+   /** Prefix(s): search for texts prefixed by string s. */\r
+   TextCollection::document_result Prefix(uchar const *s) {\r
+      Text->Prefix(s);\r
+   }\r
+\r
+   /** Suffix(s): search for texts having string s as a suffix. */\r
+   TextCollection::document_result Suffix(uchar const *s) {\r
+      Text->Suffix(s);\r
+   }\r
+\r
+   /** Equal(s): search for texts equal to string s. */\r
+   TextCollection::document_result Equal(uchar const *s) {\r
+      Text->Equal(s);\r
+   }\r
+\r
+   /** Contains(s): search for texts containing string s.  */\r
+   TextCollection::document_result Contains(uchar const *s) {\r
+      Text->Contains(s);\r
+   }\r
+\r
+   TextCollection::document_result LessThan(uchar const *s) {\r
+      Text->LessThan(s);\r
+   }\r
+  \r
+   /** GetText(d): returns the text corresponding to document with\r
+    * id d. */\r
+   uchar* GetText(DocID d) {\r
+      Text->GetText(d);\r
+   }\r
+   \r
+   /** Save: saves XML tree data structure to file. */\r
    void Save(unsigned char *filename);\r
       \r
    void Save(unsigned char *filename);\r
       \r
-   /** load: loads XML tree data structure from file. */\r
+   /** Load: loads XML tree data structure from file. sample_rate_text \r
+    * indicates the sample rate for the text search data structure. */\r
    static XMLTree *Load(unsigned char *filename, int sample_rate_text);   \r
 };\r
    static XMLTree *Load(unsigned char *filename, int sample_rate_text);   \r
 };\r
-\r
-\r
 #endif\r
 #endif\r
index a3b0e61..5db952e 100644 (file)
--- a/makefile
+++ b/makefile
@@ -1,12 +1,14 @@
 FLAGS = -O9 -I./libcds/includes/\r
 \r
 OBJECTS=libcds/lib/libcds.a\r
 FLAGS = -O9 -I./libcds/includes/\r
 \r
 OBJECTS=libcds/lib/libcds.a\r
+OBJECTS_TC= TextCollection/BitRank.o TextCollection/dynFMI.o TextCollection/rbtree.o TextCollection/Tools.o TextCollection/bittree.o TextCollection/handle.o TextCollection/testTextCollection.o TextCollection/CSA.o TextCollection/pos.o TextCollection/TextCollection.o\r
 \r
 \r
-all: text_collection XMLTree\r
+\r
+all: libcds text_collection XMLTree\r
 \r
 XMLTree: XMLTree.o bp.o darray.o bpcore.o libcds/lib/libcds.a\r
        cp libcds/lib/libcds.a XMLTree.a\r
 \r
 XMLTree: XMLTree.o bp.o darray.o bpcore.o libcds/lib/libcds.a\r
        cp libcds/lib/libcds.a XMLTree.a\r
-       ar vrcs XMLTree.a XMLTree.o bp.o darray.o bpcore.o\r
+       ar vrcs XMLTree.a XMLTree.o bp.o darray.o bpcore.o $(OBJECTS_TC)\r
 \r
 \r
 XMLTree.o: bp.c bp.h bpcore.c XMLTree.cpp XMLTree.h\r
 \r
 \r
 XMLTree.o: bp.c bp.h bpcore.c XMLTree.cpp XMLTree.h\r
@@ -24,5 +26,8 @@ bpcore.o: bpcore.c
 text_collection:\r
        make -C TextCollection/\r
 \r
 text_collection:\r
        make -C TextCollection/\r
 \r
+libcds:\r
+       make -C libcds/\r
+\r
 clean:\r
 clean:\r
-       rm -f *.o 
\ No newline at end of file
+       rm -f *.o \r
index 20265cf..c13c04d 100644 (file)
@@ -21,10 +21,10 @@ int main()
  {\r
     XMLTree *X, *Y;\r
     int rr, n, i;\r
  {\r
     XMLTree *X, *Y;\r
     int rr, n, i;\r
-    unsigned char openTag[]="A", closeTag[]="/A", filename[]="testXML";\r
+    unsigned char openTag[]="A", closeTag[]="/A", filename[]="testXML", text[]="Hello World";\r
     treeNode x;\r
 \r
     treeNode x;\r
 \r
-    n = 4999999;\r
+    n = 49999;\r
 \r
     X = new XMLTree();\r
 \r
 \r
     X = new XMLTree();\r
 \r
@@ -42,7 +42,7 @@ int main()
         X->NewClosingTag(closeTag);\r
         if ((1+(int) (2.0*rand()/(RAND_MAX+1.0))) == 1)\r
            X->NewEmptyText();\r
         X->NewClosingTag(closeTag);\r
         if ((1+(int) (2.0*rand()/(RAND_MAX+1.0))) == 1)\r
            X->NewEmptyText();\r
-        else X->NewText(NULL); // just a test, NULL string\r
+        else X->NewText(text);\r
         rr--;\r
       } \r
       else {\r
         rr--;\r
       } \r
       else {\r
@@ -50,14 +50,14 @@ int main()
            X->NewOpenTag(openTag);\r
            if ((1+(int) (2.0*rand()/(RAND_MAX+1.0))) == 1)\r
               X->NewEmptyText();\r
            X->NewOpenTag(openTag);\r
            if ((1+(int) (2.0*rand()/(RAND_MAX+1.0))) == 1)\r
               X->NewEmptyText();\r
-           else X->NewText(NULL);\r
+           else X->NewText(text);\r
            rr++;\r
          } \r
          else {\r
            X->NewClosingTag(closeTag);\r
            if ((1+(int) (2.0*rand()/(RAND_MAX+1.0))) <= 1)\r
               X->NewEmptyText();\r
            rr++;\r
          } \r
          else {\r
            X->NewClosingTag(closeTag);\r
            if ((1+(int) (2.0*rand()/(RAND_MAX+1.0))) <= 1)\r
               X->NewEmptyText();\r
-           else X->NewText(NULL);\r
+           else X->NewText(text);\r
            rr--;\r
          }\r
       }\r
            rr--;\r
          }\r
       }\r
@@ -74,13 +74,13 @@ int main()
 \r
     X->Save(filename);\r
 \r
 \r
     X->Save(filename);\r
 \r
-    delete X;\r
+    //delete X;\r
 \r
 \r
-    X = XMLTree::Load(filename, 32);\r
+//    X = XMLTree::Load(filename, 32);\r
     \r
     \r
-    x = X->Root();\r
+  //  x = X->Root();\r
     \r
     \r
-    traverseXML(X, x);    \r
+    //traverseXML(X, x);    \r
     \r
  }\r
 \r
     \r
  }\r
 \r