diff options
4 files changed, 50 insertions, 1 deletions
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalRuntimeContext.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalRuntimeContext.java index 0f2daca8..df80a33e 100644 --- a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalRuntimeContext.java +++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/context/RelationalRuntimeContext.java | |||
@@ -119,10 +119,20 @@ public class RelationalRuntimeContext implements IQueryRuntimeContext { | |||
119 | 119 | ||
120 | private Iterable<Object[]> enumerate(IInputKey key, TupleMask seedMask, ITuple seed) { | 120 | private Iterable<Object[]> enumerate(IInputKey key, TupleMask seedMask, ITuple seed) { |
121 | var relationViewKey = checkKey(key); | 121 | var relationViewKey = checkKey(key); |
122 | Iterable<Object[]> allObjects = relationViewKey.getAll(model); | 122 | Iterable<Object[]> allObjects = getAllObjects(relationViewKey, seedMask, seed); |
123 | return filter(allObjects, objectArray -> isMatching(objectArray, seedMask, seed)); | 123 | return filter(allObjects, objectArray -> isMatching(objectArray, seedMask, seed)); |
124 | } | 124 | } |
125 | 125 | ||
126 | private Iterable<Object[]> getAllObjects(AnySymbolView key, TupleMask seedMask, ITuple seed) { | ||
127 | for (int i = 0; i < seedMask.indices.length; i++) { | ||
128 | int slot = seedMask.indices[i]; | ||
129 | if (key.canIndexSlot(slot)) { | ||
130 | return key.getAdjacent(model, slot, seed.get(i)); | ||
131 | } | ||
132 | } | ||
133 | return key.getAll(model); | ||
134 | } | ||
135 | |||
126 | private static boolean isMatching(Object[] tuple, TupleMask seedMask, ITuple seed) { | 136 | private static boolean isMatching(Object[] tuple, TupleMask seedMask, ITuple seed) { |
127 | for (int i = 0; i < seedMask.indices.length; i++) { | 137 | for (int i = 0; i < seedMask.indices.length; i++) { |
128 | final Object seedElement = seed.get(i); | 138 | final Object seedElement = seed.get(i); |
diff --git a/subprojects/store-query/src/main/java/tools/refinery/store/query/view/AbstractFunctionView.java b/subprojects/store-query/src/main/java/tools/refinery/store/query/view/AbstractFunctionView.java index fd37604e..f130fa59 100644 --- a/subprojects/store-query/src/main/java/tools/refinery/store/query/view/AbstractFunctionView.java +++ b/subprojects/store-query/src/main/java/tools/refinery/store/query/view/AbstractFunctionView.java | |||
@@ -5,6 +5,7 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.store.query.view; | 6 | package tools.refinery.store.query.view; |
7 | 7 | ||
8 | import tools.refinery.store.map.CursorAsIterator; | ||
8 | import tools.refinery.store.model.Model; | 9 | import tools.refinery.store.model.Model; |
9 | import tools.refinery.store.query.dnf.FunctionalDependency; | 10 | import tools.refinery.store.query.dnf.FunctionalDependency; |
10 | import tools.refinery.store.query.term.Parameter; | 11 | import tools.refinery.store.query.term.Parameter; |
@@ -83,6 +84,20 @@ public abstract class AbstractFunctionView<T> extends SymbolView<T> { | |||
83 | } | 84 | } |
84 | 85 | ||
85 | @Override | 86 | @Override |
87 | public boolean canIndexSlot(int slot) { | ||
88 | return slot >= 0 && slot < getSymbol().arity(); | ||
89 | } | ||
90 | |||
91 | @Override | ||
92 | public Iterable<Object[]> getAdjacent(Model model, int slot, Object value) { | ||
93 | if (!(value instanceof Tuple1 tuple1)) { | ||
94 | return Set.of(); | ||
95 | } | ||
96 | return (() -> new CursorAsIterator<>(model.getInterpretation(getSymbol()).getAdjacent(slot, tuple1.get(0)), | ||
97 | this::forwardMap, this::filter)); | ||
98 | } | ||
99 | |||
100 | @Override | ||
86 | public List<Parameter> getParameters() { | 101 | public List<Parameter> getParameters() { |
87 | return parameters; | 102 | return parameters; |
88 | } | 103 | } |
diff --git a/subprojects/store-query/src/main/java/tools/refinery/store/query/view/AnySymbolView.java b/subprojects/store-query/src/main/java/tools/refinery/store/query/view/AnySymbolView.java index 90b27ebb..7e9bf6df 100644 --- a/subprojects/store-query/src/main/java/tools/refinery/store/query/view/AnySymbolView.java +++ b/subprojects/store-query/src/main/java/tools/refinery/store/query/view/AnySymbolView.java | |||
@@ -28,4 +28,12 @@ public sealed interface AnySymbolView extends Constraint permits SymbolView { | |||
28 | boolean get(Model model, Object[] tuple); | 28 | boolean get(Model model, Object[] tuple); |
29 | 29 | ||
30 | Iterable<Object[]> getAll(Model model); | 30 | Iterable<Object[]> getAll(Model model); |
31 | |||
32 | default Iterable<Object[]> getAdjacent(Model model, int slot, Object value) { | ||
33 | throw new IllegalArgumentException("Cannot index slot " + slot); | ||
34 | } | ||
35 | |||
36 | default boolean canIndexSlot(int slot) { | ||
37 | return false; | ||
38 | } | ||
31 | } | 39 | } |
diff --git a/subprojects/store-query/src/main/java/tools/refinery/store/query/view/TuplePreservingView.java b/subprojects/store-query/src/main/java/tools/refinery/store/query/view/TuplePreservingView.java index 6bc5a708..ed12cd9d 100644 --- a/subprojects/store-query/src/main/java/tools/refinery/store/query/view/TuplePreservingView.java +++ b/subprojects/store-query/src/main/java/tools/refinery/store/query/view/TuplePreservingView.java | |||
@@ -5,6 +5,7 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.store.query.view; | 6 | package tools.refinery.store.query.view; |
7 | 7 | ||
8 | import tools.refinery.store.map.CursorAsIterator; | ||
8 | import tools.refinery.store.model.Model; | 9 | import tools.refinery.store.model.Model; |
9 | import tools.refinery.store.query.term.Parameter; | 10 | import tools.refinery.store.query.term.Parameter; |
10 | import tools.refinery.store.representation.Symbol; | 11 | import tools.refinery.store.representation.Symbol; |
@@ -14,6 +15,7 @@ import tools.refinery.store.tuple.Tuple1; | |||
14 | import java.util.Arrays; | 15 | import java.util.Arrays; |
15 | import java.util.List; | 16 | import java.util.List; |
16 | import java.util.Objects; | 17 | import java.util.Objects; |
18 | import java.util.Set; | ||
17 | 19 | ||
18 | public abstract class TuplePreservingView<T> extends SymbolView<T> { | 20 | public abstract class TuplePreservingView<T> extends SymbolView<T> { |
19 | private final List<Parameter> parameters; | 21 | private final List<Parameter> parameters; |
@@ -56,6 +58,20 @@ public abstract class TuplePreservingView<T> extends SymbolView<T> { | |||
56 | } | 58 | } |
57 | 59 | ||
58 | @Override | 60 | @Override |
61 | public boolean canIndexSlot(int slot) { | ||
62 | return slot >= 0 && slot < getSymbol().arity(); | ||
63 | } | ||
64 | |||
65 | @Override | ||
66 | public Iterable<Object[]> getAdjacent(Model model, int slot, Object value) { | ||
67 | if (!(value instanceof Tuple1 tuple1)) { | ||
68 | return Set.of(); | ||
69 | } | ||
70 | return (() -> new CursorAsIterator<>(model.getInterpretation(getSymbol()).getAdjacent(slot, tuple1.get(0)), | ||
71 | this::forwardMap, this::filter)); | ||
72 | } | ||
73 | |||
74 | @Override | ||
59 | public List<Parameter> getParameters() { | 75 | public List<Parameter> getParameters() { |
60 | return parameters; | 76 | return parameters; |
61 | } | 77 | } |