diff options
author | 2021-10-25 00:46:39 +0200 | |
---|---|---|
committer | 2021-10-25 00:46:39 +0200 | |
commit | c45435142e4eb776e2f26ba1d6187b0bc4d71400 (patch) | |
tree | cdd7349ed85a6d65c85d972775332b31ec5b98d5 /store/src/main/java | |
parent | Existentially quantified variable test (diff) | |
download | refinery-c45435142e4eb776e2f26ba1d6187b0bc4d71400.tar.gz refinery-c45435142e4eb776e2f26ba1d6187b0bc4d71400.tar.zst refinery-c45435142e4eb776e2f26ba1d6187b0bc4d71400.zip |
Small fixes in query transformation and view equivalence checking
Diffstat (limited to 'store/src/main/java')
3 files changed, 12 insertions, 13 deletions
diff --git a/store/src/main/java/tools/refinery/store/query/QueriableModelStoreImpl.java b/store/src/main/java/tools/refinery/store/query/QueriableModelStoreImpl.java index 6a340589..653783dd 100644 --- a/store/src/main/java/tools/refinery/store/query/QueriableModelStoreImpl.java +++ b/store/src/main/java/tools/refinery/store/query/QueriableModelStoreImpl.java | |||
@@ -19,6 +19,7 @@ import tools.refinery.store.query.building.RelationAtom; | |||
19 | import tools.refinery.store.query.internal.DNF2PQuery; | 19 | import tools.refinery.store.query.internal.DNF2PQuery; |
20 | import tools.refinery.store.query.internal.QueriableModelImpl; | 20 | import tools.refinery.store.query.internal.QueriableModelImpl; |
21 | import tools.refinery.store.query.internal.RawPatternMatcher; | 21 | import tools.refinery.store.query.internal.RawPatternMatcher; |
22 | import tools.refinery.store.query.internal.DNF2PQuery.SimplePQuery; | ||
22 | import tools.refinery.store.query.view.RelationView; | 23 | import tools.refinery.store.query.view.RelationView; |
23 | 24 | ||
24 | public class QueriableModelStoreImpl implements QueriableModelStore { | 25 | public class QueriableModelStoreImpl implements QueriableModelStore { |
@@ -82,9 +83,9 @@ public class QueriableModelStoreImpl implements QueriableModelStore { | |||
82 | 83 | ||
83 | private Map<DNFPredicate, GenericQuerySpecification<RawPatternMatcher>> initPredicates(Set<DNFPredicate> predicates) { | 84 | private Map<DNFPredicate, GenericQuerySpecification<RawPatternMatcher>> initPredicates(Set<DNFPredicate> predicates) { |
84 | Map<DNFPredicate, GenericQuerySpecification<RawPatternMatcher>> result = new HashMap<>(); | 85 | Map<DNFPredicate, GenericQuerySpecification<RawPatternMatcher>> result = new HashMap<>(); |
85 | 86 | Map<DNFPredicate, SimplePQuery> dnf2PQueryMap = new HashMap<>(); | |
86 | for (DNFPredicate dnfPredicate : predicates) { | 87 | for (DNFPredicate dnfPredicate : predicates) { |
87 | GenericQuerySpecification<RawPatternMatcher> query = DNF2PQuery.translate(dnfPredicate).build(); | 88 | GenericQuerySpecification<RawPatternMatcher> query = DNF2PQuery.translate(dnfPredicate,dnf2PQueryMap).build(); |
88 | result.put(dnfPredicate, query); | 89 | result.put(dnfPredicate, query); |
89 | } | 90 | } |
90 | 91 | ||
diff --git a/store/src/main/java/tools/refinery/store/query/internal/DNF2PQuery.java b/store/src/main/java/tools/refinery/store/query/internal/DNF2PQuery.java index aa797cde..5e408f59 100644 --- a/store/src/main/java/tools/refinery/store/query/internal/DNF2PQuery.java +++ b/store/src/main/java/tools/refinery/store/query/internal/DNF2PQuery.java | |||
@@ -35,9 +35,9 @@ import tools.refinery.store.query.building.RelationAtom; | |||
35 | import tools.refinery.store.query.building.Variable; | 35 | import tools.refinery.store.query.building.Variable; |
36 | 36 | ||
37 | public class DNF2PQuery { | 37 | public class DNF2PQuery { |
38 | private static Map<DNFPredicate, SimplePQuery> DNF2PQueryMap = new HashMap<>(); | 38 | //private static Map<DNFPredicate, SimplePQuery> DNF2PQueryMap = new HashMap<>(); |
39 | 39 | ||
40 | public static SimplePQuery translate(DNFPredicate predicate) { | 40 | public static SimplePQuery translate(DNFPredicate predicate, Map<DNFPredicate, SimplePQuery> DNF2PQueryMap) { |
41 | SimplePQuery query = DNF2PQueryMap.get(predicate); | 41 | SimplePQuery query = DNF2PQueryMap.get(predicate); |
42 | if (query != null) { | 42 | if (query != null) { |
43 | return query; | 43 | return query; |
@@ -61,14 +61,14 @@ public class DNF2PQuery { | |||
61 | body.setSymbolicParameters(symbolicParameters); | 61 | body.setSymbolicParameters(symbolicParameters); |
62 | query.addBody(body); | 62 | query.addBody(body); |
63 | for (DNFAtom constraint : clause.getConstraints()) { | 63 | for (DNFAtom constraint : clause.getConstraints()) { |
64 | translateDNFAtom(constraint, body); | 64 | translateDNFAtom(constraint, body, DNF2PQueryMap); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | DNF2PQueryMap.put(predicate, query); | 67 | DNF2PQueryMap.put(predicate, query); |
68 | return query; | 68 | return query; |
69 | } | 69 | } |
70 | 70 | ||
71 | private static void translateDNFAtom(DNFAtom constraint, PBody body) { | 71 | private static void translateDNFAtom(DNFAtom constraint, PBody body, Map<DNFPredicate, SimplePQuery> DNF2PQueryMap) { |
72 | if (constraint instanceof EquivalenceAtom equivalence) { | 72 | if (constraint instanceof EquivalenceAtom equivalence) { |
73 | translateEquivalenceAtom(equivalence, body); | 73 | translateEquivalenceAtom(equivalence, body); |
74 | } | 74 | } |
@@ -76,7 +76,7 @@ public class DNF2PQuery { | |||
76 | translateRelationAtom(relation, body); | 76 | translateRelationAtom(relation, body); |
77 | } | 77 | } |
78 | if (constraint instanceof PredicateAtom predicate) { | 78 | if (constraint instanceof PredicateAtom predicate) { |
79 | translatePredicateAtom(predicate, body); | 79 | translatePredicateAtom(predicate, body, DNF2PQueryMap); |
80 | } | 80 | } |
81 | } | 81 | } |
82 | 82 | ||
@@ -101,7 +101,7 @@ public class DNF2PQuery { | |||
101 | new TypeConstraint(body, Tuples.flatTupleOf(variables), relation.getView()); | 101 | new TypeConstraint(body, Tuples.flatTupleOf(variables), relation.getView()); |
102 | } | 102 | } |
103 | 103 | ||
104 | private static void translatePredicateAtom(PredicateAtom predicate, PBody body) { | 104 | private static void translatePredicateAtom(PredicateAtom predicate, PBody body, Map<DNFPredicate, SimplePQuery> DNF2PQueryMap) { |
105 | Object[] variables = new Object[predicate.getSubstitution().size()]; | 105 | Object[] variables = new Object[predicate.getSubstitution().size()]; |
106 | for (int i = 0; i < predicate.getSubstitution().size(); i++) { | 106 | for (int i = 0; i < predicate.getSubstitution().size(); i++) { |
107 | variables[i] = body.getOrCreateVariableByName(predicate.getSubstitution().get(i).getName()); | 107 | variables[i] = body.getOrCreateVariableByName(predicate.getSubstitution().get(i).getName()); |
@@ -112,17 +112,17 @@ public class DNF2PQuery { | |||
112 | throw new IllegalArgumentException("Transitive Predicate Atoms must be binary."); | 112 | throw new IllegalArgumentException("Transitive Predicate Atoms must be binary."); |
113 | } | 113 | } |
114 | new BinaryTransitiveClosure(body, Tuples.flatTupleOf(variables), | 114 | new BinaryTransitiveClosure(body, Tuples.flatTupleOf(variables), |
115 | DNF2PQuery.translate(predicate.getReferred())); | 115 | DNF2PQuery.translate(predicate.getReferred(), DNF2PQueryMap)); |
116 | } else { | 116 | } else { |
117 | new PositivePatternCall(body, Tuples.flatTupleOf(variables), | 117 | new PositivePatternCall(body, Tuples.flatTupleOf(variables), |
118 | DNF2PQuery.translate(predicate.getReferred())); | 118 | DNF2PQuery.translate(predicate.getReferred(), DNF2PQueryMap)); |
119 | } | 119 | } |
120 | } else { | 120 | } else { |
121 | if (predicate.isTransitive()) { | 121 | if (predicate.isTransitive()) { |
122 | throw new InputMismatchException("Transitive Predicate Atoms cannot be negative."); | 122 | throw new InputMismatchException("Transitive Predicate Atoms cannot be negative."); |
123 | } else { | 123 | } else { |
124 | new NegativePatternCall(body, Tuples.flatTupleOf(variables), | 124 | new NegativePatternCall(body, Tuples.flatTupleOf(variables), |
125 | DNF2PQuery.translate(predicate.getReferred())); | 125 | DNF2PQuery.translate(predicate.getReferred(), DNF2PQueryMap)); |
126 | } | 126 | } |
127 | } | 127 | } |
128 | } | 128 | } |
diff --git a/store/src/main/java/tools/refinery/store/query/view/RelationView.java b/store/src/main/java/tools/refinery/store/query/view/RelationView.java index 2c2a37c4..efe9945f 100644 --- a/store/src/main/java/tools/refinery/store/query/view/RelationView.java +++ b/store/src/main/java/tools/refinery/store/query/view/RelationView.java | |||
@@ -74,8 +74,6 @@ public abstract class RelationView<D> extends BaseInputKeyWrapper<RelationView<D | |||
74 | public boolean equals(Object obj) { | 74 | public boolean equals(Object obj) { |
75 | if (this == obj) | 75 | if (this == obj) |
76 | return true; | 76 | return true; |
77 | if (!super.equals(obj)) | ||
78 | return false; | ||
79 | if (!(obj instanceof RelationView)) | 77 | if (!(obj instanceof RelationView)) |
80 | return false; | 78 | return false; |
81 | @SuppressWarnings("unchecked") | 79 | @SuppressWarnings("unchecked") |