X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=xPath.ml;h=6c88d9a32cc97ec229fae2785b2104ca80aaf6f1;hb=04630ec1de987f525c6594fcada17bb49ee79d6a;hp=727c25e425c1853be28c1dc19de1a0a4363a8117;hpb=3623eefccfb5fc69e19ad975a3669f51a2a8b276;p=SXSI%2Fxpathcomp.git diff --git a/xPath.ml b/xPath.ml index 727c25e..6c88d9a 100644 --- a/xPath.ml +++ b/xPath.ml @@ -190,14 +190,19 @@ module Functions = struct type value = [ `NodeSet of Automaton.BST.t | `Int of int | `String of string | `Bool of bool | `True | `False ] + type expr = [ value | `Call of (string*(expr list)) - | `Auto of Automaton.t ] + | `Auto of Automaton.t | `Contains of expr list ] let count = function [`NodeSet(s) ] -> `Int(Automaton.BST.cardinal s) | _ -> failwith "count" - + let contains_old = function [`NodeSet(s) ; `String(str) ] -> + `Bool(Automaton.BST.exists (fun tree -> Tree.Binary.contains_old tree str + ) s) + | _ -> failwith "contains_old" + let equal = function [ `Int i; `Int j ] -> `Bool (i == j) |_ -> failwith "equal" @@ -205,17 +210,29 @@ module Functions = struct ("count",count); ("equal",equal); + ("contains_old",contains_old); ] let text t = Tree.Binary.string (Tree.Binary.left t) let rec eval_expr tree (e:expr) : value = match e with | `Call (f,args) -> (List.assoc f globals) (List.map (eval_expr tree) args) - | `Auto(a) -> `NodeSet(ignore (Automaton.BottomUp.accept a tree);a.Automaton.result) + | `Auto(a) -> `NodeSet(ignore (Automaton.BottomUp.accept a tree); + a.Automaton.result) + | `Contains(args) -> + begin + match args with + [ `Auto(a); `String(s) ] -> + let docs = Tree.Binary.contains tree s + in + let _ = Automaton.BottomUp.accept ~strings:(Some docs) a tree + in `NodeSet(a.Automaton.result) + | _ -> failwith "contains invalid" + end | #value as x -> x let truth_value = - function `NodeSet s -> Automaton.BST.is_empty s + function `NodeSet s -> not (Automaton.BST.is_empty s) |`Bool(b) -> b | _ -> failwith "truth_value" @@ -321,6 +338,7 @@ module Compile = struct (* q' is not returned and thus not added to the set of final states. It's ok since we should never be in a final state on a node <@> *) + | Attribute,ts -> let q'' = State.mk() in (mk_tag_t Left q (TagSet.Xml.attribute) q' ignore):: (mk_tag_t Left q' (ts) q'' ignore)::( q==> any @@ (ignore,q))::trs, q''::q'::final,initial @@ -358,6 +376,7 @@ module Compile = struct | Path p -> `Auto(compile p) | Int i -> `Int i | String s -> `String s + | Function ("contains",elist) ->`Contains(List.map compile_expr elist) | Function (f,elist) -> `Call(f,List.map compile_expr elist) and cup a b = match a,b with