X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Fasta.ml;h=f96cd42353bd75fdf0e51b4a996d978a9a5e5aeb;hb=5e7268fb95cdc7e56fe24f324a710550ade3d851;hp=cb4521ef242b9daf6cca0706d7e93c3d5e4935aa;hpb=8beacdfe24b6e93a7c1a4faee4c5587104f5c1ad;p=tatoo.git diff --git a/src/asta.ml b/src/asta.ml index cb4521e..f96cd42 100644 --- a/src/asta.ml +++ b/src/asta.ml @@ -2,8 +2,8 @@ (* *) (* TAToo *) (* *) -(* Lucca Hirschi, ? *) -(* ? *) +(* Lucca Hirschi, LRI UMR8623 *) +(* Université Paris-Sud & CNRS *) (* *) (* Copyright 2010-2012 Université Paris-Sud and Centre National de la *) (* Recherche Scientifique. All rights reserved. This file is *) @@ -13,7 +13,7 @@ (* *) (***********************************************************************) -open Format +(* utils.ml-> INCLUDE "utils.ml" HASHINT2 () *) type state = State.t @@ -35,10 +35,11 @@ struct let la (st,la,f) = la let fo (st,la,f) = f let print fmt (st,la,f) = - Format.fprintf fmt "(%a,%s,%a)" + Format.fprintf fmt "%a ----%s---> %a" State.print st - "TODO la" + (QNameSet.to_string la) Formula.print f + end module SetT = @@ -46,21 +47,27 @@ struct include Set.Make(Transition) end +type transition = Transition.t + type t = { + mutable quer : StateSet.t; mutable reco : StateSet.t; mutable selec : StateSet.t; mutable bottom : StateSet.t; mutable top : StateSet.t; - mutable trans : SetT.t; + mutable trans_q : SetT.t; + mutable trans_r : SetT.t; } exception Not_found_transition exception Transition_not_injective - + let transition asta st lab = let filter (s,l,f) = (State.compare s st = 0) && (QNameSet.compare l lab = 0) in - let tr_set = SetT.elements (SetT.filter filter asta.trans) in + let tr_set = (SetT.elements (SetT.filter filter asta.trans_q)) @ + (SetT.elements (SetT.filter filter asta.trans_r)) + in match tr_set with | [] -> raise Not_found_transition | x::y::z -> raise Transition_not_injective @@ -68,26 +75,91 @@ let transition asta st lab = let transitions asta st = let filter (s,l,f) = State.compare s st = 0 in - let rec remove_states l = match l with + let rec remove_states = function | [] -> [] - | (a,s,l) :: tl -> (s,l) :: (remove_states tl) in - remove_states (SetT.elements (SetT.filter filter asta.trans)) + | (s,l,f) :: tl -> (l,f) :: (remove_states tl) in + (remove_states (SetT.elements (SetT.filter filter asta.trans_q)), + (remove_states (SetT.elements (SetT.filter filter asta.trans_r)))) +let transitions_lab asta lab = + let filter (s,l,f) = QNameSet.mem lab l in + let rec remove_lab = function + | [] -> [] + | (s,l,f) :: tl -> (s,f) :: (remove_lab tl) in + (remove_lab (SetT.elements (SetT.filter filter asta.trans_q)), + (remove_lab (SetT.elements (SetT.filter filter asta.trans_r)))) -let print fmt asta = - let pp = Format.fprintf fmt in - pp "Recognizing states: "; - StateSet.print fmt asta.reco; - pp "\nSelecting states: "; - StateSet.print fmt asta.selec; - pp "\nBottom states: "; - StateSet.print fmt asta.bottom; - pp "\nTop states: "; - StateSet.print fmt asta.top; - pp "\nTransitions: \n"; - Format.fprintf fmt "{@[ %a @]}" (* todo: check boxes *) - (Pretty.print_list ~sep:"@, " (Transition.print)) - (SetT.elements (asta.trans)) +let transitions_st_lab asta q lab = + let filter (s,l,f) = q = s && QNameSet.mem lab l in + let rec remove_st_lab = function + | [] -> [] + | (s,l,f) :: tl -> f :: (remove_st_lab tl) in + (remove_st_lab (SetT.elements (SetT.filter filter asta.trans_q)), + (remove_st_lab (SetT.elements (SetT.filter filter asta.trans_r)))) + +let empty = { + quer = StateSet.empty; + reco = StateSet.empty; + selec = StateSet.empty; + bottom = StateSet.empty; + top = StateSet.empty; + trans_q = SetT.empty; + trans_r = SetT.empty +} + +let any_label = QNameSet.complement (QNameSet.empty) + +let new_state () = State.make() + +let add_tr ast tr flag = + if flag + then ast.trans_q <- (SetT.add tr (ast.trans_q)) + else ast.trans_r <- (SetT.add tr (ast.trans_r)) + +let add_quer ast st = ast.quer <- (StateSet.add st (ast.quer)) +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 init_top ast = ast.top <- (StateSet.empty) + +let top_states ast = StateSet.elements ast.top + +let top_states_s ast = ast.top + +let bot_states_s ast = ast.bottom + +let selec_states ast = ast.selec + +let print fmt asta = + let print_box fmt flag = + let pp = Format.fprintf fmt in + pp "@[# Query states: %a@ @]" + StateSet.print asta.quer; + pp "@[# Recognizing states: %a@ @]" + StateSet.print asta.reco; + pp "@[# Selecting states: %a@ @]" + StateSet.print asta.selec; + pp "@[# Bottom states: %a@ @]" + StateSet.print asta.bottom; + pp "@[# Top states: %a@ @]" + StateSet.print asta.top; + let print_list_tr fmt z = + if SetT.is_empty z + then Format.fprintf fmt "ø" + else + SetT.iter (fun x -> Format.fprintf fmt "| %a @ " Transition.print x) z in + let print_box_list fmt trans = + Format.fprintf fmt " @[%a @]" print_list_tr trans in + Format.fprintf fmt "@[# Queries transitions:@ %a@ @]" + print_box_list asta.trans_q; + Format.fprintf fmt "@[# Recognizing transitions:@ %a@]" + print_box_list asta.trans_r in + Format.fprintf fmt "@[##### ASTA #####@. %a@ @]@." print_box 0 let to_file out asta = ()