diff options
2 files changed, 249 insertions, 163 deletions
diff --git a/language-to-store/src/main/java/tools/refinery/language/mapping/PartialModelMapper.java b/language-to-store/src/main/java/tools/refinery/language/mapping/PartialModelMapper.java index ba32921a..1593a237 100644 --- a/language-to-store/src/main/java/tools/refinery/language/mapping/PartialModelMapper.java +++ b/language-to-store/src/main/java/tools/refinery/language/mapping/PartialModelMapper.java | |||
@@ -27,117 +27,111 @@ import tools.refinery.store.model.Tuple; | |||
27 | import tools.refinery.store.model.representation.Relation; | 27 | import tools.refinery.store.model.representation.Relation; |
28 | import tools.refinery.store.model.representation.TruthValue; | 28 | import tools.refinery.store.model.representation.TruthValue; |
29 | 29 | ||
30 | |||
31 | public class PartialModelMapper { | 30 | public class PartialModelMapper { |
32 | public PartialModelMapperDTO transformProblem(Problem problem) throws PartialModelMapperException { | 31 | public PartialModelMapperDTO transformProblem(Problem problem) throws PartialModelMapperException { |
33 | //Defining an integer in order to assign different values to all the nodes | 32 | // Defining an integer in order to assign different values to all the nodes |
34 | int[] nodeIter = new int[] {0}; | 33 | int[] nodeIter = new int[] { 0 }; |
35 | 34 | ||
36 | //Getting the relations and the nodes from the given problem | 35 | // Getting the relations and the nodes from the given problem |
37 | PartialModelMapperDTO pmmDTO = initTransform(problem, nodeIter); | 36 | PartialModelMapperDTO pmmDTO = initTransform(problem, nodeIter); |
38 | 37 | ||
39 | //Getting the relations and the nodes from the built in problem | 38 | // Getting the relations and the nodes from the built in problem |
40 | Optional<Problem> builtinProblem = ProblemUtil.getBuiltInLibrary(problem); | 39 | Optional<Problem> builtinProblem = ProblemUtil.getBuiltInLibrary(problem); |
41 | if (builtinProblem.isEmpty()) throw new PartialModelMapperException("builtin.problem not found"); | 40 | if (builtinProblem.isEmpty()) |
41 | throw new PartialModelMapperException("builtin.problem not found"); | ||
42 | PartialModelMapperDTO builtinProblemDTO = initTransform(builtinProblem.get(), nodeIter); | 42 | PartialModelMapperDTO builtinProblemDTO = initTransform(builtinProblem.get(), nodeIter); |
43 | 43 | ||
44 | //Merging the relation and the nodes from the given problem and from the built in problem | 44 | // Merging the relation and the nodes from the given problem and from the built |
45 | // in problem | ||
45 | pmmDTO.getRelationMap().putAll(builtinProblemDTO.getRelationMap()); | 46 | pmmDTO.getRelationMap().putAll(builtinProblemDTO.getRelationMap()); |
46 | pmmDTO.getNodeMap().putAll(builtinProblemDTO.getNodeMap()); | 47 | pmmDTO.getNodeMap().putAll(builtinProblemDTO.getNodeMap()); |
47 | pmmDTO.getEnumNodeMap().putAll(builtinProblemDTO.getEnumNodeMap()); | 48 | pmmDTO.getEnumNodeMap().putAll(builtinProblemDTO.getEnumNodeMap()); |
48 | pmmDTO.getNewNodeMap().putAll(builtinProblemDTO.getNewNodeMap()); | 49 | pmmDTO.getNewNodeMap().putAll(builtinProblemDTO.getNewNodeMap()); |
49 | pmmDTO.getUniqueNodeMap().putAll(builtinProblemDTO.getUniqueNodeMap()); | 50 | pmmDTO.getUniqueNodeMap().putAll(builtinProblemDTO.getUniqueNodeMap()); |
50 | 51 | ||
51 | //Definition of store and model | 52 | // Definition of store and model |
52 | ModelStore store = new ModelStoreImpl(new HashSet<>(pmmDTO.getRelationMap().values())); | 53 | ModelStore store = new ModelStoreImpl(new HashSet<>(pmmDTO.getRelationMap().values())); |
53 | Model model = store.createModel(); | 54 | Model model = store.createModel(); |
54 | pmmDTO.setModel(model); | 55 | pmmDTO.setModel(model); |
55 | 56 | ||
56 | //Collecting all the nodes in one map | 57 | // Collecting all the nodes in one map |
57 | Map<Node,Integer> allNodesMap = mergeNodeMaps(pmmDTO.getEnumNodeMap(), | 58 | Map<Node, Integer> allNodesMap = mergeNodeMaps(pmmDTO.getEnumNodeMap(), pmmDTO.getUniqueNodeMap(), |
58 | pmmDTO.getUniqueNodeMap(), | 59 | pmmDTO.getNewNodeMap(), pmmDTO.getNodeMap()); |
59 | pmmDTO.getNewNodeMap(), | 60 | |
60 | pmmDTO.getNodeMap()); | 61 | // Filling up the relations with unknown truth values |
61 | |||
62 | //Filling up the relations with unknown truth values | ||
63 | for (tools.refinery.language.model.problem.Relation relation : pmmDTO.getRelationMap().keySet()) { | 62 | for (tools.refinery.language.model.problem.Relation relation : pmmDTO.getRelationMap().keySet()) { |
64 | if(!(relation instanceof PredicateDefinition pd && pd.isError())) { | 63 | if (!(relation instanceof PredicateDefinition pd && pd.isError())) { |
65 | Relation<TruthValue> r = pmmDTO.getRelationMap().get(relation); | 64 | Relation<TruthValue> r = pmmDTO.getRelationMap().get(relation); |
66 | if(r.getArity() == 1) | 65 | if (r.getArity() == 1) |
67 | for(Integer i : allNodesMap.values()) { | 66 | for (Integer i : allNodesMap.values()) { |
68 | pmmDTO.getModel().put(r, Tuple.of(i), TruthValue.UNKNOWN); | 67 | pmmDTO.getModel().put(r, Tuple.of(i), TruthValue.UNKNOWN); |
69 | } | ||
70 | else if(r.getArity() == 2) | ||
71 | for(Integer i : allNodesMap.values()) { | ||
72 | for (Integer j : allNodesMap.values()) { | ||
73 | pmmDTO.getModel().put(r, Tuple.of(i,j), TruthValue.UNKNOWN); | ||
74 | } | 68 | } |
75 | } | 69 | else if (r.getArity() == 2) |
76 | else throw new PartialModelMapperException("Relation with arity above 2 is not supported"); | 70 | for (Integer i : allNodesMap.values()) { |
71 | for (Integer j : allNodesMap.values()) { | ||
72 | pmmDTO.getModel().put(r, Tuple.of(i, j), TruthValue.UNKNOWN); | ||
73 | } | ||
74 | } | ||
75 | else | ||
76 | throw new PartialModelMapperException("Relation with arity above 2 is not supported"); | ||
77 | } | 77 | } |
78 | } | 78 | } |
79 | 79 | ||
80 | //Filling up the exists | 80 | // Filling up the exists |
81 | tools.refinery.language.model.problem.Relation existsRelation = findingRelationInDTO(builtinProblemDTO, "exists", | 81 | tools.refinery.language.model.problem.Relation existsRelation = findingRelationInDTO(builtinProblemDTO, |
82 | "The exists not found in built in problem"); | 82 | "exists", "The exists not found in built in problem"); |
83 | for (Node n : allNodesMap.keySet()) { | 83 | for (Node n : allNodesMap.keySet()) { |
84 | if(pmmDTO.getNewNodeMap().containsKey(n)) { | 84 | if (pmmDTO.getNewNodeMap().containsKey(n)) { |
85 | pmmDTO.getModel().put(builtinProblemDTO.getRelationMap().get(existsRelation), | 85 | pmmDTO.getModel().put(builtinProblemDTO.getRelationMap().get(existsRelation), |
86 | Tuple.of(allNodesMap.get(n)), | 86 | Tuple.of(allNodesMap.get(n)), TruthValue.UNKNOWN); |
87 | TruthValue.UNKNOWN); | 87 | } else { |
88 | } | ||
89 | else { | ||
90 | pmmDTO.getModel().put(builtinProblemDTO.getRelationMap().get(existsRelation), | 88 | pmmDTO.getModel().put(builtinProblemDTO.getRelationMap().get(existsRelation), |
91 | Tuple.of(allNodesMap.get(n)), | 89 | Tuple.of(allNodesMap.get(n)), TruthValue.TRUE); |
92 | TruthValue.TRUE); | ||
93 | } | 90 | } |
94 | } | 91 | } |
95 | 92 | ||
96 | //Filling up the equals | 93 | // Filling up the equals |
97 | tools.refinery.language.model.problem.Relation equalsRelation = findingRelationInDTO(builtinProblemDTO, "equals", | 94 | tools.refinery.language.model.problem.Relation equalsRelation = findingRelationInDTO(builtinProblemDTO, |
98 | "The equals not found in built in problem"); | 95 | "equals", "The equals not found in built in problem"); |
99 | for (Node n1 : allNodesMap.keySet()) { | 96 | for (Node n1 : allNodesMap.keySet()) { |
100 | for(Node n2 : allNodesMap.keySet()) { | 97 | for (Node n2 : allNodesMap.keySet()) { |
101 | if(n1.equals(n2)) { | 98 | if (n1.equals(n2)) { |
102 | if(pmmDTO.getNewNodeMap().containsKey(n1)) { | 99 | if (pmmDTO.getNewNodeMap().containsKey(n1)) { |
103 | pmmDTO.getModel().put(builtinProblemDTO.getRelationMap().get(equalsRelation), | 100 | pmmDTO.getModel().put(builtinProblemDTO.getRelationMap().get(equalsRelation), |
104 | Tuple.of(allNodesMap.get(n1),allNodesMap.get(n2)), | 101 | Tuple.of(allNodesMap.get(n1), allNodesMap.get(n2)), TruthValue.UNKNOWN); |
105 | TruthValue.UNKNOWN); | 102 | } else { |
106 | } | ||
107 | else { | ||
108 | pmmDTO.getModel().put(builtinProblemDTO.getRelationMap().get(equalsRelation), | 103 | pmmDTO.getModel().put(builtinProblemDTO.getRelationMap().get(equalsRelation), |
109 | Tuple.of(allNodesMap.get(n1),allNodesMap.get(n2)), | 104 | Tuple.of(allNodesMap.get(n1), allNodesMap.get(n2)), TruthValue.TRUE); |
110 | TruthValue.TRUE); | ||
111 | } | 105 | } |
112 | } | 106 | } else { |
113 | else { | ||
114 | pmmDTO.getModel().put(builtinProblemDTO.getRelationMap().get(equalsRelation), | 107 | pmmDTO.getModel().put(builtinProblemDTO.getRelationMap().get(equalsRelation), |
115 | Tuple.of(allNodesMap.get(n1),allNodesMap.get(n2)), | 108 | Tuple.of(allNodesMap.get(n1), allNodesMap.get(n2)), TruthValue.FALSE); |
116 | TruthValue.FALSE); | ||
117 | } | 109 | } |
118 | } | 110 | } |
119 | } | 111 | } |
120 | 112 | ||
121 | //Transforming the assertions | 113 | // Transforming the assertions |
122 | processAssertions(problem, pmmDTO, allNodesMap); | 114 | processAssertions(problem, pmmDTO, allNodesMap); |
123 | processAssertions(builtinProblem.get(), pmmDTO, allNodesMap); | 115 | processAssertions(builtinProblem.get(), pmmDTO, allNodesMap); |
124 | 116 | ||
125 | return pmmDTO; | 117 | return pmmDTO; |
126 | } | 118 | } |
127 | 119 | ||
128 | //Searches for and gives back a relation in a PartialModelMapperDTO | 120 | // Searches for and gives back a relation in a PartialModelMapperDTO |
129 | private tools.refinery.language.model.problem.Relation findingRelationInDTO(PartialModelMapperDTO partialModelMapperDTO, String searchedRelation, String errorText) | 121 | private tools.refinery.language.model.problem.Relation findingRelationInDTO( |
122 | PartialModelMapperDTO partialModelMapperDTO, String searchedRelation, String errorText) | ||
130 | throws PartialModelMapperException { | 123 | throws PartialModelMapperException { |
131 | for (tools.refinery.language.model.problem.Relation r : partialModelMapperDTO.getRelationMap().keySet()) { | 124 | for (tools.refinery.language.model.problem.Relation r : partialModelMapperDTO.getRelationMap().keySet()) { |
132 | if (searchedRelation.equals(r.getName())) return r; | 125 | if (searchedRelation.equals(r.getName())) |
126 | return r; | ||
133 | } | 127 | } |
134 | throw new PartialModelMapperException(errorText); | 128 | throw new PartialModelMapperException(errorText); |
135 | } | 129 | } |
136 | 130 | ||
137 | //Processing assertions and placing them in the model | 131 | // Processing assertions and placing them in the model |
138 | private void processAssertions(Problem problem, PartialModelMapperDTO pmmDTO, Map<Node, Integer> allNodesMap) { | 132 | private void processAssertions(Problem problem, PartialModelMapperDTO pmmDTO, Map<Node, Integer> allNodesMap) { |
139 | for(Statement s : problem.getStatements()) { | 133 | for (Statement s : problem.getStatements()) { |
140 | if(s instanceof Assertion assertion) { | 134 | if (s instanceof Assertion assertion) { |
141 | Relation<TruthValue> r1 = pmmDTO.getRelationMap().get(assertion.getRelation()); | 135 | Relation<TruthValue> r1 = pmmDTO.getRelationMap().get(assertion.getRelation()); |
142 | int i = 0; | 136 | int i = 0; |
143 | int[] integers = new int[assertion.getArguments().size()]; | 137 | int[] integers = new int[assertion.getArguments().size()]; |
@@ -148,76 +142,69 @@ public class PartialModelMapper { | |||
148 | } | 142 | } |
149 | } | 143 | } |
150 | pmmDTO.getModel().put(r1, Tuple.of(integers), logicValueToTruthValue(assertion.getValue())); | 144 | pmmDTO.getModel().put(r1, Tuple.of(integers), logicValueToTruthValue(assertion.getValue())); |
151 | } | 145 | } else if (s instanceof ClassDeclaration cd) { |
152 | else if (s instanceof ClassDeclaration cd) { | 146 | if (!cd.isAbstract()) |
153 | if(!cd.isAbstract()) | 147 | pmmDTO.getModel().put(pmmDTO.getRelationMap().get(cd), |
154 | pmmDTO.getModel().put(pmmDTO.getRelationMap().get(cd), | 148 | Tuple.of(pmmDTO.getNewNodeMap().get(cd.getNewNode())), TruthValue.TRUE); |
155 | Tuple.of(pmmDTO.getNewNodeMap().get(cd.getNewNode())), | 149 | } else if (s instanceof EnumDeclaration ed) { |
156 | TruthValue.TRUE); | ||
157 | } | ||
158 | else if (s instanceof EnumDeclaration ed) { | ||
159 | for (Node n : ed.getLiterals()) { | 150 | for (Node n : ed.getLiterals()) { |
160 | pmmDTO.getModel().put(pmmDTO.getRelationMap().get(ed), | 151 | pmmDTO.getModel().put(pmmDTO.getRelationMap().get(ed), Tuple.of(pmmDTO.getEnumNodeMap().get(n)), |
161 | Tuple.of(pmmDTO.getEnumNodeMap().get(n)), | 152 | TruthValue.TRUE); |
162 | TruthValue.TRUE); | ||
163 | } | 153 | } |
164 | } | 154 | } |
165 | } | 155 | } |
166 | } | 156 | } |
167 | 157 | ||
168 | //Getting the relations and nodes from the problem | 158 | // Getting the relations and nodes from the problem |
169 | private PartialModelMapperDTO initTransform(Problem problem, int[] nodeIter) { | 159 | private PartialModelMapperDTO initTransform(Problem problem, int[] nodeIter) { |
170 | //Defining needed Maps | 160 | // Defining needed Maps |
171 | Map<tools.refinery.language.model.problem.Relation, Relation<TruthValue>> relationMap = new HashMap<>(); | 161 | Map<tools.refinery.language.model.problem.Relation, Relation<TruthValue>> relationMap = new HashMap<>(); |
172 | Map<Node, Integer> enumNodeMap = new HashMap<>(); | 162 | Map<Node, Integer> enumNodeMap = new HashMap<>(); |
173 | Map<Node, Integer> uniqueNodeMap = new HashMap<>(); | 163 | Map<Node, Integer> uniqueNodeMap = new HashMap<>(); |
174 | Map<Node, Integer> newNodeMap = new HashMap<>(); | 164 | Map<Node, Integer> newNodeMap = new HashMap<>(); |
175 | 165 | ||
176 | //Definition of Relations, filling up the enumNodeMap, uniqueNodeMap, newNodeMap | 166 | // Definition of Relations, filling up the enumNodeMap, uniqueNodeMap, |
167 | // newNodeMap | ||
177 | EList<Statement> statements = problem.getStatements(); | 168 | EList<Statement> statements = problem.getStatements(); |
178 | for (Statement s : statements) { | 169 | for (Statement s : statements) { |
179 | if (s instanceof ClassDeclaration cd) { | 170 | if (s instanceof ClassDeclaration cd) { |
180 | Relation<TruthValue> r1 = new Relation<>(cd.getName(), 1, TruthValue.FALSE); | 171 | Relation<TruthValue> r1 = new Relation<>(cd.getName(), 1, TruthValue.FALSE); |
181 | relationMap.put(cd, r1); | 172 | relationMap.put(cd, r1); |
182 | if(!cd.isAbstract()) newNodeMap.put(cd.getNewNode(), nodeIter[0]++); | 173 | if (!cd.isAbstract()) |
174 | newNodeMap.put(cd.getNewNode(), nodeIter[0]++); | ||
183 | EList<ReferenceDeclaration> refDeclList = cd.getReferenceDeclarations(); | 175 | EList<ReferenceDeclaration> refDeclList = cd.getReferenceDeclarations(); |
184 | for (ReferenceDeclaration refDec : refDeclList) { | 176 | for (ReferenceDeclaration refDec : refDeclList) { |
185 | Relation<TruthValue> r2 = new Relation<>(refDec.getName(), 2, TruthValue.FALSE); | 177 | Relation<TruthValue> r2 = new Relation<>(refDec.getName(), 2, TruthValue.FALSE); |
186 | relationMap.put(refDec, r2); | 178 | relationMap.put(refDec, r2); |
187 | } | 179 | } |
188 | } | 180 | } else if (s instanceof EnumDeclaration ed) { |
189 | else if (s instanceof EnumDeclaration ed) { | ||
190 | Relation<TruthValue> r = new Relation<>(ed.getName(), 1, TruthValue.FALSE); | 181 | Relation<TruthValue> r = new Relation<>(ed.getName(), 1, TruthValue.FALSE); |
191 | relationMap.put(ed, r); | 182 | relationMap.put(ed, r); |
192 | for (Node n : ed.getLiterals()) { | 183 | for (Node n : ed.getLiterals()) { |
193 | enumNodeMap.put(n, nodeIter[0]++); | 184 | enumNodeMap.put(n, nodeIter[0]++); |
194 | } | 185 | } |
195 | } | 186 | } else if (s instanceof UniqueDeclaration ud) { |
196 | else if (s instanceof UniqueDeclaration ud) { | ||
197 | for (Node n : ud.getNodes()) { | 187 | for (Node n : ud.getNodes()) { |
198 | uniqueNodeMap.put(n, nodeIter[0]++); | 188 | uniqueNodeMap.put(n, nodeIter[0]++); |
199 | } | 189 | } |
200 | } | 190 | } else if (s instanceof PredicateDefinition pd) { |
201 | else if (s instanceof PredicateDefinition pd) { | ||
202 | Relation<TruthValue> r = new Relation<>(pd.getName(), 1, TruthValue.FALSE); | 191 | Relation<TruthValue> r = new Relation<>(pd.getName(), 1, TruthValue.FALSE); |
203 | relationMap.put(pd, r); | 192 | relationMap.put(pd, r); |
204 | } | 193 | } |
205 | } | 194 | } |
206 | 195 | ||
207 | //Filling the nodeMap up | 196 | // Filling the nodeMap up |
208 | Map<Node, Integer> nodeMap = new HashMap<>(); | 197 | Map<Node, Integer> nodeMap = new HashMap<>(); |
209 | for(Node n : problem.getNodes()) { | 198 | for (Node n : problem.getNodes()) { |
210 | nodeMap.put(n, nodeIter[0]++); | 199 | nodeMap.put(n, nodeIter[0]++); |
211 | } | 200 | } |
212 | 201 | ||
213 | return new PartialModelMapperDTO(null,relationMap,nodeMap,enumNodeMap,uniqueNodeMap,newNodeMap); | 202 | return new PartialModelMapperDTO(null, relationMap, nodeMap, enumNodeMap, uniqueNodeMap, newNodeMap); |
214 | } | 203 | } |
215 | 204 | ||
216 | //Merging the maps of nodes into one map | 205 | // Merging the maps of nodes into one map |
217 | private Map<Node, Integer> mergeNodeMaps(Map<Node, Integer> enumNodeMap, | 206 | private Map<Node, Integer> mergeNodeMaps(Map<Node, Integer> enumNodeMap, Map<Node, Integer> uniqueNodeMap, |
218 | Map<Node, Integer> uniqueNodeMap, | 207 | Map<Node, Integer> newNodeMap, Map<Node, Integer> nodeMap) { |
219 | Map<Node, Integer> newNodeMap, | ||
220 | Map<Node, Integer> nodeMap) { | ||
221 | Map<Node, Integer> out = new HashMap<>(); | 208 | Map<Node, Integer> out = new HashMap<>(); |
222 | out.putAll(enumNodeMap); | 209 | out.putAll(enumNodeMap); |
223 | out.putAll(uniqueNodeMap); | 210 | out.putAll(uniqueNodeMap); |
@@ -226,19 +213,25 @@ public class PartialModelMapper { | |||
226 | return out; | 213 | return out; |
227 | } | 214 | } |
228 | 215 | ||
229 | //Exchange method from LogicValue to TruthValue | 216 | // Exchange method from LogicValue to TruthValue |
230 | private TruthValue logicValueToTruthValue(LogicValue value) { | 217 | private TruthValue logicValueToTruthValue(LogicValue value) { |
231 | if(value.equals(LogicValue.TRUE)) return TruthValue.TRUE; | 218 | if (value.equals(LogicValue.TRUE)) |
232 | else if(value.equals(LogicValue.FALSE)) return TruthValue.FALSE; | 219 | return TruthValue.TRUE; |
233 | else if(value.equals(LogicValue.UNKNOWN)) return TruthValue.UNKNOWN; | 220 | else if (value.equals(LogicValue.FALSE)) |
234 | else return TruthValue.ERROR; | 221 | return TruthValue.FALSE; |
222 | else if (value.equals(LogicValue.UNKNOWN)) | ||
223 | return TruthValue.UNKNOWN; | ||
224 | else | ||
225 | return TruthValue.ERROR; | ||
235 | } | 226 | } |
236 | 227 | ||
237 | public class PartialModelMapperException extends Exception{ | 228 | public class PartialModelMapperException extends Exception { |
238 | private static final long serialVersionUID = 1L; | 229 | private static final long serialVersionUID = 1L; |
230 | |||
239 | public PartialModelMapperException(String errorText) { | 231 | public PartialModelMapperException(String errorText) { |
240 | super(errorText); | 232 | super(errorText); |
241 | } | 233 | } |
234 | |||
242 | public PartialModelMapperException() { | 235 | public PartialModelMapperException() { |
243 | super(); | 236 | super(); |
244 | } | 237 | } |
diff --git a/language-to-store/src/test/java/tools/refinery/language/mapping/tests/PartialModelMapperTest.xtend b/language-to-store/src/test/java/tools/refinery/language/mapping/tests/PartialModelMapperTest.xtend index dcdea332..52b89bae 100644 --- a/language-to-store/src/test/java/tools/refinery/language/mapping/tests/PartialModelMapperTest.xtend +++ b/language-to-store/src/test/java/tools/refinery/language/mapping/tests/PartialModelMapperTest.xtend | |||
@@ -59,9 +59,9 @@ class PartialModelMapperTest { | |||
59 | val a = problem.node("a") | 59 | val a = problem.node("a") |
60 | val b = problem.node("b") | 60 | val b = problem.node("b") |
61 | 61 | ||
62 | assertTrue(model.getDataRepresentations().contains(relationMap.get(person))); | 62 | assertTrue(model.getDataRepresentations().contains(relationMap.get(person))) |
63 | assertTrue(model.getDataRepresentations().contains(relationMap.get(friend))); | 63 | assertTrue(model.getDataRepresentations().contains(relationMap.get(friend))) |
64 | assertTrue(model.get(relationMap.get(friend), Tuple.of(nodeMap.get(a),nodeMap.get(b))).equals(TruthValue.TRUE)); | 64 | assertTrue(model.get(relationMap.get(friend), Tuple.of(nodeMap.get(a),nodeMap.get(b))).equals(TruthValue.TRUE)) |
65 | } | 65 | } |
66 | 66 | ||
67 | //Testing the class | 67 | //Testing the class |
@@ -87,10 +87,10 @@ class PartialModelMapperTest { | |||
87 | val friend = problem.findClass("Person").reference("friend") | 87 | val friend = problem.findClass("Person").reference("friend") |
88 | val a = problem.node("a") | 88 | val a = problem.node("a") |
89 | 89 | ||
90 | assertTrue(model.getDataRepresentations().contains(relationMap.get(person))); | 90 | assertTrue(model.getDataRepresentations().contains(relationMap.get(person))) |
91 | assertTrue(model.getDataRepresentations().contains(relationMap.get(friend))); | 91 | assertTrue(model.getDataRepresentations().contains(relationMap.get(friend))) |
92 | 92 | ||
93 | assertTrue(model.get(relationMap.get(person), Tuple.of(nodeMap.get(a))).equals(TruthValue.TRUE)); | 93 | assertTrue(model.get(relationMap.get(person), Tuple.of(nodeMap.get(a))).equals(TruthValue.TRUE)) |
94 | } | 94 | } |
95 | 95 | ||
96 | //Testing the equals and exists from the built in problem | 96 | //Testing the equals and exists from the built in problem |
@@ -103,7 +103,7 @@ class PartialModelMapperTest { | |||
103 | class Person. | 103 | class Person. |
104 | ''') | 104 | ''') |
105 | EcoreUtil.resolveAll(problem) | 105 | EcoreUtil.resolveAll(problem) |
106 | val builtin = problem.builtin; | 106 | val builtin = problem.builtin |
107 | 107 | ||
108 | val modelAndMaps = mapper.transformProblem(problem) | 108 | val modelAndMaps = mapper.transformProblem(problem) |
109 | assertThat(modelAndMaps, notNullValue()) | 109 | assertThat(modelAndMaps, notNullValue()) |
@@ -148,7 +148,7 @@ class PartialModelMapperTest { | |||
148 | Person(a). | 148 | Person(a). |
149 | Person(b). | 149 | Person(b). |
150 | ''') | 150 | ''') |
151 | val builtin = problem.builtin; | 151 | val builtin = problem.builtin |
152 | EcoreUtil.resolveAll(problem) | 152 | EcoreUtil.resolveAll(problem) |
153 | 153 | ||
154 | val modelAndMaps = mapper.transformProblem(problem) | 154 | val modelAndMaps = mapper.transformProblem(problem) |
@@ -166,23 +166,23 @@ class PartialModelMapperTest { | |||
166 | val exists = builtin.pred("exists") | 166 | val exists = builtin.pred("exists") |
167 | val equals = builtin.findClass("node").reference("equals") | 167 | val equals = builtin.findClass("node").reference("equals") |
168 | 168 | ||
169 | assertTrue(model.getDataRepresentations().contains(relationMap.get(Person))); | 169 | assertTrue(model.getDataRepresentations().contains(relationMap.get(Person))) |
170 | assertTrue(model.getDataRepresentations().contains(relationMap.get(exists))); | 170 | assertTrue(model.getDataRepresentations().contains(relationMap.get(exists))) |
171 | assertTrue(model.getDataRepresentations().contains(relationMap.get(equals))); | 171 | assertTrue(model.getDataRepresentations().contains(relationMap.get(equals))) |
172 | 172 | ||
173 | assertTrue(model.get(relationMap.get(exists), Tuple.of(nodeMap.get(a))).equals(TruthValue.TRUE)); | 173 | assertTrue(model.get(relationMap.get(exists), Tuple.of(nodeMap.get(a))).equals(TruthValue.TRUE)) |
174 | assertTrue(model.get(relationMap.get(exists), Tuple.of(nodeMap.get(b))).equals(TruthValue.TRUE)); | 174 | assertTrue(model.get(relationMap.get(exists), Tuple.of(nodeMap.get(b))).equals(TruthValue.TRUE)) |
175 | assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(a), nodeMap.get(a))).equals(TruthValue.TRUE)); | 175 | assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(a), nodeMap.get(a))).equals(TruthValue.TRUE)) |
176 | assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(b), nodeMap.get(b))).equals(TruthValue.TRUE)); | 176 | assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(b), nodeMap.get(b))).equals(TruthValue.TRUE)) |
177 | assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(a), nodeMap.get(b))).equals(TruthValue.FALSE)); | 177 | assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(a), nodeMap.get(b))).equals(TruthValue.FALSE)) |
178 | assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(b), nodeMap.get(a))).equals(TruthValue.FALSE)); | 178 | assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(b), nodeMap.get(a))).equals(TruthValue.FALSE)) |
179 | 179 | ||
180 | assertTrue(model.get(relationMap.get(exists), Tuple.of(newNodeMap.get(PersonNew))).equals(TruthValue.UNKNOWN)); | 180 | assertTrue(model.get(relationMap.get(exists), Tuple.of(newNodeMap.get(PersonNew))).equals(TruthValue.UNKNOWN)) |
181 | assertTrue(model.get(relationMap.get(equals), Tuple.of(newNodeMap.get(PersonNew), newNodeMap.get(PersonNew))).equals(TruthValue.UNKNOWN)); | 181 | assertTrue(model.get(relationMap.get(equals), Tuple.of(newNodeMap.get(PersonNew), newNodeMap.get(PersonNew))).equals(TruthValue.UNKNOWN)) |
182 | assertTrue(model.get(relationMap.get(equals), Tuple.of(newNodeMap.get(PersonNew), nodeMap.get(a))).equals(TruthValue.FALSE)); | 182 | assertTrue(model.get(relationMap.get(equals), Tuple.of(newNodeMap.get(PersonNew), nodeMap.get(a))).equals(TruthValue.FALSE)) |
183 | assertTrue(model.get(relationMap.get(equals), Tuple.of(newNodeMap.get(PersonNew), nodeMap.get(b))).equals(TruthValue.FALSE)); | 183 | assertTrue(model.get(relationMap.get(equals), Tuple.of(newNodeMap.get(PersonNew), nodeMap.get(b))).equals(TruthValue.FALSE)) |
184 | assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(a), newNodeMap.get(PersonNew))).equals(TruthValue.FALSE)); | 184 | assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(a), newNodeMap.get(PersonNew))).equals(TruthValue.FALSE)) |
185 | assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(b), newNodeMap.get(PersonNew))).equals(TruthValue.FALSE)); | 185 | assertTrue(model.get(relationMap.get(equals), Tuple.of(nodeMap.get(b), newNodeMap.get(PersonNew))).equals(TruthValue.FALSE)) |
186 | } | 186 | } |
187 | 187 | ||
188 | //Testing the behavior of the newNodes | 188 | //Testing the behavior of the newNodes |
@@ -194,7 +194,7 @@ class PartialModelMapperTest { | |||
194 | ''') | 194 | ''') |
195 | EcoreUtil.resolveAll(problem) | 195 | EcoreUtil.resolveAll(problem) |
196 | 196 | ||
197 | val modelAndMaps = mapper.transformProblem(problem); | 197 | val modelAndMaps = mapper.transformProblem(problem) |
198 | assertThat(modelAndMaps, notNullValue()) | 198 | assertThat(modelAndMaps, notNullValue()) |
199 | 199 | ||
200 | val model = modelAndMaps.model | 200 | val model = modelAndMaps.model |
@@ -206,11 +206,11 @@ class PartialModelMapperTest { | |||
206 | val PersonNew = problem.findClass("Person").newNode | 206 | val PersonNew = problem.findClass("Person").newNode |
207 | 207 | ||
208 | 208 | ||
209 | assertTrue(model.getDataRepresentations().contains(relationMap.get(Person))); | 209 | assertTrue(model.getDataRepresentations().contains(relationMap.get(Person))) |
210 | assertTrue(model.getDataRepresentations().contains(relationMap.get(Family))); | 210 | assertTrue(model.getDataRepresentations().contains(relationMap.get(Family))) |
211 | 211 | ||
212 | assertTrue(newNodeMap.size.equals(4)) //3 from builtin.problem, 1 from Person | 212 | assertTrue(newNodeMap.size.equals(4)) //3 from builtin.problem, 1 from Person |
213 | assertTrue(model.get(relationMap.get(Person), Tuple.of(newNodeMap.get(PersonNew))).equals(TruthValue.TRUE)); | 213 | assertTrue(model.get(relationMap.get(Person), Tuple.of(newNodeMap.get(PersonNew))).equals(TruthValue.TRUE)) |
214 | } | 214 | } |
215 | 215 | ||
216 | //Testing the behavior of enumerations | 216 | //Testing the behavior of enumerations |
@@ -236,11 +236,11 @@ class PartialModelMapperTest { | |||
236 | val adult = problem.findEnum("TaxStatus").literal("adult") | 236 | val adult = problem.findEnum("TaxStatus").literal("adult") |
237 | val retired = problem.findEnum("TaxStatus").literal("retired") | 237 | val retired = problem.findEnum("TaxStatus").literal("retired") |
238 | 238 | ||
239 | assertTrue(model.getDataRepresentations().contains(relationMap.get(TaxStatus))); | 239 | assertTrue(model.getDataRepresentations().contains(relationMap.get(TaxStatus))) |
240 | assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(child))).equals(TruthValue.TRUE)); | 240 | assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(child))).equals(TruthValue.TRUE)) |
241 | assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(student))).equals(TruthValue.TRUE)); | 241 | assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(student))).equals(TruthValue.TRUE)) |
242 | assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(adult))).equals(TruthValue.TRUE)); | 242 | assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(adult))).equals(TruthValue.TRUE)) |
243 | assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(retired))).equals(TruthValue.TRUE)); | 243 | assertTrue(model.get(relationMap.get(TaxStatus), Tuple.of(enumNodeMap.get(retired))).equals(TruthValue.TRUE)) |
244 | } | 244 | } |
245 | 245 | ||
246 | //Testing the bool from the built in problem | 246 | //Testing the bool from the built in problem |
@@ -250,7 +250,7 @@ class PartialModelMapperTest { | |||
250 | class Person. | 250 | class Person. |
251 | ''') | 251 | ''') |
252 | EcoreUtil.resolveAll(problem) | 252 | EcoreUtil.resolveAll(problem) |
253 | val builtin = problem.builtin; | 253 | val builtin = problem.builtin |
254 | 254 | ||
255 | val modelAndMaps = mapper.transformProblem(problem) | 255 | val modelAndMaps = mapper.transformProblem(problem) |
256 | assertThat(modelAndMaps, notNullValue()) | 256 | assertThat(modelAndMaps, notNullValue()) |
@@ -263,9 +263,9 @@ class PartialModelMapperTest { | |||
263 | val trueEnum = builtin.findEnum("bool").literal("true") //Emiatt nem sikerül a teszt | 263 | val trueEnum = builtin.findEnum("bool").literal("true") //Emiatt nem sikerül a teszt |
264 | val falseEnum = builtin.findEnum("bool").literal("false") | 264 | val falseEnum = builtin.findEnum("bool").literal("false") |
265 | 265 | ||
266 | assertTrue(model.getDataRepresentations().contains(relationMap.get(bool))); | 266 | assertTrue(model.getDataRepresentations().contains(relationMap.get(bool))) |
267 | assertTrue(model.get(relationMap.get(bool), Tuple.of(enumNodeMap.get(trueEnum))).equals(TruthValue.TRUE)); | 267 | assertTrue(model.get(relationMap.get(bool), Tuple.of(enumNodeMap.get(trueEnum))).equals(TruthValue.TRUE)) |
268 | assertTrue(model.get(relationMap.get(bool), Tuple.of(enumNodeMap.get(falseEnum))).equals(TruthValue.TRUE)); | 268 | assertTrue(model.get(relationMap.get(bool), Tuple.of(enumNodeMap.get(falseEnum))).equals(TruthValue.TRUE)) |
269 | } | 269 | } |
270 | 270 | ||
271 | //Testing different aspects of the behavior | 271 | //Testing different aspects of the behavior |
@@ -325,21 +325,114 @@ class PartialModelMapperTest { | |||
325 | val family = problem.uniqueNode("family") | 325 | val family = problem.uniqueNode("family") |
326 | val adult = problem.findEnum("TaxStatus").literal("adult") | 326 | val adult = problem.findEnum("TaxStatus").literal("adult") |
327 | 327 | ||
328 | assertTrue(model.getDataRepresentations().contains(relationMap.get(Family))); | 328 | assertTrue(model.getDataRepresentations().contains(relationMap.get(Family))) |
329 | assertTrue(model.getDataRepresentations().contains(relationMap.get(members))); | 329 | assertTrue(model.getDataRepresentations().contains(relationMap.get(members))) |
330 | assertTrue(model.getDataRepresentations().contains(relationMap.get(Person))); | 330 | assertTrue(model.getDataRepresentations().contains(relationMap.get(Person))) |
331 | assertTrue(model.getDataRepresentations().contains(relationMap.get(children))); | 331 | assertTrue(model.getDataRepresentations().contains(relationMap.get(children))) |
332 | assertTrue(model.getDataRepresentations().contains(relationMap.get(parent))); | 332 | assertTrue(model.getDataRepresentations().contains(relationMap.get(parent))) |
333 | assertTrue(model.getDataRepresentations().contains(relationMap.get(taxStatus))); | 333 | assertTrue(model.getDataRepresentations().contains(relationMap.get(taxStatus))) |
334 | assertTrue(model.getDataRepresentations().contains(relationMap.get(TaxStatus))); | 334 | assertTrue(model.getDataRepresentations().contains(relationMap.get(TaxStatus))) |
335 | assertTrue(model.getDataRepresentations().contains(relationMap.get(invalidTaxStatus))); | 335 | assertTrue(model.getDataRepresentations().contains(relationMap.get(invalidTaxStatus))) |
336 | 336 | ||
337 | assertTrue(model.get(relationMap.get(Family), Tuple.of(uniqueNodeMap.get(family))).equals(TruthValue.TRUE)); | 337 | assertTrue(model.get(relationMap.get(Family), Tuple.of(uniqueNodeMap.get(family))).equals(TruthValue.TRUE)) |
338 | assertTrue(model.get(relationMap.get(members), Tuple.of(uniqueNodeMap.get(family),nodeMap.get(anne))).equals(TruthValue.TRUE)); | 338 | assertTrue(model.get(relationMap.get(members), Tuple.of(uniqueNodeMap.get(family),nodeMap.get(anne))).equals(TruthValue.TRUE)) |
339 | assertTrue(model.get(relationMap.get(members), Tuple.of(uniqueNodeMap.get(family),nodeMap.get(bob))).equals(TruthValue.TRUE)); | 339 | assertTrue(model.get(relationMap.get(members), Tuple.of(uniqueNodeMap.get(family),nodeMap.get(bob))).equals(TruthValue.TRUE)) |
340 | assertTrue(model.get(relationMap.get(members), Tuple.of(uniqueNodeMap.get(family),nodeMap.get(ciri))).equals(TruthValue.TRUE)); | 340 | assertTrue(model.get(relationMap.get(members), Tuple.of(uniqueNodeMap.get(family),nodeMap.get(ciri))).equals(TruthValue.TRUE)) |
341 | assertTrue(model.get(relationMap.get(children), Tuple.of(nodeMap.get(anne),nodeMap.get(ciri))).equals(TruthValue.TRUE)); | 341 | assertTrue(model.get(relationMap.get(children), Tuple.of(nodeMap.get(anne),nodeMap.get(ciri))).equals(TruthValue.TRUE)) |
342 | assertTrue(model.get(relationMap.get(children), Tuple.of(nodeMap.get(bob),nodeMap.get(ciri))).equals(TruthValue.UNKNOWN)); | 342 | assertTrue(model.get(relationMap.get(children), Tuple.of(nodeMap.get(bob),nodeMap.get(ciri))).equals(TruthValue.UNKNOWN)) |
343 | assertTrue(model.get(relationMap.get(taxStatus), Tuple.of(nodeMap.get(anne),enumNodeMap.get(adult))).equals(TruthValue.TRUE)); | 343 | assertTrue(model.get(relationMap.get(taxStatus), Tuple.of(nodeMap.get(anne),enumNodeMap.get(adult))).equals(TruthValue.TRUE)) |
344 | } | ||
345 | |||
346 | @Test | ||
347 | def void carCaseStudyTest(){ | ||
348 | val problem = parseHelper.parse(''' | ||
349 | abstract class DynamicComponent { | ||
350 | contains StaticComponent[1..1] placedOn | ||
351 | } | ||
352 | abstract class StaticComponent. | ||
353 | class Car extends DynamicComponent. | ||
354 | class Pedestrian extends DynamicComponent. | ||
355 | class Road extends StaticComponent { | ||
356 | contains LaneSegment[0..*] lanes | ||
357 | } | ||
358 | class LaneSegment extends StaticComponent { | ||
359 | Lane[0..*] adjacentLanes | ||
360 | Lane[0..*] sameDirLanes | ||
361 | } | ||
362 | |||
363 | Car(c1). | ||
364 | Car(c2). | ||
365 | Pedestrian(p1). | ||
366 | Road(r1). | ||
367 | LaneSegment(l1). | ||
368 | LaneSegment(l2). | ||
369 | LaneSegment(l3). | ||
370 | placedOn(c1,l1). | ||
371 | placedOn(c2,l2). | ||
372 | placedOn(p1,l3). | ||
373 | lanes(r1,l1). | ||
374 | lanes(r1,l2). | ||
375 | lanes(r1,l3). | ||
376 | adjacentLanes(l1,l2). | ||
377 | adjacentLanes(l2,l1). | ||
378 | sameDirLanes(l1,l3). | ||
379 | sameDirLanes(l3,l1). | ||
380 | ''') | ||
381 | EcoreUtil.resolveAll(problem) | ||
382 | |||
383 | val modelAndMaps = mapper.transformProblem(problem) | ||
384 | assertThat(modelAndMaps, notNullValue()) | ||
385 | |||
386 | val model = modelAndMaps.model | ||
387 | val relationMap = modelAndMaps.relationMap | ||
388 | val nodeMap = modelAndMaps.nodeMap | ||
389 | |||
390 | val DynamicComponent = problem.findClass("DynamicComponent") | ||
391 | val placedOn = problem.findClass("DynamicComponent").reference("placedOn") | ||
392 | val StaticComponent = problem.findClass("StaticComponent") | ||
393 | val Car = problem.findClass("Car") | ||
394 | val Pedestrian = problem.findClass("Pedestrian") | ||
395 | val Road = problem.findClass("Road") | ||
396 | val lanes = problem.findClass("Road").reference("lanes") | ||
397 | val LaneSegment = problem.findClass("LaneSegment") | ||
398 | val adjacentLanes = problem.findClass("LaneSegment").reference("adjacentLanes") | ||
399 | val sameDirLanes = problem.findClass("LaneSegment").reference("sameDirLanes") | ||
400 | |||
401 | val c1 = problem.node("c1") | ||
402 | val c2 = problem.node("c2") | ||
403 | val p1 = problem.node("p1") | ||
404 | val r1 = problem.node("r1") | ||
405 | val l1 = problem.node("l1") | ||
406 | val l2 = problem.node("l2") | ||
407 | val l3 = problem.node("l3") | ||
408 | |||
409 | assertTrue(model.getDataRepresentations().contains(relationMap.get(DynamicComponent))) | ||
410 | assertTrue(model.getDataRepresentations().contains(relationMap.get(placedOn))) | ||
411 | assertTrue(model.getDataRepresentations().contains(relationMap.get(StaticComponent))) | ||
412 | assertTrue(model.getDataRepresentations().contains(relationMap.get(Car))) | ||
413 | assertTrue(model.getDataRepresentations().contains(relationMap.get(Pedestrian))) | ||
414 | assertTrue(model.getDataRepresentations().contains(relationMap.get(Road))) | ||
415 | assertTrue(model.getDataRepresentations().contains(relationMap.get(lanes))) | ||
416 | assertTrue(model.getDataRepresentations().contains(relationMap.get(LaneSegment))) | ||
417 | assertTrue(model.getDataRepresentations().contains(relationMap.get(adjacentLanes))) | ||
418 | assertTrue(model.getDataRepresentations().contains(relationMap.get(sameDirLanes))) | ||
419 | |||
420 | assertTrue(model.get(relationMap.get(Car), Tuple.of(nodeMap.get(c1))).equals(TruthValue.TRUE)) | ||
421 | assertTrue(model.get(relationMap.get(Car), Tuple.of(nodeMap.get(c2))).equals(TruthValue.TRUE)) | ||
422 | assertTrue(model.get(relationMap.get(Pedestrian), Tuple.of(nodeMap.get(p1))).equals(TruthValue.TRUE)) | ||
423 | assertTrue(model.get(relationMap.get(Road), Tuple.of(nodeMap.get(r1))).equals(TruthValue.TRUE)) | ||
424 | assertTrue(model.get(relationMap.get(LaneSegment), Tuple.of(nodeMap.get(l1))).equals(TruthValue.TRUE)) | ||
425 | assertTrue(model.get(relationMap.get(LaneSegment), Tuple.of(nodeMap.get(l2))).equals(TruthValue.TRUE)) | ||
426 | assertTrue(model.get(relationMap.get(LaneSegment), Tuple.of(nodeMap.get(l3))).equals(TruthValue.TRUE)) | ||
427 | assertTrue(model.get(relationMap.get(placedOn), Tuple.of(nodeMap.get(c1),nodeMap.get(l1))).equals(TruthValue.TRUE)) | ||
428 | assertTrue(model.get(relationMap.get(placedOn), Tuple.of(nodeMap.get(c2),nodeMap.get(l2))).equals(TruthValue.TRUE)) | ||
429 | assertTrue(model.get(relationMap.get(placedOn), Tuple.of(nodeMap.get(p1),nodeMap.get(l3))).equals(TruthValue.TRUE)) | ||
430 | assertTrue(model.get(relationMap.get(lanes), Tuple.of(nodeMap.get(r1),nodeMap.get(l1))).equals(TruthValue.TRUE)) | ||
431 | assertTrue(model.get(relationMap.get(lanes), Tuple.of(nodeMap.get(r1),nodeMap.get(l2))).equals(TruthValue.TRUE)) | ||
432 | assertTrue(model.get(relationMap.get(lanes), Tuple.of(nodeMap.get(r1),nodeMap.get(l3))).equals(TruthValue.TRUE)) | ||
433 | assertTrue(model.get(relationMap.get(adjacentLanes), Tuple.of(nodeMap.get(l1),nodeMap.get(l2))).equals(TruthValue.TRUE)) | ||
434 | assertTrue(model.get(relationMap.get(adjacentLanes), Tuple.of(nodeMap.get(l2),nodeMap.get(l1))).equals(TruthValue.TRUE)) | ||
435 | assertTrue(model.get(relationMap.get(sameDirLanes), Tuple.of(nodeMap.get(l1),nodeMap.get(l3))).equals(TruthValue.TRUE)) | ||
436 | assertTrue(model.get(relationMap.get(sameDirLanes), Tuple.of(nodeMap.get(l3),nodeMap.get(l1))).equals(TruthValue.TRUE)) | ||
344 | } | 437 | } |
345 | } | 438 | } |