From: kim Date: Tue, 10 Mar 2009 00:27:46 +0000 (+0000) Subject: Added TaggedFoo stuff X-Git-Url: http://git.nguyen.vg/gitweb/?a=commitdiff_plain;h=3b0e5683fd88917737d9adb681a13bb0b2160ce5;p=SXSI%2FXMLTree.git Added TaggedFoo stuff git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@230 3cdefd35-fc62-479d-8e8d-bae585ffb9ca --- diff --git a/XMLTree.cpp b/XMLTree.cpp index 057a117..95546fd 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -427,6 +427,14 @@ range XMLTree::DocIds(treeNode x) } range r; + if (x == NULLT) + { + r.min = NULLT; + r.max = NULLT; + return r; + }; + + if (indexing_empty_texts) { // faster, no rank needed r.min = x; r.max = x+2*subtree_size(Par, x)-2; @@ -489,9 +497,9 @@ treeNode XMLTree::NextSibling(treeNode x) fprintf(stderr, "Error: data structure has not been constructed properly\n"); exit(1); } - if (x == Root()) + if (x == Root() || x==NULLT) return NULLT; - + return next_sibling(Par, x); } @@ -552,25 +560,151 @@ treeNode XMLTree::TaggedDesc(treeNode x, TagType tag) else return y; } +treeNode XMLTree::TaggedDescOnly(treeNode x,TagType *desctags, unsigned int dtlen) +{ + + treeNode res,y; + if (isleaf(Par,x)) + return NULLT; + + res=NULLT; + for (unsigned int i = 0; i < dtlen; i ++ ) + { + y = TaggedDesc(x,desctags[i]); + res = (res == NULLT) || (( res != NULLT) && (y =! NULLT) && y < res) ? y : res; + + }; + + return res; + +} + + +treeNode XMLTree::TaggedBelow(treeNode x, TagType *childtags, unsigned int ctlen, + TagType *desctags, unsigned int dtlen) +{ + treeNode fs,y,res; + TagType tag; + + if (isleaf(Par,x)) + return NULLT; + + res = NULLT; + fs = first_child(Par,x); + while (fs != NULLT) { + tag = get_field(tags_fix,tags_blen,node2tagpos(fs)); + + /* Check for first_child */ + for (unsigned int i = 0; i < ctlen; i++) { + if (childtags[i] == tag) + return fs; + }; + + for (unsigned int i = 0; i < dtlen; i++) + if (desctags[i] == tag) + return fs; + + /* check in the descendants */ + res = NULLT; + for (unsigned int i = 0; i < dtlen; i ++ ){ + /* maybe inline by hand */ + y = TaggedDesc(fs,desctags[i]); + res = (res==NULLT || (y != NULLT) &&(y < res)) ? y : res; + }; + if (res != NULLT) + return res; + + fs = next_sibling(Par,fs); + }; + return res; + +} +treeNode XMLTree::TaggedFollOnly(treeNode x,TagType *folltags, unsigned int ftlen,treeNode root) +{ + + treeNode res,y,lim; + lim = find_close(Par,root); + res=NULLT; + for (unsigned int i = 0; i < ftlen; i ++ ) + { + y = TaggedFoll(x,folltags[i]); + res = (res == NULLT) || (( res != NULLT) && (y =! NULLT) && y < res) ? y : res; + + }; + + return res < lim ? res : NULLT; + +} + +treeNode XMLTree::TaggedDescOrFollOnly(treeNode x,TagType *folltags, unsigned int ftlen,treeNode root) +{ + + treeNode res,y,lim; + int r,s; + lim = find_close(Par,root); + res=NULLT; + for (unsigned int i = 0; i < ftlen; i ++ ) + { + + r = (int) Tags->rank(folltags[i], node2tagpos(x)); + s = (int) Tags->select(folltags[i], r+1); + if (s == -1) + y = NULLT; // there is no such node + else { + y = tagpos2node(s); + if (y >= lim) + y = NULLT; + }; + res = (res == NULLT) || (( res != NULLT) && (y =! NULLT) && y < res) ? y : res; + + }; + + return res < lim ? res : NULLT; + +} + + // TaggedNext(x,tag): returns the first node tagged tag with larger preorder than x // Returns NULLT if there is none. -treeNode XMLTree::TaggedNext(treeNode x, TagType tag) +treeNode XMLTree::TaggedNext(treeNode x, TagType *childtags, unsigned int ctlen, + TagType *folltags, unsigned int flen,treeNode root) { - if (!finished) { - fprintf(stderr, "Error: data structure has not been constructed properly\n"); - exit(1); - } + treeNode y,old_y,lim,res; + TagType tag; + if (x == NULLT || x == Root()) + return NULLT; - int r, s; - treeNode y; - if (x==NULLT) - return NULLT; - r = (int) Tags->rank(tag, node2tagpos(x)); - s = (int) Tags->select(tag, r+1); - if (s == -1) return NULLT; // there is no such node - y = tagpos2node(s); // transforms the tag position into a node position - return (y<=x ? NULLT : y); + lim = find_close(Par,root); + + res = NULLT; + + y = next_sibling(Par,x); + while (y != NULLT) { + tag = get_field(tags_fix,tags_blen,node2tagpos(y)); + for(unsigned int i = 0; i < ctlen;i++) + if (childtags[i] == tag) + return y; + + for(unsigned int i = 0; i < flen;i++) + if (folltags[i] == tag) + return y; + + res = TaggedBelow(y,NULL,0,folltags,flen); + if (res != NULLT) + return res; + + y = next_sibling(Par,y); + }; + //Found nothing in the following sibling of x. + res = NULLT; + for(unsigned int i = 0; i < flen;i++){ + y = TaggedFoll(x,folltags[i]); + res = (y!= x && (res == NULLT || (y != NULLT && y < res)))? y : res; + }; + + return res < lim ? res : NULLT; + } @@ -786,6 +920,29 @@ treeNode XMLTree::ParentNode(DocID d) return (treeNode)s; } +treeNode XMLTree::PrevNode(DocID d) + { + if (!finished) { + fprintf(stderr, "Error: data structure has not been constructed properly\n"); + exit(1); + } + + if (d == NULLT) + return NULLT; + + int s; + + if (indexing_empty_texts) s = d; + else s = EBVector->select1(d+1); + if (s == -1) + return NULLT; + + if (inspect(Par,s) == CP) // is a closing parenthesis + return find_open(Par, s); + else // is an opening parenthesis + return NULLT; + + } // OpenDocument(empty_texts): it starts the construction of the data structure for diff --git a/XMLTree.h b/XMLTree.h index 2e9e222..42e02b7 100644 --- a/XMLTree.h +++ b/XMLTree.h @@ -207,9 +207,21 @@ public: * is none. */ treeNode TaggedDesc(treeNode x, TagType tag); - /** TaggedNext(x,tag): returns the first node tagged tag with larger - * preorder than x. Returns NULT if there is none. */ - treeNode TaggedNext(treeNode x, TagType tag); + + treeNode TaggedBelow(treeNode x, TagType *childtags, unsigned int ctlen, + TagType *desctags, unsigned int dtlen); + + treeNode TaggedNext(treeNode x, TagType *childtags, unsigned int ctlen, + TagType *folltags, unsigned int flen,treeNode root); + + treeNode TaggedDescOnly(treeNode x, TagType *desctags, unsigned int dtlen); + + treeNode TaggedDescOrFollOnly(treeNode x, TagType *folltags, unsigned int flen, + treeNode root); + + treeNode TaggedFollOnly(treeNode x, TagType *folltags, unsigned int flen, + treeNode root); + /** TaggedPrec(x,tag): returns the first node tagged tag with smaller * preorder than x and not an ancestor of x. Returns NULLT if there @@ -220,6 +232,7 @@ public: * preorder than x and not in the subtree of x. Returns NULLT if there * is none. */ treeNode TaggedFoll(treeNode x, TagType tag); + /** TaggedFollowingSibling(x,tag) */ treeNode TaggedFollowingSibling(treeNode x, TagType tag); @@ -250,6 +263,7 @@ public: /** ParentNode(d): returns the parent node of document identifier d. */ treeNode ParentNode(DocID d); + treeNode PrevNode(DocID d); /** OpenDocument(empty_texts,sample_rate_text,dtc): initilizes the construction * of the data structure for the XML document. Parameter empty_texts