./test.native ./tests/docs/tiny.xml '/child::site/child::regions'
+echo "\n"
./test.native ./tests/docs/tiny.xml -f ./tests/queries/Treebank.xml.queries
+echo "\n"
./test.native ./tests/docs/tiny.xml '/descendant::listitem[not(descendant::keyword/child::emph)]/descendant::parlist'
let print fmt (st,la,f) =
Format.fprintf fmt "(%a,%s,%a)"
State.print st
- "TODO la"
+ (QNameSet.to_string la)
Formula.print f
end
include Set.Make(Transition)
end
+type transition = Transition.t
+
type t = {
mutable reco : StateSet.t;
mutable selec : StateSet.t;
| (a,s,l) :: tl -> (s,l) :: (remove_states tl) in
remove_states (SetT.elements (SetT.filter filter asta.trans))
-let dummy = {
+let empty = {
reco = StateSet.empty;
selec = StateSet.empty;
bottom = StateSet.empty;
trans = SetT.empty;
}
+let any_label = QNameSet.complement (QNameSet.empty)
+
+let new_state () = State.make()
+
+let add_tr ast tr = ast.trans <- (SetT.add tr (ast.trans))
+
+let add_reco ast st = ast.reco <- (StateSet.add st (ast.reco))
+
+let add_selec ast st = ast.selec <- (StateSet.add st (ast.selec))
+
+let add_bot ast st = ast.bottom <- (StateSet.add st (ast.bottom))
+
+let add_top ast st = ast.top <- (StateSet.add st (ast.top))
+
+let top_states ast = StateSet.elements ast.top
let print fmt asta =
let pp = Format.fprintf fmt in
(* *)
(* TAToo *)
(* *)
-(* Lucca Hirschi, ? *)
-(* ? *)
+(* Lucca Hirschi, ? *)
+(* ? *)
(* *)
(* Copyright 2010-2012 Université Paris-Sud and Centre National de la *)
(* Recherche Scientifique. All rights reserved. This file is *)
(** Implementation of alternating selecting tree automata (ASTA) *)
-type state
+type state = State.t
(** The type of states *)
-type label
+type label = QNameSet.t
(** The type of labels of the transitions *)
-type formula
+type formula = Formula.t
(** The type of transition formulae *)
+type transition = (state*label*formula)
+(** The type of transitions *)
+
type t
(** The type of ASTAs *)
val transitions : t -> state -> (label*formula) list
(** Give the list of labels and formulae from transitions for a given state *)
-val dummy : t
+val empty : t
(** The empty automaton *)
+val any_label : label
+(** Set of all labels which can occur in a tree *)
+
+val new_state : unit -> state
+(** Give a new state (different from all others states) *)
+
+val add_tr : t -> transition -> unit
+(** Add a transition to an asta *)
+
+val add_reco : t -> state -> unit
+(** Add a state to the recognizing states of an asta *)
+
+val add_selec : t -> state -> unit
+(** Add a state to the recognizing states of an asta *)
+
+val add_bot : t -> state -> unit
+(** Add a state to the bottom states of an asta *)
+
+val add_top : t -> state -> unit
+(** Add a state to the top states of an asta *)
+
+val top_states : t -> state list
+(** Give the list of top states of an ASTA *)
+
val print : Format.formatter -> t -> unit
(** Describe the automaton as text *)
(* *)
(***********************************************************************)
-let trad qu = Asta.dummy
+open XPath.Ast
+open Formula.Infix
+
+exception Not_core_XPath of path
+(** Raised whenever the XPath query contains not implemented structures *)
+
+let trans query =
+ let asta = Asta.empty in
+ let rec trans = function
+ | [s] -> trans_last s
+ | s :: tl -> trans_step s; trans tl
+ | [] -> ()
+
+ and trans_init () = (* add THE top state *)
+ let top_st = Asta.new_state () in
+ let or_top =
+ List.fold_left (fun acc x -> (`Left *+ x +| acc))
+ Formula.true_ (Asta.top_states asta)
+ in
+ Asta.add_tr asta (top_st, Asta.any_label, or_top)
+
+ and trans_last (ax,test,pred) = (* a selecting state is needed *)
+ ()
+
+ and trans_step (ax,test,pred) =
+ ()
+
+ and trans_pr p = ()
+
+ in
+ match query with
+ | Absolute steps -> trans_init(); trans steps; asta
+ | AbsoluteDoS steps as x -> raise (Not_core_XPath x)
+ | Relative steps as x -> raise (Not_core_XPath x)
(** Implementation of compilation from XPath queries into ASTA *)
-val trad : XPath.Ast.path -> Asta.t
+
+val trans : XPath.Ast.path -> Asta.t
(** Compilation function *)
include FiniteCofinite.Make(Ptset.Make(QName))
module Weak = FiniteCofinite.Weak(Ptset.Weak(QName))
+
+(* BEGIN : Lucca Hirschi *)
+let to_string set =
+ String.concat " "
+ [
+ (match (kind set) with
+ | `Finite -> "F("
+ | `Cofinite -> "Cof(")
+ ;
+ if is_empty (complement set) then
+ "ø"
+ else
+ ( String.concat " "
+ (List.map (fun name -> QName.to_string name) (elements (complement set))))
+ ;
+ ")"
+ ]
+(* END : Lucca Hirschi *)
include FiniteCofinite.S with type elt = QName.t
module Weak : FiniteCofinite.S with type elt = QName.t
+
+val to_string : t -> string
+(** Lucca Hirschi: print *)
open Format
-let asta = Compil.trad query
+let asta = Compil.trans query
let () =
fprintf err_formatter "Query: %a\n%!" XPath.Ast.print query;