Merge branch 'master' of ssh://git.nguyen.vg/tatoo
authorKim Nguyễn <kn@lri.fr>
Fri, 26 Oct 2012 15:44:25 +0000 (17:44 +0200)
committerKim Nguyễn <kn@lri.fr>
Fri, 26 Oct 2012 15:44:25 +0000 (17:44 +0200)
run_tests [new file with mode: 0755]
src/test.ml
src/xPath.ml
src/xPath.mli
tests/queries/Treebank.xml.queries [new file with mode: 0644]
tests/queries/chrom5.xml.queries [new file with mode: 0644]
tests/queries/medline.xml.queries [new file with mode: 0644]
tests/queries/medline_full.xml.queries [new file with mode: 0644]
tests/queries/xmark_01.04.xml.queries [new file with mode: 0644]
tests/queries/xmark_10.xml.queries [new file with mode: 0644]
tests/queries/xmark_all.xml.queries [new file with mode: 0644]

diff --git a/run_tests b/run_tests
new file mode 100755 (executable)
index 0000000..867fbe2
--- /dev/null
+++ b/run_tests
@@ -0,0 +1,3 @@
+./test.native ./tests/docs/tiny.xml '/child::site/child::regions'
+./test.native ./tests/docs/tiny.xml -f ./tests/queries/Treebank.xml.queries
+./test.native ./tests/docs/tiny.xml '/descendant::listitem[not(descendant::keyword/child::emph)]/descendant::parlist'
index 770d4c5..465e409 100644 (file)
 (***********************************************************************)
 
 
+(** use: xml_file "XPath querie"
+    or : xml_file -f XPath_querie_file
+    only the first line of XPath_querie_file is read 
+*)
+
 module F = Formula
 (* to force ocaml build to add Formula to the dependency chain even if
    we don't use it yet*)
@@ -25,7 +30,13 @@ let doc =
 
 
 
-let query = XPath.parse Sys.argv.(2)
+let query = 
+  let arg2 = Sys.argv.(2) in
+  if arg2 = "-f"
+  then  let fq = open_in Sys.argv.(3) in
+       let q = XPath.parse_file fq in
+       close_in fq; q
+  else XPath.parse_string arg2
 
 open Format
 
index cb3393f..7ebc135 100644 (file)
@@ -366,6 +366,9 @@ END
 
 *)
 
-  let parse = Gram.parse_string query (Ulexer.Loc.mk "<string>")
+  let parse_string = Gram.parse_string query (Ulexer.Loc.mk "<string>")
+  let parse_file fd = parse_string (input_line fd)
+
 end
-let parse = Parser.parse
+let parse_string = Parser.parse_string
+let parse_file = Parser.parse_file
index 44935c3..afb4c39 100644 (file)
@@ -46,4 +46,5 @@ sig
 end
 
 
