aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/boundary/InputConnector.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/boundary/InputConnector.java')
-rw-r--r--subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/boundary/InputConnector.java208
1 files changed, 208 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/boundary/InputConnector.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/boundary/InputConnector.java
new file mode 100644
index 00000000..c044850f
--- /dev/null
+++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/boundary/InputConnector.java
@@ -0,0 +1,208 @@
1/*******************************************************************************
2 * Copyright (c) 2010-2014, Bergmann Gabor, Istvan Rath and Daniel Varro
3 * This program and the accompanying materials are made available under the
4 * terms of the Eclipse Public License v. 2.0 which is available at
5 * http://www.eclipse.org/legal/epl-v20.html.
6 *
7 * SPDX-License-Identifier: EPL-2.0
8 *******************************************************************************/
9package tools.refinery.viatra.runtime.rete.boundary;
10
11import java.util.Collection;
12import java.util.Collections;
13import java.util.Map;
14import java.util.stream.Stream;
15
16import tools.refinery.viatra.runtime.matchers.context.IInputKey;
17import tools.refinery.viatra.runtime.matchers.tuple.Tuple;
18import tools.refinery.viatra.runtime.matchers.tuple.Tuples;
19import tools.refinery.viatra.runtime.matchers.util.CollectionsFactory;
20import tools.refinery.viatra.runtime.rete.network.Network;
21import tools.refinery.viatra.runtime.rete.network.Node;
22import tools.refinery.viatra.runtime.rete.recipes.InputFilterRecipe;
23import tools.refinery.viatra.runtime.rete.recipes.InputRecipe;
24import tools.refinery.viatra.runtime.rete.remote.Address;
25
26/**
27 * A class responsible for connecting input nodes to the runtime context.
28 *
29 * @author Bergmann Gabor
30 *
31 */
32public final class InputConnector {
33 Network network;
34
35 private Map<IInputKey, Map<Tuple, Address<ExternalInputEnumeratorNode>>> externalInputRoots = CollectionsFactory.createMap();
36
37// /*
38// * arity:1 used as simple entity constraints label is the object representing the type null label means all entities
39// * regardless of type (global supertype), if allowed
40// */
41// protected Map<Object, Address<? extends Tunnel>> unaryRoots = CollectionsFactory.getMap();
42// /*
43// * arity:3 (rel, from, to) used as VPM relation constraints null label means all relations regardless of type
44// * (global supertype)
45// */
46// protected Map<Object, Address<? extends Tunnel>> ternaryEdgeRoots = CollectionsFactory.getMap();
47// /*
48// * arity:2 (from, to) not used over VPM; can be used as EMF references for instance label is the object representing
49// * the type null label means all entities regardless of type if allowed (global supertype), if allowed
50// */
51// protected Map<Object, Address<? extends Tunnel>> binaryEdgeRoots = CollectionsFactory.getMap();
52//
53// protected Address<? extends Tunnel> containmentRoot = null;
54// protected Address<? extends Supplier> containmentTransitiveRoot = null;
55// protected Address<? extends Tunnel> instantiationRoot = null;
56// protected Address<? extends Supplier> instantiationTransitiveRoot = null;
57// protected Address<? extends Tunnel> generalizationRoot = null;
58// protected Address<? extends Supplier> generalizationTransitiveRoot = null;
59
60
61 public InputConnector(Network network) {
62 super();
63 this.network = network;
64 }
65
66
67 public Network getNetwork() {
68 return network;
69 }
70
71
72 /**
73 * Connects a given input filter node to the external input source.
74 */
75 public void connectInputFilter(InputFilterRecipe recipe, Node freshNode) {
76 final ExternalInputStatelessFilterNode inputNode = (ExternalInputStatelessFilterNode)freshNode;
77
78 IInputKey inputKey = (IInputKey) recipe.getInputKey();
79 inputNode.connectThroughContext(network.getEngine(), inputKey);
80 }
81
82
83 /**
84 * Connects a given input enumerator node to the external input source.
85 */
86 public void connectInput(InputRecipe recipe, Node freshNode) {
87 final ExternalInputEnumeratorNode inputNode = (ExternalInputEnumeratorNode)freshNode;
88
89 IInputKey inputKey = (IInputKey) recipe.getInputKey();
90 Tuple seed = nopSeed(inputKey); // no preseeding as of now
91 final Address<ExternalInputEnumeratorNode> freshAddress = Address.of(inputNode);
92 externalInputRoots.computeIfAbsent(inputKey, k -> CollectionsFactory.createMap()).put(seed, freshAddress);
93 inputNode.connectThroughContext(network.getEngine(), inputKey, seed);
94
95// final Address<Tunnel> freshAddress = Address.of((Tunnel)freshNode);
96// if (recipe instanceof TypeInputRecipe) {
97// final Object typeKey = ((TypeInputRecipe) recipe).getTypeKey();
98//
99// if (recipe instanceof UnaryInputRecipe) {
100// unaryRoots.put(typeKey, freshAddress);
101// new EntityFeeder(freshAddress, this, typeKey).feed();
102//// if (typeObject != null && generalizationQueryDirection == GeneralizationQueryDirection.BOTH) {
103//// Collection<? extends Object> subTypes = context.enumerateDirectUnarySubtypes(typeObject);
104////
105//// for (Object subType : subTypes) {
106//// Address<? extends Tunnel> subRoot = accessUnaryRoot(subType);
107//// network.connectRemoteNodes(subRoot, tn, true);
108//// }
109//// }
110// } else if (recipe instanceof BinaryInputRecipe) {
111// binaryEdgeRoots.put(typeKey, freshAddress);
112// externalInputRoots.put(rowKey, columnKey, freshAddress);
113// new ReferenceFeeder(freshAddress, this, typeKey).feed();
114// // if (typeObject != null && generalizationQueryDirection == GeneralizationQueryDirection.BOTH) {
115// // Collection<? extends Object> subTypes = context.enumerateDirectTernaryEdgeSubtypes(typeObject);
116// //
117// // for (Object subType : subTypes) {
118// // Address<? extends Tunnel> subRoot = accessTernaryEdgeRoot(subType);
119// // network.connectRemoteNodes(subRoot, tn, true);
120// // }
121// // }
122// }
123//
124//
125// }
126
127 }
128
129// /**
130// * fetches the entity Root node under specified label; returns null if it doesn't exist yet
131// */
132// public Address<? extends Tunnel> getUnaryRoot(Object label) {
133// return unaryRoots.get(label);
134// }
135//
136// public Collection<Address<? extends Tunnel>> getAllUnaryRoots() {
137// return unaryRoots.values();
138// }
139//
140// /**
141// * fetches the relation Root node under specified label; returns null if it doesn't exist yet
142// */
143// public Address<? extends Tunnel> getTernaryEdgeRoot(Object label) {
144// return ternaryEdgeRoots.get(label);
145// }
146//
147// public Collection<Address<? extends Tunnel>> getAllTernaryEdgeRoots() {
148// return ternaryEdgeRoots.values();
149// }
150//
151// /**
152// * fetches the reference Root node under specified label; returns null if it doesn't exist yet
153// */
154// public Address<? extends Tunnel> getBinaryEdgeRoot(Object label) {
155// return binaryEdgeRoots.get(label);
156// }
157//
158// public Collection<Address<? extends Tunnel>> getAllBinaryEdgeRoots() {
159// return binaryEdgeRoots.values();
160// }
161//
162//
163// public Address<? extends Tunnel> getContainmentRoot() {
164// return containmentRoot;
165// }
166//
167//
168// public Address<? extends Supplier> getContainmentTransitiveRoot() {
169// return containmentTransitiveRoot;
170// }
171//
172//
173// public Address<? extends Tunnel> getInstantiationRoot() {
174// return instantiationRoot;
175// }
176//
177//
178// public Address<? extends Supplier> getInstantiationTransitiveRoot() {
179// return instantiationTransitiveRoot;
180// }
181//
182//
183// public Address<? extends Tunnel> getGeneralizationRoot() {
184// return generalizationRoot;
185// }
186
187
188 public Stream<Address<ExternalInputEnumeratorNode>> getAllExternalInputNodes() {
189 return externalInputRoots.values().stream().flatMap(map -> map.values().stream());
190 }
191 public Collection<Address<ExternalInputEnumeratorNode>> getAllExternalInputNodesForKey(IInputKey inputKey) {
192 return externalInputRoots.getOrDefault(inputKey, Collections.emptyMap()).values();
193 }
194 public Address<ExternalInputEnumeratorNode> getExternalInputNodeForKeyUnseeded(IInputKey inputKey) {
195 return externalInputRoots.getOrDefault(inputKey, Collections.emptyMap()).get(nopSeed(inputKey));
196 }
197 public Address<ExternalInputEnumeratorNode> getExternalInputNode(IInputKey inputKey, Tuple seed) {
198 if (seed == null) seed = nopSeed(inputKey);
199 return externalInputRoots.getOrDefault(inputKey, Collections.emptyMap()).get(seed);
200 }
201
202
203 Tuple nopSeed(IInputKey inputKey) {
204 return Tuples.flatTupleOf(new Object[inputKey.getArity()]);
205 }
206
207
208}