diff options
Diffstat (limited to 'subprojects')
8 files changed, 38 insertions, 38 deletions
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/CountExpressionEvaluator.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/CountExpressionEvaluator.java index 6fc96c05..e583e187 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/CountExpressionEvaluator.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/CountExpressionEvaluator.java | |||
@@ -3,14 +3,14 @@ package tools.refinery.store.query.viatra.internal.pquery; | |||
3 | import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; | 3 | import org.eclipse.viatra.query.runtime.matchers.psystem.IExpressionEvaluator; |
4 | import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; | 4 | import org.eclipse.viatra.query.runtime.matchers.psystem.IValueProvider; |
5 | import tools.refinery.store.query.atom.ComparisonOperator; | 5 | import tools.refinery.store.query.atom.ComparisonOperator; |
6 | import tools.refinery.store.query.atom.CountCallKind; | 6 | import tools.refinery.store.query.atom.CountingPolarity; |
7 | 7 | ||
8 | import java.util.List; | 8 | import java.util.List; |
9 | 9 | ||
10 | public record CountExpressionEvaluator(String variableName, ComparisonOperator operator, | 10 | public record CountExpressionEvaluator(String variableName, ComparisonOperator operator, |
11 | int threshold) implements IExpressionEvaluator { | 11 | int threshold) implements IExpressionEvaluator { |
12 | public CountExpressionEvaluator(String variableName, CountCallKind callKind) { | 12 | public CountExpressionEvaluator(String variableName, CountingPolarity polarity) { |
13 | this(variableName, callKind.operator(), callKind.threshold()); | 13 | this(variableName, polarity.operator(), polarity.threshold()); |
14 | } | 14 | } |
15 | 15 | ||
16 | @Override | 16 | @Override |
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/DNF2PQuery.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/DNF2PQuery.java index 61b984ae..ae99365d 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/DNF2PQuery.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/DNF2PQuery.java | |||
@@ -127,21 +127,21 @@ public class DNF2PQuery { | |||
127 | } | 127 | } |
128 | var variablesTuple = translateSubstitution(callAtom.getSubstitution(), body); | 128 | var variablesTuple = translateSubstitution(callAtom.getSubstitution(), body); |
129 | var translatedReferred = translate(target); | 129 | var translatedReferred = translate(target); |
130 | var callKind = callAtom.getKind(); | 130 | var polarity = callAtom.getPolarity(); |
131 | if (callKind instanceof BasicCallKind basicCallKind) { | 131 | if (polarity instanceof SimplePolarity simplePolarity) { |
132 | switch (basicCallKind) { | 132 | switch (simplePolarity) { |
133 | case POSITIVE -> new PositivePatternCall(body, variablesTuple, translatedReferred); | 133 | case POSITIVE -> new PositivePatternCall(body, variablesTuple, translatedReferred); |
134 | case TRANSITIVE -> new BinaryTransitiveClosure(body, variablesTuple, translatedReferred); | 134 | case TRANSITIVE -> new BinaryTransitiveClosure(body, variablesTuple, translatedReferred); |
135 | case NEGATIVE -> new NegativePatternCall(body, variablesTuple, translatedReferred); | 135 | case NEGATIVE -> new NegativePatternCall(body, variablesTuple, translatedReferred); |
136 | default -> throw new IllegalArgumentException("Unknown BasicCallKind: " + basicCallKind); | 136 | default -> throw new IllegalArgumentException("Unknown BasicCallKind: " + simplePolarity); |
137 | } | 137 | } |
138 | } else if (callKind instanceof CountCallKind countCallKind) { | 138 | } else if (polarity instanceof CountingPolarity countingPolarity) { |
139 | var countVariableName = DNFUtils.generateUniqueName("count"); | 139 | var countVariableName = DNFUtils.generateUniqueName("count"); |
140 | var countPVariable = body.getOrCreateVariableByName(countVariableName); | 140 | var countPVariable = body.getOrCreateVariableByName(countVariableName); |
141 | new PatternMatchCounter(body, variablesTuple, translatedReferred, countPVariable); | 141 | new PatternMatchCounter(body, variablesTuple, translatedReferred, countPVariable); |
142 | new ExpressionEvaluation(body, new CountExpressionEvaluator(countVariableName, countCallKind), null); | 142 | new ExpressionEvaluation(body, new CountExpressionEvaluator(countVariableName, countingPolarity), null); |
143 | } else { | 143 | } else { |
144 | throw new IllegalArgumentException("Unknown CallKind: " + callKind); | 144 | throw new IllegalArgumentException("Unknown CallKind: " + polarity); |
145 | } | 145 | } |
146 | } | 146 | } |
147 | 147 | ||
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java index 224df362..ea92b223 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java | |||
@@ -438,7 +438,7 @@ class QueryTest { | |||
438 | .clause( | 438 | .clause( |
439 | new RelationViewAtom(personView, p3), | 439 | new RelationViewAtom(personView, p3), |
440 | new RelationViewAtom(personView, p4), | 440 | new RelationViewAtom(personView, p4), |
441 | new CallAtom<>(BasicCallKind.TRANSITIVE, friendPredicate, p3, p4) | 441 | new CallAtom<>(SimplePolarity.TRANSITIVE, friendPredicate, p3, p4) |
442 | ) | 442 | ) |
443 | .build(); | 443 | .build(); |
444 | 444 | ||
@@ -480,7 +480,7 @@ class QueryTest { | |||
480 | .parameters(p1) | 480 | .parameters(p1) |
481 | .clause( | 481 | .clause( |
482 | new RelationViewAtom(personView, p1), | 482 | new RelationViewAtom(personView, p1), |
483 | new CallAtom<>(new CountCallKind(ComparisonOperator.EQUALS, 2), called, p1, p2) | 483 | new CallAtom<>(new CountingPolarity(ComparisonOperator.EQUALS, 2), called, p1, p2) |
484 | ) | 484 | ) |
485 | .build(); | 485 | .build(); |
486 | 486 | ||
diff --git a/subprojects/store/src/main/java/tools/refinery/store/query/atom/CallAtom.java b/subprojects/store/src/main/java/tools/refinery/store/query/atom/CallAtom.java index e52e33ac..9e289a8a 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/query/atom/CallAtom.java +++ b/subprojects/store/src/main/java/tools/refinery/store/query/atom/CallAtom.java | |||
@@ -8,22 +8,22 @@ import java.util.Objects; | |||
8 | import java.util.Set; | 8 | import java.util.Set; |
9 | 9 | ||
10 | public final class CallAtom<T extends RelationLike> extends AbstractSubstitutionAtom<T> { | 10 | public final class CallAtom<T extends RelationLike> extends AbstractSubstitutionAtom<T> { |
11 | private final CallKind kind; | 11 | private final CallPolarity polarity; |
12 | 12 | ||
13 | public CallAtom(CallKind kind, T target, List<Variable> substitution) { | 13 | public CallAtom(CallPolarity polarity, T target, List<Variable> substitution) { |
14 | super(target, substitution); | 14 | super(target, substitution); |
15 | if (kind.isTransitive() && target.getArity() != 2) { | 15 | if (polarity.isTransitive() && target.getArity() != 2) { |
16 | throw new IllegalArgumentException("Transitive closures can only take binary relations"); | 16 | throw new IllegalArgumentException("Transitive closures can only take binary relations"); |
17 | } | 17 | } |
18 | this.kind = kind; | 18 | this.polarity = polarity; |
19 | } | 19 | } |
20 | 20 | ||
21 | public CallAtom(CallKind kind, T target, Variable... substitution) { | 21 | public CallAtom(CallPolarity polarity, T target, Variable... substitution) { |
22 | this(kind, target, List.of(substitution)); | 22 | this(polarity, target, List.of(substitution)); |
23 | } | 23 | } |
24 | 24 | ||
25 | public CallAtom(boolean positive, T target, List<Variable> substitution) { | 25 | public CallAtom(boolean positive, T target, List<Variable> substitution) { |
26 | this(CallKind.fromBoolean(positive), target, substitution); | 26 | this(CallPolarity.fromBoolean(positive), target, substitution); |
27 | } | 27 | } |
28 | 28 | ||
29 | public CallAtom(boolean positive, T target, Variable... substitution) { | 29 | public CallAtom(boolean positive, T target, Variable... substitution) { |
@@ -38,13 +38,13 @@ public final class CallAtom<T extends RelationLike> extends AbstractSubstitution | |||
38 | this(target, List.of(substitution)); | 38 | this(target, List.of(substitution)); |
39 | } | 39 | } |
40 | 40 | ||
41 | public CallKind getKind() { | 41 | public CallPolarity getPolarity() { |
42 | return kind; | 42 | return polarity; |
43 | } | 43 | } |
44 | 44 | ||
45 | @Override | 45 | @Override |
46 | public void collectAllVariables(Set<Variable> variables) { | 46 | public void collectAllVariables(Set<Variable> variables) { |
47 | if (kind.isPositive()) { | 47 | if (polarity.isPositive()) { |
48 | super.collectAllVariables(variables); | 48 | super.collectAllVariables(variables); |
49 | } | 49 | } |
50 | } | 50 | } |
@@ -54,13 +54,13 @@ public final class CallAtom<T extends RelationLike> extends AbstractSubstitution | |||
54 | if (this == o) return true; | 54 | if (this == o) return true; |
55 | if (o == null || getClass() != o.getClass()) return false; | 55 | if (o == null || getClass() != o.getClass()) return false; |
56 | CallAtom<?> that = (CallAtom<?>) o; | 56 | CallAtom<?> that = (CallAtom<?>) o; |
57 | return Objects.equals(kind, that.kind) | 57 | return Objects.equals(polarity, that.polarity) |
58 | && Objects.equals(getTarget(), that.getTarget()) | 58 | && Objects.equals(getTarget(), that.getTarget()) |
59 | && Objects.equals(getSubstitution(), that.getSubstitution()); | 59 | && Objects.equals(getSubstitution(), that.getSubstitution()); |
60 | } | 60 | } |
61 | 61 | ||
62 | @Override | 62 | @Override |
63 | public int hashCode() { | 63 | public int hashCode() { |
64 | return Objects.hash(kind, getTarget(), getSubstitution()); | 64 | return Objects.hash(polarity, getTarget(), getSubstitution()); |
65 | } | 65 | } |
66 | } | 66 | } |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/query/atom/CallKind.java b/subprojects/store/src/main/java/tools/refinery/store/query/atom/CallKind.java deleted file mode 100644 index 86066b8e..00000000 --- a/subprojects/store/src/main/java/tools/refinery/store/query/atom/CallKind.java +++ /dev/null | |||
@@ -1,11 +0,0 @@ | |||
1 | package tools.refinery.store.query.atom; | ||
2 | |||
3 | public sealed interface CallKind permits BasicCallKind, CountCallKind { | ||
4 | boolean isPositive(); | ||
5 | |||
6 | boolean isTransitive(); | ||
7 | |||
8 | static CallKind fromBoolean(boolean positive) { | ||
9 | return positive ? BasicCallKind.POSITIVE : BasicCallKind.NEGATIVE; | ||
10 | } | ||
11 | } | ||
diff --git a/subprojects/store/src/main/java/tools/refinery/store/query/atom/CallPolarity.java b/subprojects/store/src/main/java/tools/refinery/store/query/atom/CallPolarity.java new file mode 100644 index 00000000..2ab2b6d2 --- /dev/null +++ b/subprojects/store/src/main/java/tools/refinery/store/query/atom/CallPolarity.java | |||
@@ -0,0 +1,11 @@ | |||
1 | package tools.refinery.store.query.atom; | ||
2 | |||
3 | public sealed interface CallPolarity permits SimplePolarity, CountingPolarity { | ||
4 | boolean isPositive(); | ||
5 | |||
6 | boolean isTransitive(); | ||
7 | |||
8 | static CallPolarity fromBoolean(boolean positive) { | ||
9 | return positive ? SimplePolarity.POSITIVE : SimplePolarity.NEGATIVE; | ||
10 | } | ||
11 | } | ||
diff --git a/subprojects/store/src/main/java/tools/refinery/store/query/atom/CountCallKind.java b/subprojects/store/src/main/java/tools/refinery/store/query/atom/CountingPolarity.java index 2c85cb4f..08a62f4f 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/query/atom/CountCallKind.java +++ b/subprojects/store/src/main/java/tools/refinery/store/query/atom/CountingPolarity.java | |||
@@ -1,6 +1,6 @@ | |||
1 | package tools.refinery.store.query.atom; | 1 | package tools.refinery.store.query.atom; |
2 | 2 | ||
3 | public record CountCallKind(ComparisonOperator operator, int threshold) implements CallKind { | 3 | public record CountingPolarity(ComparisonOperator operator, int threshold) implements CallPolarity { |
4 | @Override | 4 | @Override |
5 | public boolean isPositive() { | 5 | public boolean isPositive() { |
6 | return false; | 6 | return false; |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/query/atom/BasicCallKind.java b/subprojects/store/src/main/java/tools/refinery/store/query/atom/SimplePolarity.java index cf2ffc07..d243bf26 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/query/atom/BasicCallKind.java +++ b/subprojects/store/src/main/java/tools/refinery/store/query/atom/SimplePolarity.java | |||
@@ -1,6 +1,6 @@ | |||
1 | package tools.refinery.store.query.atom; | 1 | package tools.refinery.store.query.atom; |
2 | 2 | ||
3 | public enum BasicCallKind implements CallKind { | 3 | public enum SimplePolarity implements CallPolarity { |
4 | POSITIVE(true, false), | 4 | POSITIVE(true, false), |
5 | NEGATIVE(false, false), | 5 | NEGATIVE(false, false), |
6 | TRANSITIVE(true, true); | 6 | TRANSITIVE(true, true); |
@@ -9,7 +9,7 @@ public enum BasicCallKind implements CallKind { | |||
9 | 9 | ||
10 | private final boolean transitive; | 10 | private final boolean transitive; |
11 | 11 | ||
12 | BasicCallKind(boolean positive, boolean transitive) { | 12 | SimplePolarity(boolean positive, boolean transitive) { |
13 | this.positive = positive; | 13 | this.positive = positive; |
14 | this.transitive = transitive; | 14 | this.transitive = transitive; |
15 | } | 15 | } |