aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/UpperTypeScopePropagator.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/UpperTypeScopePropagator.java')
-rw-r--r--subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/UpperTypeScopePropagator.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/UpperTypeScopePropagator.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/UpperTypeScopePropagator.java
new file mode 100644
index 00000000..4aba5aac
--- /dev/null
+++ b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/UpperTypeScopePropagator.java
@@ -0,0 +1,59 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.reasoning.scope;
7
8import tools.refinery.store.query.dnf.AnyQuery;
9import tools.refinery.store.query.dnf.Query;
10import tools.refinery.store.query.dnf.RelationalQuery;
11import tools.refinery.store.reasoning.representation.PartialRelation;
12
13import java.util.Collection;
14import java.util.List;
15
16import static tools.refinery.store.reasoning.literal.PartialLiterals.must;
17import static tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator.MULTI_VIEW;
18
19class UpperTypeScopePropagator extends TypeScopePropagator {
20 private final int upperBound;
21
22 private UpperTypeScopePropagator(BoundScopePropagator adapter, int upperBound, RelationalQuery allQuery,
23 RelationalQuery multiQuery) {
24 super(adapter, allQuery, multiQuery);
25 this.upperBound = upperBound;
26 }
27
28 @Override
29 protected void doUpdateBounds() {
30 constraint.setUb((upperBound - getSingleCount()));
31 }
32
33 public static class Factory extends TypeScopePropagator.Factory {
34 private final int upperBound;
35 private final RelationalQuery allMust;
36 private final RelationalQuery multiMust;
37
38 public Factory(PartialRelation type, int upperBound) {
39 this.upperBound = upperBound;
40 allMust = Query.of(type.name() + "#must", (builder, instance) -> builder.clause(
41 must(type.call(instance))
42 ));
43 multiMust = Query.of(type.name() + "#multiMust", (builder, instance) -> builder.clause(
44 must(type.call(instance)),
45 MULTI_VIEW.call(instance)
46 ));
47 }
48
49 @Override
50 public TypeScopePropagator createPropagator(BoundScopePropagator adapter) {
51 return new UpperTypeScopePropagator(adapter, upperBound, allMust, multiMust);
52 }
53
54 @Override
55 protected Collection<AnyQuery> getQueries() {
56 return List.of(allMust, multiMust);
57 }
58 }
59}