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 | 34 |
1 files changed, 26 insertions, 8 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 aa3fba6e..2b5618d2 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 | |||
@@ -1,5 +1,6 @@ | |||
1 | package tools.refinery.store.query.viatra.internal.pquery; | 1 | package tools.refinery.store.query.viatra.internal.pquery; |
2 | 2 | ||
3 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
3 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | 4 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; |
4 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | 5 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; |
5 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | 6 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; |
@@ -20,20 +21,28 @@ import tools.refinery.store.query.atom.*; | |||
20 | import tools.refinery.store.query.view.AnyRelationView; | 21 | import tools.refinery.store.query.view.AnyRelationView; |
21 | 22 | ||
22 | import java.util.*; | 23 | import java.util.*; |
24 | import java.util.function.Function; | ||
23 | import java.util.stream.Collectors; | 25 | import java.util.stream.Collectors; |
24 | 26 | ||
25 | public class DNF2PQuery { | 27 | public class DNF2PQuery { |
26 | private final Set<DNF> translating = new LinkedHashSet<>(); | 28 | private final Set<DNF> translating = new LinkedHashSet<>(); |
27 | 29 | ||
28 | private final Map<DNF, SimplePQuery> dnf2PQueryMap = new HashMap<>(); | 30 | private final Map<DNF, RawPQuery> dnf2PQueryMap = new HashMap<>(); |
29 | 31 | ||
30 | private final Map<AnyRelationView, RelationViewWrapper> view2WrapperMap = new HashMap<>(); | 32 | private final Map<AnyRelationView, RelationViewWrapper> view2WrapperMap = new LinkedHashMap<>(); |
31 | 33 | ||
32 | public SimplePQuery translate(DNF dnfQuery) { | 34 | private Function<DNF, QueryEvaluationHint> computeHint = dnf -> new QueryEvaluationHint(null, |
35 | QueryEvaluationHint.BackendRequirement.UNSPECIFIED); | ||
36 | |||
37 | public void setComputeHint(Function<DNF, QueryEvaluationHint> computeHint) { | ||
38 | this.computeHint = computeHint; | ||
39 | } | ||
40 | |||
41 | public RawPQuery translate(DNF dnfQuery) { | ||
33 | if (translating.contains(dnfQuery)) { | 42 | if (translating.contains(dnfQuery)) { |
34 | var path = translating.stream().map(DNF::getName).collect(Collectors.joining(" -> ")); | 43 | var path = translating.stream().map(DNF::name).collect(Collectors.joining(" -> ")); |
35 | throw new IllegalStateException("Circular reference %s -> %s detected".formatted(path, | 44 | throw new IllegalStateException("Circular reference %s -> %s detected".formatted(path, |
36 | dnfQuery.getName())); | 45 | dnfQuery.name())); |
37 | } | 46 | } |
38 | // We can't use computeIfAbsent here, because translating referenced queries calls this method in a reentrant | 47 | // We can't use computeIfAbsent here, because translating referenced queries calls this method in a reentrant |
39 | // way, which would cause a ConcurrentModificationException with computeIfAbsent. | 48 | // way, which would cause a ConcurrentModificationException with computeIfAbsent. |
@@ -50,8 +59,17 @@ public class DNF2PQuery { | |||
50 | return pQuery; | 59 | return pQuery; |
51 | } | 60 | } |
52 | 61 | ||
53 | private SimplePQuery doTranslate(DNF dnfQuery) { | 62 | public Collection<AnyRelationView> getRelationViews() { |
54 | var pQuery = new SimplePQuery(dnfQuery.getUniqueName()); | 63 | return Collections.unmodifiableCollection(view2WrapperMap.keySet()); |
64 | } | ||
65 | |||
66 | public RawPQuery getAlreadyTranslated(DNF dnfQuery) { | ||
67 | return dnf2PQueryMap.get(dnfQuery); | ||
68 | } | ||
69 | |||
70 | private RawPQuery doTranslate(DNF dnfQuery) { | ||
71 | var pQuery = new RawPQuery(dnfQuery.getUniqueName()); | ||
72 | pQuery.setEvaluationHints(computeHint.apply(dnfQuery)); | ||
55 | 73 | ||
56 | Map<Variable, PParameter> parameters = new HashMap<>(); | 74 | Map<Variable, PParameter> parameters = new HashMap<>(); |
57 | for (Variable variable : dnfQuery.getParameters()) { | 75 | for (Variable variable : dnfQuery.getParameters()) { |
@@ -86,7 +104,7 @@ public class DNF2PQuery { | |||
86 | translateEquivalenceAtom(equivalenceAtom, body); | 104 | translateEquivalenceAtom(equivalenceAtom, body); |
87 | } else if (constraint instanceof RelationViewAtom relationViewAtom) { | 105 | } else if (constraint instanceof RelationViewAtom relationViewAtom) { |
88 | translateRelationViewAtom(relationViewAtom, body); | 106 | translateRelationViewAtom(relationViewAtom, body); |
89 | } else if (constraint instanceof CallAtom<?> callAtom) { | 107 | } else if (constraint instanceof DNFCallAtom callAtom) { |
90 | translateCallAtom(callAtom, body); | 108 | translateCallAtom(callAtom, body); |
91 | } else if (constraint instanceof ConstantAtom constantAtom) { | 109 | } else if (constraint instanceof ConstantAtom constantAtom) { |
92 | translateConstantAtom(constantAtom, body); | 110 | translateConstantAtom(constantAtom, body); |