diff options
author | 2023-04-21 02:12:04 +0200 | |
---|---|---|
committer | 2023-04-21 02:34:52 +0200 | |
commit | ea0f09096afe05e2d414c707584e1e33c0c44383 (patch) | |
tree | 60763156db85be14e34aaf1b504ccbd1faad8bff /subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning | |
parent | fix: REAL_SUM input and result type (diff) | |
download | refinery-ea0f09096afe05e2d414c707584e1e33c0c44383.tar.gz refinery-ea0f09096afe05e2d414c707584e1e33c0c44383.tar.zst refinery-ea0f09096afe05e2d414c707584e1e33c0c44383.zip |
refactor: simplify ModelAdapter
* Remove the reflection-based machinery around adapter types.
* Adapter builders, store adapters, and model adapters are now only associated
with each other based on static and runtime types.
* Simplifies writing new adapters.
* Hierarchical syntax for adding adapter builders to the store builder.
Diffstat (limited to 'subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning')
9 files changed, 19 insertions, 58 deletions
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/Reasoning.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/Reasoning.java deleted file mode 100644 index 3d3df2b2..00000000 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/Reasoning.java +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.reasoning; | ||
7 | |||
8 | import tools.refinery.store.reasoning.internal.ReasoningBuilderImpl; | ||
9 | import tools.refinery.store.adapter.ModelAdapterBuilderFactory; | ||
10 | import tools.refinery.store.model.ModelStoreBuilder; | ||
11 | import tools.refinery.store.reasoning.representation.PartialRelation; | ||
12 | |||
13 | public final class Reasoning extends ModelAdapterBuilderFactory<ReasoningAdapter, | ||
14 | ReasoningStoreAdapter, ReasoningBuilder> { | ||
15 | public static final Reasoning ADAPTER = new Reasoning(); | ||
16 | |||
17 | public static final PartialRelation EXISTS = new PartialRelation("exists", 1); | ||
18 | |||
19 | public static final PartialRelation EQUALS = new PartialRelation("equals", 1); | ||
20 | |||
21 | private Reasoning() { | ||
22 | super(ReasoningAdapter.class, ReasoningStoreAdapter.class, ReasoningBuilder.class); | ||
23 | } | ||
24 | |||
25 | @Override | ||
26 | public ReasoningBuilder createBuilder(ModelStoreBuilder storeBuilder) { | ||
27 | return new ReasoningBuilderImpl(storeBuilder); | ||
28 | } | ||
29 | } | ||
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/ReasoningAdapter.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/ReasoningAdapter.java index 8dedddf7..8f319242 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/ReasoningAdapter.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/ReasoningAdapter.java | |||
@@ -6,12 +6,15 @@ | |||
6 | package tools.refinery.store.reasoning; | 6 | package tools.refinery.store.reasoning; |
7 | 7 | ||
8 | import tools.refinery.store.adapter.ModelAdapter; | 8 | import tools.refinery.store.adapter.ModelAdapter; |
9 | import tools.refinery.store.query.ResultSet; | ||
10 | import tools.refinery.store.query.dnf.Dnf; | ||
9 | import tools.refinery.store.reasoning.representation.AnyPartialSymbol; | 11 | import tools.refinery.store.reasoning.representation.AnyPartialSymbol; |
12 | import tools.refinery.store.reasoning.representation.PartialRelation; | ||
10 | import tools.refinery.store.reasoning.representation.PartialSymbol; | 13 | import tools.refinery.store.reasoning.representation.PartialSymbol; |
11 | import tools.refinery.store.query.dnf.Dnf; | ||
12 | import tools.refinery.store.query.ResultSet; | ||
13 | 14 | ||
14 | public interface ReasoningAdapter extends ModelAdapter { | 15 | public interface ReasoningAdapter extends ModelAdapter { |
16 | PartialRelation EXISTS = new PartialRelation("exists", 1); | ||
17 | |||
15 | @Override | 18 | @Override |
16 | ReasoningStoreAdapter getStoreAdapter(); | 19 | ReasoningStoreAdapter getStoreAdapter(); |
17 | 20 | ||
@@ -23,5 +26,5 @@ public interface ReasoningAdapter extends ModelAdapter { | |||
23 | 26 | ||
24 | <A, C> PartialInterpretation<A, C> getPartialInterpretation(PartialSymbol<A, C> partialSymbol); | 27 | <A, C> PartialInterpretation<A, C> getPartialInterpretation(PartialSymbol<A, C> partialSymbol); |
25 | 28 | ||
26 | ResultSet getLiftedResultSet(Dnf query); | 29 | ResultSet<Boolean> getLiftedResultSet(Dnf query); |
27 | } | 30 | } |
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/ReasoningBuilder.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/ReasoningBuilder.java index df7b6e4d..d3a337e8 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/ReasoningBuilder.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/ReasoningBuilder.java | |||
@@ -29,5 +29,5 @@ public interface ReasoningBuilder extends ModelAdapterBuilder { | |||
29 | Dnf lift(Modality modality, Dnf query); | 29 | Dnf lift(Modality modality, Dnf query); |
30 | 30 | ||
31 | @Override | 31 | @Override |
32 | ReasoningStoreAdapter createStoreAdapter(ModelStore store); | 32 | ReasoningStoreAdapter build(ModelStore store); |
33 | } | 33 | } |
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/internal/ReasoningAdapterImpl.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/internal/ReasoningAdapterImpl.java index 96514d36..33b6f3c6 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/internal/ReasoningAdapterImpl.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/internal/ReasoningAdapterImpl.java | |||
@@ -37,7 +37,7 @@ public class ReasoningAdapterImpl implements ReasoningAdapter { | |||
37 | } | 37 | } |
38 | 38 | ||
39 | @Override | 39 | @Override |
40 | public ResultSet getLiftedResultSet(Dnf query) { | 40 | public ResultSet<Boolean> getLiftedResultSet(Dnf query) { |
41 | return null; | 41 | return null; |
42 | } | 42 | } |
43 | } | 43 | } |
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/internal/ReasoningBuilderImpl.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/internal/ReasoningBuilderImpl.java index 49f7c7d3..aa71496c 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/internal/ReasoningBuilderImpl.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/internal/ReasoningBuilderImpl.java | |||
@@ -7,16 +7,12 @@ package tools.refinery.store.reasoning.internal; | |||
7 | 7 | ||
8 | import tools.refinery.store.adapter.AbstractModelAdapterBuilder; | 8 | import tools.refinery.store.adapter.AbstractModelAdapterBuilder; |
9 | import tools.refinery.store.model.ModelStore; | 9 | import tools.refinery.store.model.ModelStore; |
10 | import tools.refinery.store.model.ModelStoreBuilder; | 10 | import tools.refinery.store.query.dnf.Dnf; |
11 | import tools.refinery.store.reasoning.ReasoningBuilder; | 11 | import tools.refinery.store.reasoning.ReasoningBuilder; |
12 | import tools.refinery.store.reasoning.literal.Modality; | 12 | import tools.refinery.store.reasoning.literal.Modality; |
13 | import tools.refinery.store.query.dnf.Dnf; | ||
14 | |||
15 | public class ReasoningBuilderImpl extends AbstractModelAdapterBuilder implements ReasoningBuilder { | ||
16 | public ReasoningBuilderImpl(ModelStoreBuilder storeBuilder) { | ||
17 | super(storeBuilder); | ||
18 | } | ||
19 | 13 | ||
14 | public class ReasoningBuilderImpl extends AbstractModelAdapterBuilder<ReasoningStoreAdapterImpl> | ||
15 | implements ReasoningBuilder { | ||
20 | @Override | 16 | @Override |
21 | public ReasoningBuilder liftedQuery(Dnf liftedQuery) { | 17 | public ReasoningBuilder liftedQuery(Dnf liftedQuery) { |
22 | return null; | 18 | return null; |
@@ -24,11 +20,12 @@ public class ReasoningBuilderImpl extends AbstractModelAdapterBuilder implements | |||
24 | 20 | ||
25 | @Override | 21 | @Override |
26 | public Dnf lift(Modality modality, Dnf query) { | 22 | public Dnf lift(Modality modality, Dnf query) { |
23 | checkNotConfigured(); | ||
27 | return null; | 24 | return null; |
28 | } | 25 | } |
29 | 26 | ||
30 | @Override | 27 | @Override |
31 | public ReasoningStoreAdapterImpl createStoreAdapter(ModelStore store) { | 28 | public ReasoningStoreAdapterImpl doBuild(ModelStore store) { |
32 | return null; | 29 | return null; |
33 | } | 30 | } |
34 | } | 31 | } |
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/lifting/DnfLifter.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/lifting/DnfLifter.java index 157f06e8..594005f1 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/lifting/DnfLifter.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/lifting/DnfLifter.java | |||
@@ -14,7 +14,7 @@ import tools.refinery.store.query.literal.CallPolarity; | |||
14 | import tools.refinery.store.query.literal.Literal; | 14 | import tools.refinery.store.query.literal.Literal; |
15 | import tools.refinery.store.query.term.DataVariable; | 15 | import tools.refinery.store.query.term.DataVariable; |
16 | import tools.refinery.store.query.term.Variable; | 16 | import tools.refinery.store.query.term.Variable; |
17 | import tools.refinery.store.reasoning.Reasoning; | 17 | import tools.refinery.store.reasoning.ReasoningAdapter; |
18 | import tools.refinery.store.reasoning.literal.ModalConstraint; | 18 | import tools.refinery.store.reasoning.literal.ModalConstraint; |
19 | import tools.refinery.store.reasoning.literal.Modality; | 19 | import tools.refinery.store.reasoning.literal.Modality; |
20 | import tools.refinery.store.reasoning.literal.PartialLiterals; | 20 | import tools.refinery.store.reasoning.literal.PartialLiterals; |
@@ -74,8 +74,8 @@ public class DnfLifter { | |||
74 | } | 74 | } |
75 | for (var quantifiedVariable : quantifiedVariables) { | 75 | for (var quantifiedVariable : quantifiedVariables) { |
76 | // Quantify over data variables that are not already quantified with the expected modality. | 76 | // Quantify over data variables that are not already quantified with the expected modality. |
77 | liftedLiterals.add(new CallLiteral(CallPolarity.POSITIVE, new ModalConstraint(modality, Reasoning.EXISTS), | 77 | liftedLiterals.add(new CallLiteral(CallPolarity.POSITIVE, |
78 | List.of(quantifiedVariable))); | 78 | new ModalConstraint(modality, ReasoningAdapter.EXISTS), List.of(quantifiedVariable))); |
79 | } | 79 | } |
80 | builder.clause(liftedLiterals); | 80 | builder.clause(liftedLiterals); |
81 | return changed || !quantifiedVariables.isEmpty(); | 81 | return changed || !quantifiedVariables.isEmpty(); |
@@ -87,7 +87,7 @@ public class DnfLifter { | |||
87 | callLiteral.getPolarity() == CallPolarity.POSITIVE && | 87 | callLiteral.getPolarity() == CallPolarity.POSITIVE && |
88 | callLiteral.getTarget() instanceof ModalConstraint modalConstraint && | 88 | callLiteral.getTarget() instanceof ModalConstraint modalConstraint && |
89 | modalConstraint.modality() == modality && | 89 | modalConstraint.modality() == modality && |
90 | modalConstraint.constraint().equals(Reasoning.EXISTS)) { | 90 | modalConstraint.constraint().equals(ReasoningAdapter.EXISTS)) { |
91 | return callLiteral.getArguments().get(0); | 91 | return callLiteral.getArguments().get(0); |
92 | } | 92 | } |
93 | return null; | 93 | return null; |
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RelationRefinementAction.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RelationRefinementAction.java index e4c702ea..0beee248 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RelationRefinementAction.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/rule/RelationRefinementAction.java | |||
@@ -5,7 +5,7 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.store.reasoning.rule; | 6 | package tools.refinery.store.reasoning.rule; |
7 | 7 | ||
8 | import tools.refinery.store.reasoning.Reasoning; | 8 | import tools.refinery.store.reasoning.ReasoningAdapter; |
9 | import tools.refinery.store.reasoning.representation.PartialRelation; | 9 | import tools.refinery.store.reasoning.representation.PartialRelation; |
10 | import tools.refinery.store.model.Model; | 10 | import tools.refinery.store.model.Model; |
11 | import tools.refinery.store.query.term.Variable; | 11 | import tools.refinery.store.query.term.Variable; |
@@ -28,7 +28,7 @@ public record RelationRefinementAction(PartialRelation target, List<Variable> ar | |||
28 | 28 | ||
29 | @Override | 29 | @Override |
30 | public RuleActionExecutor createExecutor(int[] argumentIndices, Model model) { | 30 | public RuleActionExecutor createExecutor(int[] argumentIndices, Model model) { |
31 | var targetInterpretation = model.getAdapter(Reasoning.ADAPTER).getPartialInterpretation(target); | 31 | var targetInterpretation = model.getAdapter(ReasoningAdapter.class).getPartialInterpretation(target); |
32 | return activationTuple -> { | 32 | return activationTuple -> { |
33 | int arity = argumentIndices.length; | 33 | int arity = argumentIndices.length; |
34 | var arguments = new int[arity]; | 34 | var arguments = new int[arity]; |
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/TranslationUnit.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/TranslationUnit.java index 7f01122b..6e44a7d7 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/TranslationUnit.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/TranslationUnit.java | |||
@@ -6,7 +6,6 @@ | |||
6 | package tools.refinery.store.reasoning.translator; | 6 | package tools.refinery.store.reasoning.translator; |
7 | 7 | ||
8 | import tools.refinery.store.model.Model; | 8 | import tools.refinery.store.model.Model; |
9 | import tools.refinery.store.model.ModelStoreBuilder; | ||
10 | import tools.refinery.store.reasoning.ReasoningBuilder; | 9 | import tools.refinery.store.reasoning.ReasoningBuilder; |
11 | 10 | ||
12 | import java.util.Collection; | 11 | import java.util.Collection; |
@@ -23,10 +22,6 @@ public abstract class TranslationUnit { | |||
23 | configureReasoningBuilder(); | 22 | configureReasoningBuilder(); |
24 | } | 23 | } |
25 | 24 | ||
26 | protected ModelStoreBuilder getModelStoreBuilder() { | ||
27 | return reasoningBuilder.getStoreBuilder(); | ||
28 | } | ||
29 | |||
30 | protected void configureReasoningBuilder() { | 25 | protected void configureReasoningBuilder() { |
31 | // Nothing to configure by default. | 26 | // Nothing to configure by default. |
32 | } | 27 | } |
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/base/BaseDecisionTranslationUnit.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/base/BaseDecisionTranslationUnit.java index d41e11c6..405e58ac 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/base/BaseDecisionTranslationUnit.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/base/BaseDecisionTranslationUnit.java | |||
@@ -37,11 +37,6 @@ public class BaseDecisionTranslationUnit extends TranslationUnit { | |||
37 | } | 37 | } |
38 | 38 | ||
39 | @Override | 39 | @Override |
40 | protected void configureReasoningBuilder() { | ||
41 | getModelStoreBuilder().symbol(symbol); | ||
42 | } | ||
43 | |||
44 | @Override | ||
45 | public Collection<TranslatedRelation> getTranslatedRelations() { | 40 | public Collection<TranslatedRelation> getTranslatedRelations() { |
46 | return List.of(new TranslatedBaseDecision(getReasoningBuilder(), partialRelation, symbol)); | 41 | return List.of(new TranslatedBaseDecision(getReasoningBuilder(), partialRelation, symbol)); |
47 | } | 42 | } |