diff options
Diffstat (limited to 'subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/DNF2PQuery.java')
-rw-r--r-- | subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/pquery/DNF2PQuery.java | 37 |
1 files changed, 5 insertions, 32 deletions
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 ae99365d..98054161 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 | |||
@@ -85,8 +85,6 @@ public class DNF2PQuery { | |||
85 | translateCallAtom(callAtom, body); | 85 | translateCallAtom(callAtom, body); |
86 | } else if (constraint instanceof ConstantAtom constantAtom) { | 86 | } else if (constraint instanceof ConstantAtom constantAtom) { |
87 | translateConstantAtom(constantAtom, body); | 87 | translateConstantAtom(constantAtom, body); |
88 | } else if (constraint instanceof CountNotEqualsAtom<?> countNotEqualsAtom) { | ||
89 | translateCountNotEqualsAtom(countNotEqualsAtom, body); | ||
90 | } else { | 88 | } else { |
91 | throw new IllegalArgumentException("Unknown constraint: " + constraint.toString()); | 89 | throw new IllegalArgumentException("Unknown constraint: " + constraint.toString()); |
92 | } | 90 | } |
@@ -128,20 +126,11 @@ public class DNF2PQuery { | |||
128 | var variablesTuple = translateSubstitution(callAtom.getSubstitution(), body); | 126 | var variablesTuple = translateSubstitution(callAtom.getSubstitution(), body); |
129 | var translatedReferred = translate(target); | 127 | var translatedReferred = translate(target); |
130 | var polarity = callAtom.getPolarity(); | 128 | var polarity = callAtom.getPolarity(); |
131 | if (polarity instanceof SimplePolarity simplePolarity) { | 129 | switch (polarity) { |
132 | switch (simplePolarity) { | 130 | case POSITIVE -> new PositivePatternCall(body, variablesTuple, translatedReferred); |
133 | case POSITIVE -> new PositivePatternCall(body, variablesTuple, translatedReferred); | 131 | case TRANSITIVE -> new BinaryTransitiveClosure(body, variablesTuple, translatedReferred); |
134 | case TRANSITIVE -> new BinaryTransitiveClosure(body, variablesTuple, translatedReferred); | 132 | case NEGATIVE -> new NegativePatternCall(body, variablesTuple, translatedReferred); |
135 | case NEGATIVE -> new NegativePatternCall(body, variablesTuple, translatedReferred); | 133 | default -> throw new IllegalArgumentException("Unknown polarity: " + polarity); |
136 | default -> throw new IllegalArgumentException("Unknown BasicCallKind: " + simplePolarity); | ||
137 | } | ||
138 | } else if (polarity instanceof CountingPolarity countingPolarity) { | ||
139 | var countVariableName = DNFUtils.generateUniqueName("count"); | ||
140 | var countPVariable = body.getOrCreateVariableByName(countVariableName); | ||
141 | new PatternMatchCounter(body, variablesTuple, translatedReferred, countPVariable); | ||
142 | new ExpressionEvaluation(body, new CountExpressionEvaluator(countVariableName, countingPolarity), null); | ||
143 | } else { | ||
144 | throw new IllegalArgumentException("Unknown CallKind: " + polarity); | ||
145 | } | 134 | } |
146 | } | 135 | } |
147 | 136 | ||
@@ -149,20 +138,4 @@ public class DNF2PQuery { | |||
149 | var variable = body.getOrCreateVariableByName(constantAtom.variable().getUniqueName()); | 138 | var variable = body.getOrCreateVariableByName(constantAtom.variable().getUniqueName()); |
150 | new ConstantValue(body, variable, constantAtom.nodeId()); | 139 | new ConstantValue(body, variable, constantAtom.nodeId()); |
151 | } | 140 | } |
152 | |||
153 | private void translateCountNotEqualsAtom(CountNotEqualsAtom<?> countNotEqualsAtom, PBody body) { | ||
154 | if (!(countNotEqualsAtom.mayTarget() instanceof DNF mayTarget) || | ||
155 | !(countNotEqualsAtom.mustTarget() instanceof DNF mustTarget)) { | ||
156 | throw new IllegalArgumentException("Only calls to DNF are supported"); | ||
157 | } | ||
158 | var variablesTuple = translateSubstitution(countNotEqualsAtom.substitution(), body); | ||
159 | var mayCountName = DNFUtils.generateUniqueName("countMay"); | ||
160 | var mayCountVariable = body.getOrCreateVariableByName(mayCountName); | ||
161 | new PatternMatchCounter(body, variablesTuple, translate(mayTarget), mayCountVariable); | ||
162 | var mustCountName = DNFUtils.generateUniqueName("countMust"); | ||
163 | var mustCountVariable = body.getOrCreateVariableByName(mustCountName); | ||
164 | new PatternMatchCounter(body, variablesTuple, translate(mustTarget), mustCountVariable); | ||
165 | new ExpressionEvaluation(body, new CountNotEqualsExpressionEvaluator(countNotEqualsAtom.must(), | ||
166 | countNotEqualsAtom.threshold(), mayCountName, mustCountName), null); | ||
167 | } | ||
168 | } | 141 | } |