Commit 5d3c1168 authored by SALVATI Sylvain's avatar SALVATI Sylvain

Mise a jour de details sur le parser datalog

parent 56c9e5e5
......@@ -272,11 +272,32 @@ struct
program
(It(magic,[0])::(List.rev facts))
let init_solver3 program init_state list magic =
let Prog(sign,_) = program in
let facts =
List.fold_left
(function l ->
function (string,(state1,state2)) ->
try
let (_,pred) = Signature.find_pred_of_name string sign in
It(pred,[state1;state2])::l
with
Not_found ->
failwith ("init_solver3: predicate '"^string^"' is not defined.")
)
[]
list
in
init_solver
program
(It(magic,[init_state])::(List.rev facts))
let solve program facts = naive_solve(init_solver program facts)
let solve2 program list magic = naive_solve(init_solver2 program list magic)
let solve3 program init_state list magic = naive_solve(init_solver3 program init_state list magic)
let print_chart (M(sign,chart,_,_,_,step,_,_)) =
let res = Array.make (step+1) [] in
let _ =
......
init = s;
s(x1 y1 x2 y2) :- p(x1,x2) q(y1,y2);
p("a1" "a2", "a3" "a4");
p("a1" x1 "a2","a3" x2 "a4") :- p(x1,x2);
q("b1" "b2", "b3" "b4");
q("b1" y1 "b2","b3" y2 "b4") :- q(y1,y2);
init = S;
S(x "b" x) :- A(x);
A("a");
......@@ -71,7 +71,32 @@ module Kanazawa_transform =
let (map,prog) = Magic_set_rewritting.magic ad_program in
(Magic_set_rewritting.Adorned_predicate_map.find goal map,prog)
let transform_pmcfg_0 grammar =
let program =
PMCFG.naive_program_of_pmcfg (Oriented_pmcfg.orient_grammar grammar)
in
let Program.Prog(Signature.S (l,_,neq),_) = program in
let n = List.length l in
let program = Prefix_correct_program.prefix_correct_transform exceptions program in
let PMCFG.Grammar(_,_,init_id) = grammar in
let goal = Adornment.AdP(init_id,[true;false]) in
let ad_program =
Adornment.adorn_program
program
goal
(is_impermissible n)
(Adornment.compare_adornments3 neq)
in
let _ =
print_string
(Program_printer.print_program
(Adornment.program_of_adorned_program ad_program)
)
in
let (map,prog) = Magic_set_rewritting.magic ad_program in
(Magic_set_rewritting.Adorned_predicate_map.find goal map,prog)
let transform_pmcfg_1 grammar =
let program =
PMCFG.program_of_pmcfg (Oriented_pmcfg.orient_grammar grammar)
......
......@@ -20,8 +20,9 @@ struct
match grammar with
Grammar (_,rules,_) ->
List.filter (is_rule_defining_cat cat) rules
let program_of_pmcfg grammar =
let program_of_pmcfg_gen grammar is_naive =
match grammar with
Grammar (sign,rules,init) ->
let new_sign =
......@@ -139,13 +140,22 @@ struct
(function s ->
function id ->
function rules ->
(Program.Cl(Program.Pred(rg_eq,[0;2;3;5]),
[Program.Pred(neq,[0;2]);
Program.Pred(id,[0;1]);
Program.Pred(id,[3;4]);
Program.Pred(rg_eq,[1;2;4;5])
]
))
(if is_naive
then
(Program.Cl(Program.Pred(rg_eq,[0;2;3;5]),
[Program.Pred(id,[0;1]);
Program.Pred(id,[3;4]);
Program.Pred(rg_eq,[1;2;4;5])
]
))
else
(Program.Cl(Program.Pred(rg_eq,[0;2;3;5]),
[Program.Pred(neq,[0;2]);
Program.Pred(id,[0;1]);
Program.Pred(id,[3;4]);
Program.Pred(rg_eq,[1;2;4;5])
]
)))
::
rules
)
......@@ -168,4 +178,7 @@ struct
let eq_clauses = get_eq_clauses string_predicates in
Program.Prog (new_sign,(clauses @ eq_clauses))
let program_of_pmcfg grammar = program_of_pmcfg_gen grammar false
let naive_program_of_pmcfg grammar = program_of_pmcfg_gen grammar true
end
......@@ -43,16 +43,18 @@ let ch_in = open_in "kan.pmcfg";;
(*parsing the grammar*)
let grammar = PMCFG_syn.parse (Stream.of_channel ch_in);;
(*transforming the grammar *)
(*Kanazawa_transform.transform_pmcfg_1 is for simple equality*)
(*Kanazawa_transform.transform_pmcfg_2 is for structural equality*)
let ((start,magic),program) = Kanazawa_transform.transform_pmcfg_1 grammar;;
(*let ((start,magic),program) = Kanazawa_transform.transform_pmcfg_2 grammar;;*)
(*let ((start,magic),program) = Kanazawa_transform.transform_pmcfg_1 is for simple equality*)
(*let ((start,magic),program)Kanazawa_transform.transform_pmcfg_2 is for structural equality*)
(*let ((start,magic),program) = Kanazawa_transform.transform_pmcfg_0 grammar;;*)
(*let ((start,magic),program) = Kanazawa_transform.transform_pmcfg_1 grammar;;*)
let ((start,magic),program) = Kanazawa_transform.transform_pmcfg_2 grammar;;
(*printing the resulting datalog program*)
print_string (Program_printer.print_program program);;
(*sentence to analyse as a list of extensional predicate*)
(*the list [a1;...;an] is translated in the extensional db a1(0,1),...,an(n-1,n)*)
(*NB: ["ab"] is different from ["a";"b"]*)
let sentence = ["a1";"a2";"b1";"b2";"a3";"a4";"b3";"b4"];;
let sentence = ["a";"a";"a";"a";"b";"b";"b"];;
(*let sentence = ["a";"a";"a";"a";"a";"b";"b";"b"];;*)
(*analysing sentence*)
let mem = Datalog_solver.solve2 program sentence magic;;
(*presenting the chart in a stepwise fashion*)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment