diff options
Diffstat (limited to 'subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/multiobject/MultiObjectTranslator.java')
-rw-r--r-- | subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/multiobject/MultiObjectTranslator.java | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/multiobject/MultiObjectTranslator.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/multiobject/MultiObjectTranslator.java index 0367214b..09993c80 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/multiobject/MultiObjectTranslator.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/translator/multiobject/MultiObjectTranslator.java | |||
@@ -8,11 +8,14 @@ package tools.refinery.store.reasoning.translator.multiobject; | |||
8 | import tools.refinery.store.model.ModelStoreBuilder; | 8 | import tools.refinery.store.model.ModelStoreBuilder; |
9 | import tools.refinery.store.model.ModelStoreConfiguration; | 9 | import tools.refinery.store.model.ModelStoreConfiguration; |
10 | import tools.refinery.store.query.dnf.Query; | 10 | import tools.refinery.store.query.dnf.Query; |
11 | import tools.refinery.store.query.view.AnySymbolView; | ||
11 | import tools.refinery.store.reasoning.ReasoningAdapter; | 12 | import tools.refinery.store.reasoning.ReasoningAdapter; |
12 | import tools.refinery.store.reasoning.ReasoningBuilder; | 13 | import tools.refinery.store.reasoning.ReasoningBuilder; |
14 | import tools.refinery.store.reasoning.representation.PartialFunction; | ||
13 | import tools.refinery.store.reasoning.translator.PartialRelationTranslator; | 15 | import tools.refinery.store.reasoning.translator.PartialRelationTranslator; |
14 | import tools.refinery.store.reasoning.translator.RoundingMode; | 16 | import tools.refinery.store.reasoning.translator.RoundingMode; |
15 | import tools.refinery.store.representation.Symbol; | 17 | import tools.refinery.store.representation.Symbol; |
18 | import tools.refinery.store.representation.cardinality.CardinalityDomain; | ||
16 | import tools.refinery.store.representation.cardinality.CardinalityInterval; | 19 | import tools.refinery.store.representation.cardinality.CardinalityInterval; |
17 | import tools.refinery.store.representation.cardinality.UpperCardinalities; | 20 | import tools.refinery.store.representation.cardinality.UpperCardinalities; |
18 | import tools.refinery.store.representation.cardinality.UpperCardinality; | 21 | import tools.refinery.store.representation.cardinality.UpperCardinality; |
@@ -26,35 +29,37 @@ import static tools.refinery.store.query.term.uppercardinality.UpperCardinalityT | |||
26 | import static tools.refinery.store.query.term.uppercardinality.UpperCardinalityTerms.greaterEq; | 29 | import static tools.refinery.store.query.term.uppercardinality.UpperCardinalityTerms.greaterEq; |
27 | 30 | ||
28 | public class MultiObjectTranslator implements ModelStoreConfiguration { | 31 | public class MultiObjectTranslator implements ModelStoreConfiguration { |
29 | private final Symbol<CardinalityInterval> countSymbol = Symbol.of("COUNT", 1, CardinalityInterval.class, | 32 | private static final Symbol<CardinalityInterval> COUNT_STORAGE = Symbol.of("COUNT", 1, CardinalityInterval.class, |
30 | null); | 33 | null); |
31 | private final LowerCardinalityView lowerCardinalityView = new LowerCardinalityView(countSymbol); | 34 | public static final AnySymbolView LOWER_CARDINALITY_VIEW = new LowerCardinalityView(COUNT_STORAGE); |
32 | private final UpperCardinalityView upperCardinalityView = new UpperCardinalityView(countSymbol); | 35 | public static final AnySymbolView UPPER_CARDINALITY_VIEW = new UpperCardinalityView(COUNT_STORAGE); |
36 | public static final PartialFunction<CardinalityInterval, Integer> COUNT_SYMBOL = new PartialFunction<>("COUNT", 1, | ||
37 | CardinalityDomain.INSTANCE); | ||
33 | 38 | ||
34 | @Override | 39 | @Override |
35 | public void apply(ModelStoreBuilder storeBuilder) { | 40 | public void apply(ModelStoreBuilder storeBuilder) { |
36 | storeBuilder.symbol(countSymbol); | 41 | storeBuilder.symbol(COUNT_STORAGE); |
37 | 42 | ||
38 | storeBuilder.with(PartialRelationTranslator.of(ReasoningAdapter.EXISTS_SYMBOL) | 43 | storeBuilder.with(PartialRelationTranslator.of(ReasoningAdapter.EXISTS_SYMBOL) |
39 | .may(Query.of("MAY_EXISTS", (builder, p1) -> builder | 44 | .may(Query.of("MAY_EXISTS", (builder, p1) -> builder |
40 | .clause(UpperCardinality.class, upper -> List.of( | 45 | .clause(UpperCardinality.class, upper -> List.of( |
41 | upperCardinalityView.call(p1, upper), | 46 | UPPER_CARDINALITY_VIEW.call(p1, upper), |
42 | check(greaterEq(upper, constant(UpperCardinalities.ONE))) | 47 | check(greaterEq(upper, constant(UpperCardinalities.ONE))) |
43 | )))) | 48 | )))) |
44 | .must(Query.of("MUST_EXISTS", (builder, p1) -> builder | 49 | .must(Query.of("MUST_EXISTS", (builder, p1) -> builder |
45 | .clause(Integer.class, lower -> List.of( | 50 | .clause(Integer.class, lower -> List.of( |
46 | lowerCardinalityView.call(p1, lower), | 51 | LOWER_CARDINALITY_VIEW.call(p1, lower), |
47 | check(greaterEq(lower, constant(1))) | 52 | check(greaterEq(lower, constant(1))) |
48 | )))) | 53 | )))) |
49 | .roundingMode(RoundingMode.PREFER_FALSE) | 54 | .roundingMode(RoundingMode.PREFER_FALSE) |
50 | .refiner(ExistsRefiner.of(countSymbol))); | 55 | .refiner(ExistsRefiner.of(COUNT_STORAGE))); |
51 | 56 | ||
52 | storeBuilder.with(PartialRelationTranslator.of(ReasoningAdapter.EQUALS_SYMBOL) | 57 | storeBuilder.with(PartialRelationTranslator.of(ReasoningAdapter.EQUALS_SYMBOL) |
53 | .rewriter(EqualsRelationRewriter.of(upperCardinalityView)) | 58 | .rewriter(EqualsRelationRewriter.of(UPPER_CARDINALITY_VIEW)) |
54 | .refiner(EqualsRefiner.of(countSymbol))); | 59 | .refiner(EqualsRefiner.of(COUNT_STORAGE))); |
55 | 60 | ||
56 | var reasoningBuilder = storeBuilder.getAdapter(ReasoningBuilder.class); | 61 | var reasoningBuilder = storeBuilder.getAdapter(ReasoningBuilder.class); |
57 | reasoningBuilder.initializer(new MultiObjectInitializer(countSymbol)); | 62 | reasoningBuilder.initializer(new MultiObjectInitializer(COUNT_STORAGE)); |
58 | reasoningBuilder.storageRefiner(countSymbol, MultiObjectStorageRefiner::new); | 63 | reasoningBuilder.storageRefiner(COUNT_STORAGE, MultiObjectStorageRefiner::new); |
59 | } | 64 | } |
60 | } | 65 | } |