Commit 6bb5503e authored by Josh Kunz's avatar Josh Kunz

Removes debugging code.

parent 92889a5e
......@@ -29,10 +29,8 @@ let madd_fact g f =
let mremove_fact g f =
let rec mremove_edge l e =
match l with
| [] -> print_endline "nothing removed."; []
| {out = o; label = la} :: l when o = e.out && la = e.label ->
print_endline "something removed.";
l
| [] -> []
| {out = o; label = la} :: l when o = e.out && la = e.label -> l
| _e :: l -> _e :: mremove_edge l e
in
let e = {out = f.tail; label = f.rel} in
......
......@@ -34,6 +34,9 @@ let rec qtriple_as_string = function
^ (qitem_as_string b) ^ ", "
^ (qitem_as_string c) ^ ")";;
let fact_as_string (f : KG.fact) =
sprintf "fact(%s, %s, %s)" f.head f.rel f.tail;;
let field_match (qf, ef) context =
match qf with
| Variable x ->
......@@ -50,8 +53,6 @@ let field_match (qf, ef) context =
let epairs (q : query_triple) (e : KG.fact) =
[(q.head, e.head); (q.rel, e.rel); (q.tail, e.tail)];;
let fact_as_string (f : KG.fact) = sprintf "fact(%s, %s, %s)" f.head f.rel f.tail;;
(* Checks to see if a given set of pairs 'is a match'. That is to say, that
* all constants are equal, and that all variables can be bound meaningfully.
* This function yeilds true when the pairs all match, and a context that
......@@ -63,15 +64,12 @@ let is_match pairs context =
List.fold_left match_item (true, context) pairs;;
let matches_for graph q context =
printf "Matching with query %s and context: %s\n"
(qtriple_as_string q) (Context.as_string context);
KG.all_facts graph |> List.map fact_as_string |>
String.concat "\n" |> printf "Graph looks like: \n%s\n";
let facts_for_query graph query =
match query.head with
| Value x -> KG.facts_off graph x
| Variable x when Context.mem context x ->
printf "Matching bound variable case...\n";
(* If x is bound to a variable, then we can use only facts with
* that variable binding in their head for the query *)
Context.binding context x |> KG.facts_off graph;
(* If the head of the query is an unbound variable, then we have
* to check against the entire graph *)
......@@ -80,28 +78,16 @@ let matches_for graph q context =
let rec match_facts = function
| [] -> []
| fact :: facts ->
printf "Matching fact %s with query %s and context: %s\n"
(fact_as_string fact) (qtriple_as_string q) (Context.as_string context);
let (did_match, _context) = is_match (epairs q fact) context in
if did_match then
begin
print_endline "Matched!";
(fact, _context) :: (match_facts facts)
end
else
begin
print_endline "Not matched...";
(match_facts facts)
end
in
let test_facts = facts_for_query graph q in
List.map fact_as_string test_facts |>
String.concat "\n" |> printf "Matching against facts: \n%s\n";
test_facts |> match_facts;;
facts_for_query graph q |> match_facts;;
(* -> (graph, context) *)
let rec rquery_graph graph query context path =
Graph.length graph |> printf "Checking against graph of size: %d\n" ;
match query with
| [] -> [(path, context)]
| q :: qs ->
......
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