% Copyright (C) 2013 Peter Schueller % % required_equivalence/4(G,EQ,N1,N2): % % for each (G,EQ), collect all pairs (N1,N2) % => require to unify at least one of these pairs (N1,N2) % (similar to Minimal Recursion Semantics equivalence conditions) % % define equivalence class equivalenceclass(G,EQ) :- required_equivalence(G,EQ,_,_). % guess which equivalence class is used 1 { applyequivalence(G,N1,N2) : required_equivalence(G,EQ,N1,N2) } :- equivalenceclass(G,EQ), not skip_required_equivalence. % % activated knowledge % % this is activatable background knowledge that matches % a node (name, type) in other activated knowledge % (we will define the input graph(s) as activated and this rule activates the rest) % activated_because(G,Node) :- gactivatable(G,Node), gn(G,Node), gp(G,Node,type,Type), gp(G,Node,name,Name), activated(OG,_), OG != G, gn(OG,ON), gp(OG,ON,type,Type), gp(OG,ON,name,Name). activated(G,1) :- activated_because(G,Node). %%%%%%%%%%%%%%% % % do the mixing % %%%%%%%%%%%%%%% % % deterministic mix graph (activatable knowledge) % % import g1 into mix gimport(mix,g1,1,none). % import all background graphs into mix gimport(mix,G,1,none) :- gactivatable(G,_). %gprintrepresentatives(mix,none). %gprint(mix). % % nondeterministic result graph (activated and merged knowledge) % (in fact we deactivate what we will not need for sure and we abduce what else % to deactivate, this way we achieve to have only one nondeterministic graph % layer - conjectured this is faster) % % % mark activated knowledge and guess used knowledge % % g1 is clearly activated activated(g1,1). % guess which activated knowledge is used { used(G,A) } :- activated(G,A). % g1 is always used used(g1,1). %print(@concat(("activated graph ",G))) :- activated(G), G != g1. print(@concat(("used graph ",G,"/",A))) :- used(G,A). print(@concat(("unused activated graph ",G,"/",A))) :- activated(G,A), not used(G,A). % remove what is not used gremove(merge,mix,i(G,N,A)) :- gn(mix,i(G,N,A)), not used(G,A). % % guess equivalence contractions % % do forced equivalence contractions gcontract(merge,mix,i(G,N1,1),i(G,N2,1)) :- applyequivalence(G,N1,N2). % guess equivalences between all pairs of used graphs gguesscontractions_intergraph(mix,merge,G1,A1,G2,A2) :- mix, used(G1,A1), used(G2,A2), G1 < G2. gimport(res,mix,1,merge). %gprintrepresentatives(mix,merge). gprint(res). %%%%%%%%%%%%%%%%%%%%%%% % % determine correctness % %%%%%%%%%%%%%%%%%%%%%%% % good if N1 and N2 from G obtain same Target in res (= are collapsed) good :- correct_result(G,N1,N2), gntarget(res,Target,mix,i(G,N1,_),_), gntarget(res,Target,mix,i(G,N2,_),_). bad :- not good. print("Correct Result!") :- good. error("Wrong Result!","") :- bad. % % configure output/projection % %#hide. #show gn/2. #show gp/4. #show ge/3. #show print/1. #show gprint/1. #show error/2. #show good/0. #show bad/0. #show schema1/0. #show schema2/0.