-val parse : string -> Ast.path
+val parse_string : string -> Ast.path
+val parse_file : in_channel -> Ast.path
diff --git a/tests/queries/Treebank.xml.queries b/tests/queries/Treebank.xml.queries
new file mode 100644 (file)
index 0000000..114552e
--- /dev/null
@@ -0,0 +1,9 @@
+/descendant::NP
+#%/descendant::*/child::NP
+#T03%/descendant::NP/descendant::VBZ
+T02%/descendant::S[descendant::VP and descendant::NP]/child::VP/child::PP[child::IN]/child::NP/child::VBN
+T03%/descendant::NP[descendant::JJ or descendant::CC]
+T04%/descendant::CC[ not(descendant::JJ) ]
+#%/descendant::S/child::VP/child::PP[child::NP/child::VBN]/child::IN
+T05%/descendant::NN[descendant::VBZ or descendant::IN]/child::*[descendant::NN or descendant::_QUOTE_]
+#T06%/descendant::EMPTY[descendant::VP and descendant::S]/descendant::PP[descendant::S and descendant::VGN]
\ No newline at end of file
diff --git a/tests/queries/chrom5.xml.queries b/tests/queries/chrom5.xml.queries
new file mode 100644 (file)
index 0000000..705d741
--- /dev/null
@@ -0,0 +1,9 @@
+/descendant::promoter[contains(.,  "PSSM 5000 8 1 0 19 20 18 1 20 7 1 0 1 0 1 18 0 2 17 0 0 0 1 0 0 3 1 20 0 0 0 1 0 8")]
+/descendant::promoter[contains(.,  "PSSM 100000 12 6 19 19 20 5 0 1 20 19 20 1 1 4 0 0 0 3 10 1 0 1 0 13 13 10 1 0 0 11 0 18 0 0 0 6 1 0 0 1 0 1 10 0 0 0 0 0 5") ]
+/descendant::promoter[contains(.,  "PSSM 300000 14 0 1 12 6 0 0 0 1 2 6 6 1 3 0 0 0 0 7 13 3 2 0 0 4 5 10 6 3 2 12 1 0 0 0 0 0 11 3 1 1 0 3 11 0 0 0 0 10 11 12 0 0 1 1 4 7") ]
+/descendant::exon[ descendant::sequence[ contains(., "PSSM 5000 8 1 0 19 20 18 1 20 7 1 0 1 0 1 18 0 2 17 0 0 0 1 0 0 3 1 20 0 0 0 1 0 8")] ]
+/descendant::exon[ descendant::sequence[ contains( .,  "PSSM 100000 12 6 19 19 20 5 0 1 20 19 20 1 1 4 0 0 0 3 10 1 0 1 0 13 13 10 1 0 0 11 0 18 0 0 0 6 1 0 0 1 0 1 10 0 0 0 0 0 5") ] ]
+/descendant::exon[ descendant::sequence[ contains(.,  "PSSM 300000 14 0 1 12 6 0 0 0 1 2 6 6 1 3 0 0 0 0 7 13 3 2 0 0 4 5 10 6 3 2 12 1 0 0 0 0 0 11 3 1 1 0 3 11 0 0 0 0 10 11 12 0 0 1 1 4 7") ] ]
+/descendant::*[contains(.,  "PSSM 5000 8 1 0 19 20 18 1 20 7 1 0 1 0 1 18 0 2 17 0 0 0 1 0 0 3 1 20 0 0 0 1 0 8")]
+/descendant::*[contains(.,  "PSSM 100000 12 6 19 19 20 5 0 1 20 19 20 1 1 4 0 0 0 3 10 1 0 1 0 13 13 10 1 0 0 11 0 18 0 0 0 6 1 0 0 1 0 1 10 0 0 0 0 0 5") ]
+/descendant::*[contains(.,  "PSSM 300000 14 0 1 12 6 0 0 0 1 2 6 6 1 3 0 0 0 0 7 13 3 2 0 0 4 5 10 6 3 2 12 1 0 0 0 0 0 11 3 1 1 0 3 11 0 0 0 0 10 11 12 0 0 1 1 4 7") ]
diff --git a/tests/queries/medline.xml.queries b/tests/queries/medline.xml.queries
new file mode 100644 (file)
index 0000000..738f266
--- /dev/null
@@ -0,0 +1,7 @@
+/descendant::Article[ descendant::AbstractText[ contains ( . , "plus") or contains ( . , "for")  ] ]%/descendant::Article/descendant::AbstractText[ . ftcontains "plus" ftor "for" ]
+/descendant::Article[ descendant::AbstractText[ contains ( . , "plus") and not(contains ( . , "for"))  ] ]%/descendant::Article/descendant::AbstractText[ . ftcontains "plus" ftand ftnot "for" ]
+/descendant::MedlineCitation/child::Article/child::AuthorList/child::Author[ child::LastName[starts-with( ., "Bar")]]%/descendant::MedlineCitation/child::Article/child::AuthorList/child::Author[ child::LastName ftcontains "Bar" at start ]
+/descendant::*[ descendant::LastName[ contains( ., "Nguyen") ] ]%/descendant::*[ descendant::LastName ftcontains "Nguyen" entire content ]
+/descendant::*/descendant::*[ contains( ., "epididymis") ]%/descendant::*/descendant::*[ . ftcontains "epididymis" ]
+/descendant::*[ descendant::PublicationType[ ends-with( ., "Article") ]]%/descendant::*[ descendant::PublicationType ftcontains "Article" at end ]
+/descendant::MedlineCitation[ descendant::Country[ contains( ., "AUSTRALIA") ] ]%/descendant::MedlineCitation[ descendant::Country ftcontains "AUSTRALIA" ]
diff --git a/tests/queries/medline_full.xml.queries b/tests/queries/medline_full.xml.queries
new file mode 100644 (file)
index 0000000..012d255
--- /dev/null
@@ -0,0 +1,10 @@
+/descendant::Article[ descendant::AbstractText[ contains ( . , "blood sample") ] ]%/descendant::Article/descendant::AbstractText[ . ftcontains "blood sample" all words ordered ]
+W2%/descendant::Article[ descendant::AbstractText[ contains ( . , "is such that")  ] ]%/descendant::Article/descendant::AbstractText[ . ftcontains "is such that" all words ordered ]
+W3%/descendant::Article[ descendant::AbstractText[ contains( . , "various types of") and contains( . , "immune cells") ] ]%/descendant::Article[descendant::AbstractText[ . ftcontains "various types of" all words ordered ftand "immune cells" all words ordered ]]
+W4%/descendant::Article[ descendant::AbstractText[ contains( . , "of the bone marrow") ] ]%/descendant::Article[descendant::AbstractText[ . ftcontains "of the bone marrow" all words ordered ]]
+W5%/descendant::Article[ descendant::AbstractText[ contains( . , "cell") and not(contains( ., "blood")) ] ]%/descendant::Article[descendant::AbstractText[ . ftcontains "cell" ftand ftnot "blood" ]]
+#W5%/descendant::MedlineCitation/child::Article/child::AuthorList/child::Author[ child::LastName[starts-with( ., "Bar")]]%/descendant::MedlineCitation/child::Article/child::AuthorList/child::Author[ child::LastName ftcontains "Bar" at start ]
+#W6%/descendant::*[ descendant::LastName[ contains( ., "Nguyen") ] ]%/descendant::*[ descendant::LastName ftcontains "Nguyen" entire content ]
+#W7%/descendant::*/descendant::*[ contains( ., "epididymis") ]%/descendant::*/descendant::*[ . ftcontains "epididymis" ]
+#W8%/descendant::*[ descendant::PublicationType[ ends-with( ., "Article") ]]%/descendant::*[ descendant::PublicationType ftcontains "Article" at end ]
+#W9%/descendant::MedlineCitation[ descendant::Country[ contains( ., "AUSTRALIA") ] ]%/descendant::MedlineCitation[ descendant::Country ftcontains "AUSTRALIA" ]
diff --git a/tests/queries/xmark_01.04.xml.queries b/tests/queries/xmark_01.04.xml.queries
new file mode 100644 (file)
index 0000000..7755f47
--- /dev/null
@@ -0,0 +1,26 @@
+/child::site/child::closed_auctions/child::closed_auction/child::annotation/child::description/child::text/child::keyword
+X04%/descendant::listitem/descendant::keyword
+#%/descendant::closed_auction/descendant::keyword
+#%/site/closed_auctions/closed_auction/descendant::keyword
+X05%/child::site/child::closed_auctions/child::closed_auction[child::annotation/child::description/child::text/child::keyword]/child::date
+X06%/child::site/child::closed_auctions/child::closed_auction[descendant::keyword]/child::date
+X07%/child::site/child::people/child::person[child::profile/child::gender and child::profile/child::age]/child::name
+X08%/child::site/child::people/child::person[child::phone or child::homepage]/child::name
+X09%/child::site/child::people/child::person[child::address and (child::phone or child::homepage) and (child::creditcard or child::profile)]/child::name
+X10%/descendant::listitem[not(descendant::keyword/child::emph)]/descendant::parlist
+X11%/descendant::listitem[ (descendant::keyword or descendant::emph) and (descendant::emph or descendant::bold)]/child::parlist
+X12%/descendant::people[ descendant::person[not(child::address)] and descendant::person[not(child::watches)]]/child::person[child::watches]
+#%/site/regions/europe/item/mailbox/mail/text/keyword
+#%/site/closed_auctions/closed_auction/annotation/description/parlist/listitem
+#%/site/closed_auctions/closed_auction/annotation/description/parlist/listitem/parlist/listitem/*/descendant::keyword
+#%/site/regions/*/item/descendant::keyword
+#%/site/regions/*/person[ address and (phone or homepage) ]
+#%/descendant::listitem[ descendant::keyword and descendant::emph]/descendant::parlist
+#%/site/regions/*/item[ mailbox/mail/date ]/mailbox/mail
+X13%/child::*[ descendant::* ]
+X14%/descendant::*
+X15%/descendant::*/descendant::*
+X16%/descendant::*/descendant::*/descendant::*
+X17%/descendant::*/descendant::*/descendant::*/descendant::*
+#%/descendant::*/descendant::*/descendant::*/descendant::*/descendant::*/descendant::*
+#%/descendant::*/descendant::*
diff --git a/tests/queries/xmark_10.xml.queries b/tests/queries/xmark_10.xml.queries
new file mode 100644 (file)
index 0000000..5e28255
--- /dev/null
@@ -0,0 +1,27 @@
+/child::site/child::regions/child::*/child::item
+X03%/child::site/child::closed_auctions/child::closed_auction/child::annotation/child::description/child::text/child::keyword
+X04%/descendant::listitem/descendant::keyword
+#%/descendant::closed_auction/descendant::keyword
+#%/site/closed_auctions/closed_auction/descendant::keyword
+X05%/child::site/child::closed_auctions/child::closed_auction[child::annotation/child::description/child::text/child::keyword]/child::date
+X06%/child::site/child::closed_auctions/child::closed_auction[descendant::keyword]/child::date
+X07%/child::site/child::people/child::person[child::profile/child::gender and child::profile/child::age]/child::name
+X08%/child::site/child::people/child::person[child::phone or child::homepage]/child::name
+X09%/child::site/child::people/child::person[child::address and (child::phone or child::homepage) and (child::creditcard or child::profile)]/child::name
+X10%/descendant::listitem[not(descendant::keyword/child::emph)]/descendant::parlist
+X11%/descendant::listitem[ (descendant::keyword or descendant::emph) and (descendant::emph or descendant::bold)]/child::parlist
+X12%/descendant::people[ descendant::person[not(child::address)] and descendant::person[not(child::watches)]]/child::person[child::watches]
+#%/site/regions/europe/item/mailbox/mail/text/keyword
+#%/site/closed_auctions/closed_auction/annotation/description/parlist/listitem
+#%/site/closed_auctions/closed_auction/annotation/description/parlist/listitem/parlist/listitem/*/descendant::keyword
+#%/site/regions/*/item/descendant::keyword
+#%/site/regions/*/person[ address and (phone or homepage) ]
+#%/descendant::listitem[ descendant::keyword and descendant::emph]/descendant::parlist
+#%/site/regions/*/item[ mailbox/mail/date ]/mailbox/mail
+X13%/child::*[ descendant::* ]
+X14%/descendant::*
+X15%/descendant::*/descendant::*
+X16%/descendant::*/descendant::*/descendant::*
+X17%/descendant::*/descendant::*/descendant::*/descendant::*
+#%/descendant::*/descendant::*/descendant::*/descendant::*/descendant::*/descendant::*
+#%/descendant::*/descendant::*
diff --git a/tests/queries/xmark_all.xml.queries b/tests/queries/xmark_all.xml.queries
new file mode 100644 (file)
index 0000000..5331567
--- /dev/null
@@ -0,0 +1,28 @@
+/child::site/child::closed_auctions
+X02%/child::site/child::regions/child::*/child::item
+X03%/child::site/child::closed_auctions/child::closed_auction/child::annotation/child::description/child::text/child::keyword
+X04%/descendant::listitem/descendant::keyword
+#%/descendant::closed_auction/descendant::keyword
+#%/site/closed_auctions/closed_auction/descendant::keyword
+X05%/child::site/child::closed_auctions/child::closed_auction[child::annotation/child::description/child::text/child::keyword]/child::date
+X06%/child::site/child::closed_auctions/child::closed_auction[descendant::keyword]/child::date
+X07%/child::site/child::people/child::person[child::profile/child::gender and child::profile/child::age]/child::name
+X08%/child::site/child::people/child::person[child::phone or child::homepage]/child::name
+X09%/child::site/child::people/child::person[child::address and (child::phone or child::homepage) and (child::creditcard or child::profile)]/child::name
+X10%/descendant::listitem[not(descendant::keyword/child::emph)]/descendant::parlist
+X11%/descendant::listitem[ (descendant::keyword or descendant::emph) and (descendant::emph or descendant::bold)]/child::parlist
+X12%/descendant::people[ descendant::person[not(child::address)] and descendant::person[not(child::watches)]]/child::person[child::watches]
+#%/site/regions/europe/item/mailbox/mail/text/keyword
+#%/site/closed_auctions/closed_auction/annotation/description/parlist/listitem
+#%/site/closed_auctions/closed_auction/annotation/description/parlist/listitem/parlist/listitem/*/descendant::keyword
+#%/site/regions/*/item/descendant::keyword
+#%/site/regions/*/person[ address and (phone or homepage) ]
+#%/descendant::listitem[ descendant::keyword and descendant::emph]/descendant::parlist
+#%/site/regions/*/item[ mailbox/mail/date ]/mailbox/mail
+X13%/child::*[ descendant::* ]
+X14%/descendant::*
+X15%/descendant::*/descendant::*
+X16%/descendant::*/descendant::*/descendant::*
+X17%/descendant::*/descendant::*/descendant::*/descendant::*
+#%/descendant::*/descendant::*/descendant::*/descendant::*/descendant::*/descendant::*
+#%/descendant::*/descendant::*