diff options
Diffstat (limited to 'subprojects/logic/src/main/java/tools/refinery/logic/dnf/RelationalQuery.java')
-rw-r--r-- | subprojects/logic/src/main/java/tools/refinery/logic/dnf/RelationalQuery.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/subprojects/logic/src/main/java/tools/refinery/logic/dnf/RelationalQuery.java b/subprojects/logic/src/main/java/tools/refinery/logic/dnf/RelationalQuery.java new file mode 100644 index 00000000..dc2b8eb6 --- /dev/null +++ b/subprojects/logic/src/main/java/tools/refinery/logic/dnf/RelationalQuery.java | |||
@@ -0,0 +1,77 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.logic.dnf; | ||
7 | |||
8 | import tools.refinery.logic.InvalidQueryException; | ||
9 | import tools.refinery.logic.literal.CallLiteral; | ||
10 | import tools.refinery.logic.literal.CallPolarity; | ||
11 | import tools.refinery.logic.term.AssignedValue; | ||
12 | import tools.refinery.logic.term.NodeVariable; | ||
13 | |||
14 | import java.util.Collections; | ||
15 | import java.util.List; | ||
16 | |||
17 | public final class RelationalQuery extends Query<Boolean> { | ||
18 | RelationalQuery(Dnf dnf) { | ||
19 | super(dnf); | ||
20 | for (var parameter : dnf.getSymbolicParameters()) { | ||
21 | var parameterType = parameter.tryGetType(); | ||
22 | if (parameterType.isPresent()) { | ||
23 | throw new InvalidQueryException("Expected parameter %s of %s to be a node variable, got %s instead" | ||
24 | .formatted(parameter, dnf, parameterType.get().getName())); | ||
25 | } | ||
26 | } | ||
27 | } | ||
28 | |||
29 | @Override | ||
30 | public int arity() { | ||
31 | return getDnf().arity(); | ||
32 | } | ||
33 | |||
34 | @Override | ||
35 | public Class<Boolean> valueType() { | ||
36 | return Boolean.class; | ||
37 | } | ||
38 | |||
39 | @Override | ||
40 | public Boolean defaultValue() { | ||
41 | return false; | ||
42 | } | ||
43 | |||
44 | @Override | ||
45 | protected RelationalQuery withDnfInternal(Dnf newDnf) { | ||
46 | return newDnf.asRelation(); | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public RelationalQuery withDnf(Dnf newDnf) { | ||
51 | return (RelationalQuery) super.withDnf(newDnf); | ||
52 | } | ||
53 | |||
54 | public CallLiteral call(CallPolarity polarity, List<NodeVariable> arguments) { | ||
55 | return getDnf().call(polarity, Collections.unmodifiableList(arguments)); | ||
56 | } | ||
57 | |||
58 | public CallLiteral call(CallPolarity polarity, NodeVariable... arguments) { | ||
59 | return getDnf().call(polarity, arguments); | ||
60 | } | ||
61 | |||
62 | public CallLiteral call(NodeVariable... arguments) { | ||
63 | return getDnf().call(arguments); | ||
64 | } | ||
65 | |||
66 | public CallLiteral callTransitive(NodeVariable left, NodeVariable right) { | ||
67 | return getDnf().callTransitive(left, right); | ||
68 | } | ||
69 | |||
70 | public AssignedValue<Integer> count(List<NodeVariable> arguments) { | ||
71 | return getDnf().count(Collections.unmodifiableList(arguments)); | ||
72 | } | ||
73 | |||
74 | public AssignedValue<Integer> count(NodeVariable... arguments) { | ||
75 | return getDnf().count(arguments); | ||
76 | } | ||
77 | } | ||