From 4ef83e49878441a5146af5326c1b49ced4002756 Mon Sep 17 00:00:00 2001 From: kim Date: Wed, 11 Mar 2009 04:03:20 +0000 Subject: [PATCH] bug fixes, added the count queries git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/xpathcomp@246 3cdefd35-fc62-479d-8e8d-bae585ffb9ca --- Makefile | 2 +- ata.ml | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ata.mli | 1 + main.ml | 4 +++- 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 024552f..38b2b26 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ OCAMLOPT = ocamlopt -g -cc "$(CXX)" SYNT_DEBUG = -ppopt -DDEBUG else CXX = g++ -OCAMLOPT = ocamlopt -cc "$(CXX)" -ccopt -O3 -ccopt -std=c++0x -noassert -inline $(INLINE) +OCAMLOPT = ocamlopt -g -unsafe -cc "$(CXX)" -ccopt -O3 -ccopt -std=c++0x -noassert -inline $(INLINE) endif ifeq ($(PROFILE), true) SYNT_PROF = $(SYNT_DEBUG) -ppopt -DPROFILE diff --git a/ata.ml b/ata.ml index d17c0c8..fc29e98 100644 --- a/ata.ml +++ b/ata.ml @@ -706,6 +706,73 @@ type t = { let st,res = accepting_among a t a.init t in if Ptset.is_empty (st) then TS.empty else res + let rec accepting_among_count a t r ctx = + let orig = r in + let rest = Ptset.inter r a.final in + let r = Ptset.diff r rest in + if Ptset.is_empty r then rest,0 else + if Tree.is_node t + then + let ((ls,lls),(rs,rrs)),formula,mark,has_true,r' = + let tag = Tree.tag t in + get_trans t a tag r + in + let tl = tags a ls + and tr = tags a rs + and tll = tags a lls + and trr = tags a rrs + in + let first = + if Ptset.mem Tag.pcdata (pt_cup tl tll) + then + Tree.text_below t + else + let etl = Ptset.is_empty tl + and etll = Ptset.is_empty tll + in + if etl && etll + then Tree.mk_nil t + else + if etl then Tree.tagged_desc_only t tll + else if etll then Tree.first_child t + else (* add child only *) + Tree.tagged_below t tl tll + and next = + if Ptset.mem Tag.pcdata (pt_cup tr trr) + then + Tree.text_next t ctx + else + let etr = Ptset.is_empty tr + and etrr = Ptset.is_empty trr + in + if etr && etrr + then Tree.mk_nil t + else + if etr then Tree.tagged_foll_only t trr ctx + else if etrr then Tree.next_sibling t + else (* add ns only *) + Tree.tagged_next t tr trr ctx + + in + let s1,res1 = accepting_among_count a first (pt_cup ls lls) t + and s2,res2 = accepting_among_count a next (pt_cup rs rrs) ctx + in + let rb,rb1,rb2 = eval_form_bool formula s1 s2 in + if rb + then + let res1 = if rb1 then res1 else 0 + and res2 = if rb2 then res2 else 0 + in r', res2 + (if mark then 1 + res1 else res1) + else Ptset.empty,0 + + + + else orig,0 + + + let run_count a t = + let st,res = accepting_among_count a t a.init t in + if Ptset.is_empty (st) then 0 else res diff --git a/ata.mli b/ata.mli index 593a39e..bf9368f 100644 --- a/ata.mli +++ b/ata.mli @@ -78,6 +78,7 @@ end (*module BottomUpJumpNew : sig *) val run : t -> Tree.Binary.t -> TS.t + val run_count : t -> Tree.Binary.t -> int val run_time : t -> Tree.Binary.t -> TS.t (*end *) diff --git a/main.ml b/main.ml index 8264278..ab043b7 100644 --- a/main.ml +++ b/main.ml @@ -59,7 +59,9 @@ let main v query output = Printf.eprintf "Execution time %s : " (if !Options.count_only then "(counting only)" else ""); begin if !Options.count_only then - failwith "Count only not implemented in this version" + let r = time ( run_count auto )v in + let _ = Printf.eprintf "Number of nodes in the result set : %i\n%!" r + in () else (* let _ = Gc.set ({ Gc.get() with Gc.max_overhead = 1000000; Gc.space_overhead = 100 }) in *) let result = time (if !Options.time then run_time auto else run auto) v in -- 2.17.1