From efb1ed61a33a2a65690020782cadda413611467a Mon Sep 17 00:00:00 2001 From: Val Date: Tue, 23 Apr 2024 19:25:53 +0200 Subject: [PATCH] Quartz sync: Apr 23, 2024, 7:25 PM --- .../foldInductionRuleCasev2.pl | 19 +++++++++++++++++++ content/functions/compareResults.pl | 3 +++ content/functions/inference.pl | 16 ++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 content/examples/modesOfInference/foldInductionRuleCasev2.pl create mode 100644 content/functions/inference.pl diff --git a/content/examples/modesOfInference/foldInductionRuleCasev2.pl b/content/examples/modesOfInference/foldInductionRuleCasev2.pl new file mode 100644 index 0000000..6399ea1 --- /dev/null +++ b/content/examples/modesOfInference/foldInductionRuleCasev2.pl @@ -0,0 +1,19 @@ +:- use_module(library(scasp)). +:- ensure_loaded('../../functions/inference.pl'). + +ontology(Ontology, Predicates) :- + Ontology = [ + sack(s1), + bean(b1), + white(Y) + ], + Predicates = [sack, bean, from_s1]. + +theory(Case, Result) :- + Case = [ + from_s1(b1), % These beans are from this sack + positive(b1) + ], + Result = white. % These beans are white + +?- ontology(Ontology, Predicates), theory(Case, Result), inference(induction, Ontology, Predicates, [], Case, Result). \ No newline at end of file diff --git a/content/functions/compareResults.pl b/content/functions/compareResults.pl index 6c0b258..a9dfe70 100644 --- a/content/functions/compareResults.pl +++ b/content/functions/compareResults.pl @@ -1,3 +1,6 @@ +expected_model(ExpectedM) :- + ExpectedM = []. + compare_results(Result, Expected) :- sort(Result, SortedResult), sort(Expected, SortedExpected), diff --git a/content/functions/inference.pl b/content/functions/inference.pl new file mode 100644 index 0000000..90807a4 --- /dev/null +++ b/content/functions/inference.pl @@ -0,0 +1,16 @@ +:- use_module(library(scasp)). +:- ensure_loaded('./functions/createBackground.pl'). +:- ensure_loaded('./First-Order-Learner-of-Default/fold.pl'). + +inference(Type, Ontology, Predicates, Rule, Case, Result) :- + append(Ontology, Rule, OR), + append(OR, Case, ORC), + create_background(ORC), + extract_pos_neg(ORC, Positive, Negative), + (Type = deduction -> scasp(Result, [model(M), tree(T)]); + Type = abduction -> scasp(Result, [model(M), tree(T)]); + Type = induction -> fold(Result, Positive, Negative, ORC, Predicates, D, AB, false)). + +extract_pos_neg(Background, Positive, Negative) :- + findall(X, member(positive(X), Background), Positive), + findall(X, member(negative(X), Background), Negative). \ No newline at end of file