From 77e19919f6001b5ea29e707968d97a97d09743d6 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sat, 1 Jun 2024 19:21:04 +0200 Subject: refactor(reasoning): candidate view should always be a refinement of partial Merge the candidate may/must queries with the partial may/must queries so that reasoning in the candidate model uses "Gentzen-style" assumptions about the candidate values of partal symbols that would be computed as unknown. This should not lead to performance degradation, because the corresponding joins were already being computed in the stopping criterion. In many cases, the extra clauses are immediately optimized away by the query optimizer anyways. --- .../translator/PartialRelationTranslator.java | 33 +++++++++++++++------- .../TypeHierarchyPartialModelTest.java | 6 ++-- 2 files changed, 26 insertions(+), 13 deletions(-) (limited to 'subprojects/store-reasoning/src') diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/PartialRelationTranslator.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/PartialRelationTranslator.java index 1c3f6a6d..a9031f4c 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/PartialRelationTranslator.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/PartialRelationTranslator.java @@ -52,6 +52,8 @@ public final class PartialRelationTranslator extends PartialSymbolTranslator builder + .clause( + candidateMay.call(arguments), + may.call(arguments) + )); + } + if (candidateMustMerged == null) { + candidateMustMerged = createQuery("candidateMustMerged", (builder, arguments) -> builder + .clause(candidateMust.call(arguments)) + .clause(must.call(arguments))); + } + } + private void createFallbackRewriter() { if (rewriter == null) { - rewriter = new QueryBasedRelationRewriter(may, must, candidateMay, candidateMust); + rewriter = new QueryBasedRelationRewriter(may, must, candidateMayMerged, candidateMustMerged); } } private void createFallbackInterpretation() { if (interpretationFactory == null) { - interpretationFactory = new QueryBasedRelationInterpretationFactory(may, must, candidateMay, candidateMust); + interpretationFactory = new QueryBasedRelationInterpretationFactory(may, must, candidateMayMerged, + candidateMustMerged); } } @@ -354,14 +375,6 @@ public final class PartialRelationTranslator extends PartialSymbolTranslator { var literals = new ArrayList(parameters.length + 1); diff --git a/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/typehierarchy/TypeHierarchyPartialModelTest.java b/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/typehierarchy/TypeHierarchyPartialModelTest.java index e87b2684..85147921 100644 --- a/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/typehierarchy/TypeHierarchyPartialModelTest.java +++ b/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/typehierarchy/TypeHierarchyPartialModelTest.java @@ -149,7 +149,7 @@ class TypeHierarchyPartialModelTest { var personCandidateInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.CANDIDATE, person); assertThat(personCandidateInterpretation.get(Tuple.of(1)), is(TruthValue.TRUE)); - assertThat(personCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE)); + assertThat(personCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.ERROR)); var memberInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.PARTIAL, member); assertThat(memberInterpretation.get(Tuple.of(1)), is(TruthValue.TRUE)); @@ -157,7 +157,7 @@ class TypeHierarchyPartialModelTest { var memberCandidateInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.CANDIDATE, member); assertThat(memberCandidateInterpretation.get(Tuple.of(1)), is(TruthValue.TRUE)); - assertThat(memberCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE)); + assertThat(memberCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.ERROR)); var studentInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.PARTIAL, student); assertThat(studentInterpretation.get(Tuple.of(1)), is(TruthValue.FALSE)); @@ -165,7 +165,7 @@ class TypeHierarchyPartialModelTest { var studentCandidateInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.CANDIDATE, student); assertThat(studentCandidateInterpretation.get(Tuple.of(1)), is(TruthValue.FALSE)); - assertThat(studentCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.FALSE)); + assertThat(studentCandidateInterpretation.get(Tuple.of(3)), is(TruthValue.ERROR)); var teacherInterpretation = reasoningAdapter.getPartialInterpretation(Concreteness.PARTIAL, teacher); assertThat(teacherInterpretation.get(Tuple.of(1)), is(TruthValue.TRUE)); -- cgit v1.2.3-54-g00ecf