diff options
Diffstat (limited to 'subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/literal/ModalConstraint.java')
-rw-r--r-- | subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/literal/ModalConstraint.java | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/literal/ModalConstraint.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/literal/ModalConstraint.java index 4e5a6099..2235a95d 100644 --- a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/literal/ModalConstraint.java +++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/literal/ModalConstraint.java | |||
@@ -6,18 +6,29 @@ | |||
6 | package tools.refinery.store.reasoning.literal; | 6 | package tools.refinery.store.reasoning.literal; |
7 | 7 | ||
8 | import tools.refinery.store.query.Constraint; | 8 | import tools.refinery.store.query.Constraint; |
9 | import tools.refinery.store.query.InvalidQueryException; | ||
9 | import tools.refinery.store.query.equality.LiteralEqualityHelper; | 10 | import tools.refinery.store.query.equality.LiteralEqualityHelper; |
10 | import tools.refinery.store.query.literal.Reduction; | 11 | import tools.refinery.store.query.literal.Reduction; |
11 | import tools.refinery.store.query.term.Parameter; | 12 | import tools.refinery.store.query.term.Parameter; |
13 | import tools.refinery.store.query.view.AnySymbolView; | ||
12 | 14 | ||
13 | import java.util.List; | 15 | import java.util.List; |
14 | 16 | ||
15 | public record ModalConstraint(Modality modality, Constraint constraint) implements Constraint { | 17 | public record ModalConstraint(Modality modality, Concreteness concreteness, Constraint constraint) |
16 | private static final String FORMAT = "%s %s"; | 18 | implements Constraint { |
19 | public ModalConstraint { | ||
20 | if (constraint instanceof AnySymbolView || constraint instanceof ModalConstraint) { | ||
21 | throw new InvalidQueryException("Already concrete constraints cannot be abstracted"); | ||
22 | } | ||
23 | } | ||
24 | |||
25 | public ModalConstraint(Modality modality, Constraint constraint) { | ||
26 | this(modality, Concreteness.PARTIAL, constraint); | ||
27 | } | ||
17 | 28 | ||
18 | @Override | 29 | @Override |
19 | public String name() { | 30 | public String name() { |
20 | return FORMAT.formatted(modality, constraint.name()); | 31 | return formatName(constraint.name()); |
21 | } | 32 | } |
22 | 33 | ||
23 | @Override | 34 | @Override |
@@ -36,16 +47,33 @@ public record ModalConstraint(Modality modality, Constraint constraint) implemen | |||
36 | return false; | 47 | return false; |
37 | } | 48 | } |
38 | var otherModalConstraint = (ModalConstraint) other; | 49 | var otherModalConstraint = (ModalConstraint) other; |
39 | return modality == otherModalConstraint.modality && constraint.equals(helper, otherModalConstraint.constraint); | 50 | return modality == otherModalConstraint.modality && |
51 | concreteness == otherModalConstraint.concreteness && | ||
52 | constraint.equals(helper, otherModalConstraint.constraint); | ||
40 | } | 53 | } |
41 | 54 | ||
42 | @Override | 55 | @Override |
43 | public String toReferenceString() { | 56 | public String toReferenceString() { |
44 | return FORMAT.formatted(modality, constraint.toReferenceString()); | 57 | return formatName(constraint.toReferenceString()); |
45 | } | 58 | } |
46 | 59 | ||
47 | @Override | 60 | @Override |
48 | public String toString() { | 61 | public String toString() { |
49 | return FORMAT.formatted(modality, constraint); | 62 | return formatName(constraint.toString()); |
63 | } | ||
64 | |||
65 | private String formatName(String constraintName) { | ||
66 | if (concreteness == Concreteness.PARTIAL) { | ||
67 | return "%s %s".formatted(modality, constraintName); | ||
68 | } | ||
69 | return "%s %s %s".formatted(modality, concreteness, constraintName); | ||
70 | } | ||
71 | |||
72 | public static Constraint of(Modality modality, Concreteness concreteness, Constraint constraint) { | ||
73 | if (constraint instanceof AnySymbolView || constraint instanceof ModalConstraint) { | ||
74 | // Symbol views and lifted constraints are already concrete. Thus, they cannot be abstracted at all. | ||
75 | return constraint; | ||
76 | } | ||
77 | return new ModalConstraint(modality, concreteness, constraint); | ||
50 | } | 78 | } |
51 | } | 79 | } |