diff options
Diffstat (limited to 'subprojects/store-reasoning/src')
9 files changed, 81 insertions, 18 deletions
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 f560c74c..3d4c672f 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 | |||
@@ -18,8 +18,17 @@ import tools.refinery.store.reasoning.refinement.StorageRefiner; | |||
18 | import tools.refinery.store.reasoning.translator.AnyPartialSymbolTranslator; | 18 | import tools.refinery.store.reasoning.translator.AnyPartialSymbolTranslator; |
19 | import tools.refinery.store.representation.Symbol; | 19 | import tools.refinery.store.representation.Symbol; |
20 | 20 | ||
21 | import java.util.Collection; | ||
22 | import java.util.List; | ||
23 | |||
21 | @SuppressWarnings("UnusedReturnValue") | 24 | @SuppressWarnings("UnusedReturnValue") |
22 | public interface ReasoningBuilder extends ModelAdapterBuilder { | 25 | public interface ReasoningBuilder extends ModelAdapterBuilder { |
26 | ReasoningBuilder requiredInterpretations(Collection<Concreteness> requiredInterpretations); | ||
27 | |||
28 | default ReasoningBuilder requiredInterpretations(Concreteness... requiredInterpretations) { | ||
29 | return requiredInterpretations(List.of(requiredInterpretations)); | ||
30 | } | ||
31 | |||
23 | ReasoningBuilder partialSymbol(AnyPartialSymbolTranslator translator); | 32 | ReasoningBuilder partialSymbol(AnyPartialSymbolTranslator translator); |
24 | 33 | ||
25 | <T> ReasoningBuilder storageRefiner(Symbol<T> symbol, StorageRefiner.Factory<T> refiner); | 34 | <T> ReasoningBuilder storageRefiner(Symbol<T> symbol, StorageRefiner.Factory<T> refiner); |
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/ReasoningStoreAdapter.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/ReasoningStoreAdapter.java index 6f9354eb..fe3cc3ea 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/ReasoningStoreAdapter.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/ReasoningStoreAdapter.java | |||
@@ -7,16 +7,20 @@ package tools.refinery.store.reasoning; | |||
7 | 7 | ||
8 | import tools.refinery.store.adapter.ModelStoreAdapter; | 8 | import tools.refinery.store.adapter.ModelStoreAdapter; |
9 | import tools.refinery.store.model.Model; | 9 | import tools.refinery.store.model.Model; |
10 | import tools.refinery.store.reasoning.literal.Concreteness; | ||
10 | import tools.refinery.store.reasoning.representation.AnyPartialSymbol; | 11 | import tools.refinery.store.reasoning.representation.AnyPartialSymbol; |
11 | import tools.refinery.store.reasoning.seed.ModelSeed; | 12 | import tools.refinery.store.reasoning.seed.ModelSeed; |
12 | 13 | ||
13 | import java.util.Collection; | 14 | import java.util.Collection; |
15 | import java.util.Set; | ||
14 | 16 | ||
15 | public interface ReasoningStoreAdapter extends ModelStoreAdapter { | 17 | public interface ReasoningStoreAdapter extends ModelStoreAdapter { |
16 | Collection<AnyPartialSymbol> getPartialSymbols(); | 18 | Collection<AnyPartialSymbol> getPartialSymbols(); |
17 | 19 | ||
18 | Collection<AnyPartialSymbol> getRefinablePartialSymbols(); | 20 | Collection<AnyPartialSymbol> getRefinablePartialSymbols(); |
19 | 21 | ||
22 | Set<Concreteness> getSupportedInterpretations(); | ||
23 | |||
20 | Model createInitialModel(ModelSeed modelSeed); | 24 | Model createInitialModel(ModelSeed modelSeed); |
21 | 25 | ||
22 | @Override | 26 | @Override |
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 579b08dd..2fa744de 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 | |||
@@ -48,16 +48,20 @@ class ReasoningAdapterImpl implements ReasoningAdapter { | |||
48 | refiners = new HashMap<>(refinerFactories.size()); | 48 | refiners = new HashMap<>(refinerFactories.size()); |
49 | createRefiners(); | 49 | createRefiners(); |
50 | 50 | ||
51 | storageRefiners = storeAdapter.createStprageRefiner(model); | 51 | storageRefiners = storeAdapter.createStorageRefiner(model); |
52 | 52 | ||
53 | nodeCountInterpretation = model.getInterpretation(NODE_COUNT_SYMBOL); | 53 | nodeCountInterpretation = model.getInterpretation(NODE_COUNT_SYMBOL); |
54 | } | 54 | } |
55 | 55 | ||
56 | private void createPartialInterpretations() { | 56 | private void createPartialInterpretations() { |
57 | var supportedInterpretations = storeAdapter.getSupportedInterpretations(); | ||
57 | int concretenessLength = Concreteness.values().length; | 58 | int concretenessLength = Concreteness.values().length; |
58 | var interpretationFactories = storeAdapter.getSymbolInterpreters(); | 59 | var interpretationFactories = storeAdapter.getSymbolInterpreters(); |
59 | for (int i = 0; i < concretenessLength; i++) { | 60 | for (int i = 0; i < concretenessLength; i++) { |
60 | partialInterpretations[i] = new HashMap<>(interpretationFactories.size()); | 61 | var concreteness = Concreteness.values()[i]; |
62 | if (supportedInterpretations.contains(concreteness)) { | ||
63 | partialInterpretations[i] = new HashMap<>(interpretationFactories.size()); | ||
64 | } | ||
61 | } | 65 | } |
62 | // Create the partial interpretations in order so that factories may refer to interpretations of symbols | 66 | // Create the partial interpretations in order so that factories may refer to interpretations of symbols |
63 | // preceding them in the ordered {@code interpretationFactories} map, e.g., for opposite interpretations. | 67 | // preceding them in the ordered {@code interpretationFactories} map, e.g., for opposite interpretations. |
@@ -65,9 +69,11 @@ class ReasoningAdapterImpl implements ReasoningAdapter { | |||
65 | var partialSymbol = entry.getKey(); | 69 | var partialSymbol = entry.getKey(); |
66 | var factory = entry.getValue(); | 70 | var factory = entry.getValue(); |
67 | for (int i = 0; i < concretenessLength; i++) { | 71 | for (int i = 0; i < concretenessLength; i++) { |
68 | var concreteness = Concreteness.values()[i]; | 72 | if (partialInterpretations[i] != null) { |
69 | var interpretation = createPartialInterpretation(concreteness, factory, partialSymbol); | 73 | var concreteness = Concreteness.values()[i]; |
70 | partialInterpretations[i].put(partialSymbol, interpretation); | 74 | var interpretation = createPartialInterpretation(concreteness, factory, partialSymbol); |
75 | partialInterpretations[i].put(partialSymbol, interpretation); | ||
76 | } | ||
71 | } | 77 | } |
72 | } | 78 | } |
73 | } | 79 | } |
@@ -114,6 +120,9 @@ class ReasoningAdapterImpl implements ReasoningAdapter { | |||
114 | public <A, C> PartialInterpretation<A, C> getPartialInterpretation(Concreteness concreteness, | 120 | public <A, C> PartialInterpretation<A, C> getPartialInterpretation(Concreteness concreteness, |
115 | PartialSymbol<A, C> partialSymbol) { | 121 | PartialSymbol<A, C> partialSymbol) { |
116 | var map = partialInterpretations[concreteness.ordinal()]; | 122 | var map = partialInterpretations[concreteness.ordinal()]; |
123 | if (map == null) { | ||
124 | throw new IllegalArgumentException("No interpretation for concreteness: " + concreteness); | ||
125 | } | ||
117 | var interpretation = map.get(partialSymbol); | 126 | var interpretation = map.get(partialSymbol); |
118 | if (interpretation == null) { | 127 | if (interpretation == null) { |
119 | throw new IllegalArgumentException("No interpretation for partial symbol: " + partialSymbol); | 128 | throw new IllegalArgumentException("No interpretation for partial symbol: " + partialSymbol); |
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 2af84e2d..b4971d2c 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 | |||
@@ -34,6 +34,7 @@ public class ReasoningBuilderImpl extends AbstractModelAdapterBuilder<ReasoningS | |||
34 | implements ReasoningBuilder { | 34 | implements ReasoningBuilder { |
35 | private final DnfLifter lifter = new DnfLifter(); | 35 | private final DnfLifter lifter = new DnfLifter(); |
36 | private final PartialQueryRewriter queryRewriter = new PartialQueryRewriter(lifter); | 36 | private final PartialQueryRewriter queryRewriter = new PartialQueryRewriter(lifter); |
37 | private Set<Concreteness> requiredInterpretations = Set.of(Concreteness.values()); | ||
37 | private final Map<AnyPartialSymbol, AnyPartialSymbolTranslator> translators = new LinkedHashMap<>(); | 38 | private final Map<AnyPartialSymbol, AnyPartialSymbolTranslator> translators = new LinkedHashMap<>(); |
38 | private final Map<AnyPartialSymbol, PartialInterpretation.Factory<?, ?>> symbolInterpreters = new LinkedHashMap<>(); | 39 | private final Map<AnyPartialSymbol, PartialInterpretation.Factory<?, ?>> symbolInterpreters = new LinkedHashMap<>(); |
39 | private final Map<AnyPartialSymbol, PartialInterpretationRefiner.Factory<?, ?>> symbolRefiners = | 40 | private final Map<AnyPartialSymbol, PartialInterpretationRefiner.Factory<?, ?>> symbolRefiners = |
@@ -42,6 +43,12 @@ public class ReasoningBuilderImpl extends AbstractModelAdapterBuilder<ReasoningS | |||
42 | private final List<PartialModelInitializer> initializers = new ArrayList<>(); | 43 | private final List<PartialModelInitializer> initializers = new ArrayList<>(); |
43 | 44 | ||
44 | @Override | 45 | @Override |
46 | public ReasoningBuilder requiredInterpretations(Collection<Concreteness> requiredInterpretations) { | ||
47 | this.requiredInterpretations = Set.copyOf(requiredInterpretations); | ||
48 | return this; | ||
49 | } | ||
50 | |||
51 | @Override | ||
45 | public ReasoningBuilder partialSymbol(AnyPartialSymbolTranslator translator) { | 52 | public ReasoningBuilder partialSymbol(AnyPartialSymbolTranslator translator) { |
46 | var partialSymbol = translator.getPartialSymbol(); | 53 | var partialSymbol = translator.getPartialSymbol(); |
47 | var oldConfiguration = translators.put(partialSymbol, translator); | 54 | var oldConfiguration = translators.put(partialSymbol, translator); |
@@ -93,7 +100,7 @@ public class ReasoningBuilderImpl extends AbstractModelAdapterBuilder<ReasoningS | |||
93 | for (var translator : translators.values()) { | 100 | for (var translator : translators.values()) { |
94 | translator.configure(storeBuilder); | 101 | translator.configure(storeBuilder); |
95 | if (translator instanceof PartialRelationTranslator relationConfiguration) { | 102 | if (translator instanceof PartialRelationTranslator relationConfiguration) { |
96 | doConfigure(relationConfiguration); | 103 | doConfigure(storeBuilder, relationConfiguration); |
97 | } else { | 104 | } else { |
98 | throw new IllegalArgumentException("Unknown partial symbol translator %s for partial symbol %s" | 105 | throw new IllegalArgumentException("Unknown partial symbol translator %s for partial symbol %s" |
99 | .formatted(translator, translator.getPartialSymbol())); | 106 | .formatted(translator, translator.getPartialSymbol())); |
@@ -104,10 +111,12 @@ public class ReasoningBuilderImpl extends AbstractModelAdapterBuilder<ReasoningS | |||
104 | queryBuilder.rewriter(queryRewriter); | 111 | queryBuilder.rewriter(queryRewriter); |
105 | } | 112 | } |
106 | 113 | ||
107 | private void doConfigure(PartialRelationTranslator relationConfiguration) { | 114 | private void doConfigure(ModelStoreBuilder storeBuilder, PartialRelationTranslator relationConfiguration) { |
108 | var partialRelation = relationConfiguration.getPartialRelation(); | 115 | var partialRelation = relationConfiguration.getPartialRelation(); |
109 | queryRewriter.addRelationRewriter(partialRelation, relationConfiguration.getRewriter()); | 116 | queryRewriter.addRelationRewriter(partialRelation, relationConfiguration.getRewriter()); |
110 | symbolInterpreters.put(partialRelation, relationConfiguration.getInterpretationFactory()); | 117 | var interpretationFactory = relationConfiguration.getInterpretationFactory(); |
118 | interpretationFactory.configure(storeBuilder, requiredInterpretations); | ||
119 | symbolInterpreters.put(partialRelation, interpretationFactory); | ||
111 | var refiner = relationConfiguration.getInterpretationRefiner(); | 120 | var refiner = relationConfiguration.getInterpretationRefiner(); |
112 | if (refiner != null) { | 121 | if (refiner != null) { |
113 | symbolRefiners.put(partialRelation, refiner); | 122 | symbolRefiners.put(partialRelation, refiner); |
@@ -116,9 +125,9 @@ public class ReasoningBuilderImpl extends AbstractModelAdapterBuilder<ReasoningS | |||
116 | 125 | ||
117 | @Override | 126 | @Override |
118 | public ReasoningStoreAdapterImpl doBuild(ModelStore store) { | 127 | public ReasoningStoreAdapterImpl doBuild(ModelStore store) { |
119 | return new ReasoningStoreAdapterImpl(store, Collections.unmodifiableMap(symbolInterpreters), | 128 | return new ReasoningStoreAdapterImpl(store, requiredInterpretations, |
120 | Collections.unmodifiableMap(symbolRefiners), getStorageRefiners(store), | 129 | Collections.unmodifiableMap(symbolInterpreters), Collections.unmodifiableMap(symbolRefiners), |
121 | Collections.unmodifiableList(initializers)); | 130 | getStorageRefiners(store), Collections.unmodifiableList(initializers)); |
122 | } | 131 | } |
123 | 132 | ||
124 | private Map<AnySymbol, StorageRefiner.Factory<?>> getStorageRefiners(ModelStore store) { | 133 | private Map<AnySymbol, StorageRefiner.Factory<?>> getStorageRefiners(ModelStore store) { |
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/internal/ReasoningStoreAdapterImpl.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/internal/ReasoningStoreAdapterImpl.java index 3dac53ef..8eb5a034 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/internal/ReasoningStoreAdapterImpl.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/internal/ReasoningStoreAdapterImpl.java | |||
@@ -10,6 +10,7 @@ import tools.refinery.store.model.ModelStore; | |||
10 | import tools.refinery.store.query.ModelQueryAdapter; | 10 | import tools.refinery.store.query.ModelQueryAdapter; |
11 | import tools.refinery.store.reasoning.ReasoningStoreAdapter; | 11 | import tools.refinery.store.reasoning.ReasoningStoreAdapter; |
12 | import tools.refinery.store.reasoning.interpretation.PartialInterpretation; | 12 | import tools.refinery.store.reasoning.interpretation.PartialInterpretation; |
13 | import tools.refinery.store.reasoning.literal.Concreteness; | ||
13 | import tools.refinery.store.reasoning.refinement.PartialInterpretationRefiner; | 14 | import tools.refinery.store.reasoning.refinement.PartialInterpretationRefiner; |
14 | import tools.refinery.store.reasoning.refinement.PartialModelInitializer; | 15 | import tools.refinery.store.reasoning.refinement.PartialModelInitializer; |
15 | import tools.refinery.store.reasoning.refinement.StorageRefiner; | 16 | import tools.refinery.store.reasoning.refinement.StorageRefiner; |
@@ -22,20 +23,23 @@ import tools.refinery.store.tuple.Tuple; | |||
22 | import java.util.Collection; | 23 | import java.util.Collection; |
23 | import java.util.List; | 24 | import java.util.List; |
24 | import java.util.Map; | 25 | import java.util.Map; |
26 | import java.util.Set; | ||
25 | 27 | ||
26 | class ReasoningStoreAdapterImpl implements ReasoningStoreAdapter { | 28 | class ReasoningStoreAdapterImpl implements ReasoningStoreAdapter { |
27 | private final ModelStore store; | 29 | private final ModelStore store; |
30 | private final Set<Concreteness> supportedInterpretations; | ||
28 | private final Map<AnyPartialSymbol, PartialInterpretation.Factory<?, ?>> symbolInterpreters; | 31 | private final Map<AnyPartialSymbol, PartialInterpretation.Factory<?, ?>> symbolInterpreters; |
29 | private final Map<AnyPartialSymbol, PartialInterpretationRefiner.Factory<?, ?>> symbolRefiners; | 32 | private final Map<AnyPartialSymbol, PartialInterpretationRefiner.Factory<?, ?>> symbolRefiners; |
30 | private final Map<AnySymbol, StorageRefiner.Factory<?>> storageRefiners; | 33 | private final Map<AnySymbol, StorageRefiner.Factory<?>> storageRefiners; |
31 | private final List<PartialModelInitializer> initializers; | 34 | private final List<PartialModelInitializer> initializers; |
32 | 35 | ||
33 | ReasoningStoreAdapterImpl(ModelStore store, | 36 | ReasoningStoreAdapterImpl(ModelStore store, Set<Concreteness> supportedInterpretations, |
34 | Map<AnyPartialSymbol, PartialInterpretation.Factory<?, ?>> symbolInterpreters, | 37 | Map<AnyPartialSymbol, PartialInterpretation.Factory<?, ?>> symbolInterpreters, |
35 | Map<AnyPartialSymbol, PartialInterpretationRefiner.Factory<?, ?>> symbolRefiners, | 38 | Map<AnyPartialSymbol, PartialInterpretationRefiner.Factory<?, ?>> symbolRefiners, |
36 | Map<AnySymbol, StorageRefiner.Factory<?>> storageRefiners, | 39 | Map<AnySymbol, StorageRefiner.Factory<?>> storageRefiners, |
37 | List<PartialModelInitializer> initializers) { | 40 | List<PartialModelInitializer> initializers) { |
38 | this.store = store; | 41 | this.store = store; |
42 | this.supportedInterpretations = supportedInterpretations; | ||
39 | this.symbolInterpreters = symbolInterpreters; | 43 | this.symbolInterpreters = symbolInterpreters; |
40 | this.symbolRefiners = symbolRefiners; | 44 | this.symbolRefiners = symbolRefiners; |
41 | this.storageRefiners = storageRefiners; | 45 | this.storageRefiners = storageRefiners; |
@@ -48,6 +52,11 @@ class ReasoningStoreAdapterImpl implements ReasoningStoreAdapter { | |||
48 | } | 52 | } |
49 | 53 | ||
50 | @Override | 54 | @Override |
55 | public Set<Concreteness> getSupportedInterpretations() { | ||
56 | return supportedInterpretations; | ||
57 | } | ||
58 | |||
59 | @Override | ||
51 | public Collection<AnyPartialSymbol> getPartialSymbols() { | 60 | public Collection<AnyPartialSymbol> getPartialSymbols() { |
52 | return symbolInterpreters.keySet(); | 61 | return symbolInterpreters.keySet(); |
53 | } | 62 | } |
@@ -69,7 +78,7 @@ class ReasoningStoreAdapterImpl implements ReasoningStoreAdapter { | |||
69 | return symbolRefiners; | 78 | return symbolRefiners; |
70 | } | 79 | } |
71 | 80 | ||
72 | StorageRefiner[] createStprageRefiner(Model model) { | 81 | StorageRefiner[] createStorageRefiner(Model model) { |
73 | var refiners = new StorageRefiner[storageRefiners.size()]; | 82 | var refiners = new StorageRefiner[storageRefiners.size()]; |
74 | int i = 0; | 83 | int i = 0; |
75 | for (var entry : storageRefiners.entrySet()) { | 84 | for (var entry : storageRefiners.entrySet()) { |
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialInterpretation.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialInterpretation.java index 3d3d6056..86ffe751 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialInterpretation.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialInterpretation.java | |||
@@ -6,11 +6,14 @@ | |||
6 | package tools.refinery.store.reasoning.interpretation; | 6 | package tools.refinery.store.reasoning.interpretation; |
7 | 7 | ||
8 | import tools.refinery.store.map.Cursor; | 8 | import tools.refinery.store.map.Cursor; |
9 | import tools.refinery.store.model.ModelStoreBuilder; | ||
9 | import tools.refinery.store.reasoning.ReasoningAdapter; | 10 | import tools.refinery.store.reasoning.ReasoningAdapter; |
10 | import tools.refinery.store.reasoning.literal.Concreteness; | 11 | import tools.refinery.store.reasoning.literal.Concreteness; |
11 | import tools.refinery.store.reasoning.representation.PartialSymbol; | 12 | import tools.refinery.store.reasoning.representation.PartialSymbol; |
12 | import tools.refinery.store.tuple.Tuple; | 13 | import tools.refinery.store.tuple.Tuple; |
13 | 14 | ||
15 | import java.util.Set; | ||
16 | |||
14 | public non-sealed interface PartialInterpretation<A, C> extends AnyPartialInterpretation { | 17 | public non-sealed interface PartialInterpretation<A, C> extends AnyPartialInterpretation { |
15 | @Override | 18 | @Override |
16 | PartialSymbol<A, C> getPartialSymbol(); | 19 | PartialSymbol<A, C> getPartialSymbol(); |
@@ -19,8 +22,13 @@ public non-sealed interface PartialInterpretation<A, C> extends AnyPartialInterp | |||
19 | 22 | ||
20 | Cursor<Tuple, A> getAll(); | 23 | Cursor<Tuple, A> getAll(); |
21 | 24 | ||
25 | @FunctionalInterface | ||
22 | interface Factory<A, C> { | 26 | interface Factory<A, C> { |
23 | PartialInterpretation<A, C> create(ReasoningAdapter adapter, Concreteness concreteness, | 27 | PartialInterpretation<A, C> create(ReasoningAdapter adapter, Concreteness concreteness, |
24 | PartialSymbol<A, C> partialSymbol); | 28 | PartialSymbol<A, C> partialSymbol); |
29 | |||
30 | default void configure(ModelStoreBuilder storeBuilder, Set<Concreteness> requiredInterpretations) { | ||
31 | // Nothing to configure by default. | ||
32 | } | ||
25 | } | 33 | } |
26 | } | 34 | } |
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/QueryBasedRelationInterpretationFactory.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/QueryBasedRelationInterpretationFactory.java index 2535714a..5cdaa185 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/QueryBasedRelationInterpretationFactory.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/QueryBasedRelationInterpretationFactory.java | |||
@@ -6,7 +6,9 @@ | |||
6 | package tools.refinery.store.reasoning.interpretation; | 6 | package tools.refinery.store.reasoning.interpretation; |
7 | 7 | ||
8 | import tools.refinery.store.map.Cursor; | 8 | import tools.refinery.store.map.Cursor; |
9 | import tools.refinery.store.model.ModelStoreBuilder; | ||
9 | import tools.refinery.store.query.ModelQueryAdapter; | 10 | import tools.refinery.store.query.ModelQueryAdapter; |
11 | import tools.refinery.store.query.ModelQueryBuilder; | ||
10 | import tools.refinery.store.query.dnf.Query; | 12 | import tools.refinery.store.query.dnf.Query; |
11 | import tools.refinery.store.query.resultset.ResultSet; | 13 | import tools.refinery.store.query.resultset.ResultSet; |
12 | import tools.refinery.store.reasoning.ReasoningAdapter; | 14 | import tools.refinery.store.reasoning.ReasoningAdapter; |
@@ -15,6 +17,8 @@ import tools.refinery.store.reasoning.representation.PartialSymbol; | |||
15 | import tools.refinery.store.representation.TruthValue; | 17 | import tools.refinery.store.representation.TruthValue; |
16 | import tools.refinery.store.tuple.Tuple; | 18 | import tools.refinery.store.tuple.Tuple; |
17 | 19 | ||
20 | import java.util.Set; | ||
21 | |||
18 | public class QueryBasedRelationInterpretationFactory implements PartialInterpretation.Factory<TruthValue, Boolean> { | 22 | public class QueryBasedRelationInterpretationFactory implements PartialInterpretation.Factory<TruthValue, Boolean> { |
19 | private final Query<Boolean> may; | 23 | private final Query<Boolean> may; |
20 | private final Query<Boolean> must; | 24 | private final Query<Boolean> must; |
@@ -54,6 +58,17 @@ public class QueryBasedRelationInterpretationFactory implements PartialInterpret | |||
54 | } | 58 | } |
55 | } | 59 | } |
56 | 60 | ||
61 | @Override | ||
62 | public void configure(ModelStoreBuilder storeBuilder, Set<Concreteness> requiredInterpretations) { | ||
63 | var queryBuilder = storeBuilder.getAdapter(ModelQueryBuilder.class); | ||
64 | if (requiredInterpretations.contains(Concreteness.PARTIAL)) { | ||
65 | queryBuilder.queries(may, must); | ||
66 | } | ||
67 | if (requiredInterpretations.contains(Concreteness.CANDIDATE)) { | ||
68 | queryBuilder.queries(candidateMay, candidateMust); | ||
69 | } | ||
70 | } | ||
71 | |||
57 | private static class TwoValuedInterpretation extends AbstractPartialInterpretation<TruthValue, Boolean> { | 72 | private static class TwoValuedInterpretation extends AbstractPartialInterpretation<TruthValue, Boolean> { |
58 | private final ResultSet<Boolean> resultSet; | 73 | private final ResultSet<Boolean> resultSet; |
59 | 74 | ||
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 6f9492a3..4600d5a4 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 | |||
@@ -7,7 +7,6 @@ package tools.refinery.store.reasoning.translator; | |||
7 | 7 | ||
8 | import tools.refinery.store.model.ModelStoreBuilder; | 8 | import tools.refinery.store.model.ModelStoreBuilder; |
9 | import tools.refinery.store.query.Constraint; | 9 | import tools.refinery.store.query.Constraint; |
10 | import tools.refinery.store.query.ModelQueryBuilder; | ||
11 | import tools.refinery.store.query.dnf.Query; | 10 | import tools.refinery.store.query.dnf.Query; |
12 | import tools.refinery.store.query.dnf.QueryBuilder; | 11 | import tools.refinery.store.query.dnf.QueryBuilder; |
13 | import tools.refinery.store.query.dnf.RelationalQuery; | 12 | import tools.refinery.store.query.dnf.RelationalQuery; |
@@ -169,7 +168,7 @@ public final class PartialRelationTranslator extends PartialSymbolTranslator<Tru | |||
169 | createFallbackQueriesFromSymbol(); | 168 | createFallbackQueriesFromSymbol(); |
170 | setFallbackCandidateQueries(); | 169 | setFallbackCandidateQueries(); |
171 | createFallbackRewriter(); | 170 | createFallbackRewriter(); |
172 | createFallbackInterpretation(storeBuilder); | 171 | createFallbackInterpretation(); |
173 | createFallbackRefiner(); | 172 | createFallbackRefiner(); |
174 | super.doConfigure(storeBuilder); | 173 | super.doConfigure(storeBuilder); |
175 | } | 174 | } |
@@ -279,11 +278,9 @@ public final class PartialRelationTranslator extends PartialSymbolTranslator<Tru | |||
279 | } | 278 | } |
280 | } | 279 | } |
281 | 280 | ||
282 | private void createFallbackInterpretation(ModelStoreBuilder storeBuilder) { | 281 | private void createFallbackInterpretation() { |
283 | if (interpretationFactory == null) { | 282 | if (interpretationFactory == null) { |
284 | var queryBuilder = storeBuilder.getAdapter(ModelQueryBuilder.class); | ||
285 | interpretationFactory = new QueryBasedRelationInterpretationFactory(may, must, candidateMay, candidateMust); | 283 | interpretationFactory = new QueryBasedRelationInterpretationFactory(may, must, candidateMay, candidateMust); |
286 | queryBuilder.queries(may, must, candidateMay, candidateMust); | ||
287 | } | 284 | } |
288 | } | 285 | } |
289 | 286 | ||
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/PartialSymbolTranslator.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/PartialSymbolTranslator.java index 542acdb3..e7e26cb2 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/PartialSymbolTranslator.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/PartialSymbolTranslator.java | |||
@@ -8,6 +8,7 @@ package tools.refinery.store.reasoning.translator; | |||
8 | import tools.refinery.store.model.ModelStoreBuilder; | 8 | import tools.refinery.store.model.ModelStoreBuilder; |
9 | import tools.refinery.store.reasoning.ReasoningBuilder; | 9 | import tools.refinery.store.reasoning.ReasoningBuilder; |
10 | import tools.refinery.store.reasoning.interpretation.PartialInterpretation; | 10 | import tools.refinery.store.reasoning.interpretation.PartialInterpretation; |
11 | import tools.refinery.store.reasoning.literal.Concreteness; | ||
11 | import tools.refinery.store.reasoning.refinement.PartialInterpretationRefiner; | 12 | import tools.refinery.store.reasoning.refinement.PartialInterpretationRefiner; |
12 | import tools.refinery.store.reasoning.refinement.PartialModelInitializer; | 13 | import tools.refinery.store.reasoning.refinement.PartialModelInitializer; |
13 | import tools.refinery.store.reasoning.refinement.StorageRefiner; | 14 | import tools.refinery.store.reasoning.refinement.StorageRefiner; |
@@ -16,6 +17,8 @@ import tools.refinery.store.reasoning.seed.SeedInitializer; | |||
16 | import tools.refinery.store.representation.AnySymbol; | 17 | import tools.refinery.store.representation.AnySymbol; |
17 | import tools.refinery.store.representation.Symbol; | 18 | import tools.refinery.store.representation.Symbol; |
18 | 19 | ||
20 | import java.util.Set; | ||
21 | |||
19 | @SuppressWarnings("UnusedReturnValue") | 22 | @SuppressWarnings("UnusedReturnValue") |
20 | public abstract sealed class PartialSymbolTranslator<A, C> implements AnyPartialSymbolTranslator | 23 | public abstract sealed class PartialSymbolTranslator<A, C> implements AnyPartialSymbolTranslator |
21 | permits PartialRelationTranslator { | 24 | permits PartialRelationTranslator { |