aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Márton Golej <golejmarci@gmail.com>2021-10-18 18:52:24 +0200
committerLibravatar Márton Golej <golejmarci@gmail.com>2021-10-18 18:52:24 +0200
commitc8c2550de1e5ceb8c06ddc53a6701cee0d940456 (patch)
tree3f76c10c6b48c0479719c0ff28fdcb87d3f2c1e5
parentCommments added, code cleanup: (diff)
downloadrefinery-c8c2550de1e5ceb8c06ddc53a6701cee0d940456.tar.gz
refinery-c8c2550de1e5ceb8c06ddc53a6701cee0d940456.tar.zst
refinery-c8c2550de1e5ceb8c06ddc53a6701cee0d940456.zip
nodeIter moved from private field inside the method
-rw-r--r--language-to-store/src/main/java/tools/refinery/language/mapping/PartialModelMapper.java23
1 files changed, 10 insertions, 13 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 53fa78e3..2ace27f4 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
@@ -29,20 +29,17 @@ import tools.refinery.store.model.representation.TruthValue;
29 29
30 30
31public class PartialModelMapper { 31public class PartialModelMapper {
32
33 private int nodeIter;
34 public PartialModelMapper() {
35 this.nodeIter = 0;
36 }
37
38 public PartialModelMapperDTO transformProblem(Problem problem) throws PartialModelMapperException { 32 public PartialModelMapperDTO transformProblem(Problem problem) throws PartialModelMapperException {
33 //Defining an integer in order to assign different values to all the nodes
34 int[] nodeIter = new int[] {0};
35
39 //Getting the relations and the nodes from the given problem 36 //Getting the relations and the nodes from the given problem
40 PartialModelMapperDTO pmmDTO = initTransform(problem); 37 PartialModelMapperDTO pmmDTO = initTransform(problem, nodeIter);
41 38
42 //Getting the relations and the nodes from the built in problem 39 //Getting the relations and the nodes from the built in problem
43 Optional<Problem> builtinProblem = ProblemUtil.getBuiltInLibrary(problem); 40 Optional<Problem> builtinProblem = ProblemUtil.getBuiltInLibrary(problem);
44 if (builtinProblem.isEmpty()) throw new PartialModelMapperException("builtin.problem not found"); 41 if (builtinProblem.isEmpty()) throw new PartialModelMapperException("builtin.problem not found");
45 PartialModelMapperDTO builtinProblemDTO = initTransform(builtinProblem.get()); 42 PartialModelMapperDTO builtinProblemDTO = initTransform(builtinProblem.get(), nodeIter);
46 43
47 //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 in problem
48 pmmDTO.getRelationMap().putAll(builtinProblemDTO.getRelationMap()); 45 pmmDTO.getRelationMap().putAll(builtinProblemDTO.getRelationMap());
@@ -171,7 +168,7 @@ public class PartialModelMapper {
171 } 168 }
172 169
173 //Getting the relations and nodes from the problem 170 //Getting the relations and nodes from the problem
174 public PartialModelMapperDTO initTransform(Problem problem) { 171 private PartialModelMapperDTO initTransform(Problem problem, int[] nodeIter) {
175 //Defining needed Maps 172 //Defining needed Maps
176 Map<tools.refinery.language.model.problem.Relation, Relation<TruthValue>> relationMap = new HashMap<>(); 173 Map<tools.refinery.language.model.problem.Relation, Relation<TruthValue>> relationMap = new HashMap<>();
177 Map<Node, Integer> enumNodeMap = new HashMap<>(); 174 Map<Node, Integer> enumNodeMap = new HashMap<>();
@@ -184,7 +181,7 @@ public class PartialModelMapper {
184 if (s instanceof ClassDeclaration cd) { 181 if (s instanceof ClassDeclaration cd) {
185 Relation<TruthValue> r1 = new Relation<>(cd.getName(), 1, TruthValue.FALSE); 182 Relation<TruthValue> r1 = new Relation<>(cd.getName(), 1, TruthValue.FALSE);
186 relationMap.put(cd, r1); 183 relationMap.put(cd, r1);
187 if(!cd.isAbstract()) newNodeMap.put(cd.getNewNode(), this.nodeIter++); 184 if(!cd.isAbstract()) newNodeMap.put(cd.getNewNode(), nodeIter[0]++);
188 EList<ReferenceDeclaration> refDeclList = cd.getReferenceDeclarations(); 185 EList<ReferenceDeclaration> refDeclList = cd.getReferenceDeclarations();
189 for (ReferenceDeclaration refDec : refDeclList) { 186 for (ReferenceDeclaration refDec : refDeclList) {
190 Relation<TruthValue> r2 = new Relation<>(refDec.getName(), 2, TruthValue.FALSE); 187 Relation<TruthValue> r2 = new Relation<>(refDec.getName(), 2, TruthValue.FALSE);
@@ -195,12 +192,12 @@ public class PartialModelMapper {
195 Relation<TruthValue> r = new Relation<>(ed.getName(), 1, TruthValue.FALSE); 192 Relation<TruthValue> r = new Relation<>(ed.getName(), 1, TruthValue.FALSE);
196 relationMap.put(ed, r); 193 relationMap.put(ed, r);
197 for (Node n : ed.getLiterals()) { 194 for (Node n : ed.getLiterals()) {
198 enumNodeMap.put(n, nodeIter++); 195 enumNodeMap.put(n, nodeIter[0]++);
199 } 196 }
200 } 197 }
201 else if (s instanceof UniqueDeclaration ud) { 198 else if (s instanceof UniqueDeclaration ud) {
202 for (Node n : ud.getNodes()) { 199 for (Node n : ud.getNodes()) {
203 uniqueNodeMap.put(n, this.nodeIter++); 200 uniqueNodeMap.put(n, nodeIter[0]++);
204 } 201 }
205 } 202 }
206 else if (s instanceof PredicateDefinition pd) { 203 else if (s instanceof PredicateDefinition pd) {
@@ -212,7 +209,7 @@ public class PartialModelMapper {
212 //Filling the nodeMap up 209 //Filling the nodeMap up
213 Map<Node, Integer> nodeMap = new HashMap<>(); 210 Map<Node, Integer> nodeMap = new HashMap<>();
214 for(Node n : problem.getNodes()) { 211 for(Node n : problem.getNodes()) {
215 nodeMap.put(n, this.nodeIter++); 212 nodeMap.put(n, nodeIter[0]++);
216 } 213 }
217 214
218 return new PartialModelMapperDTO(null,relationMap,nodeMap,enumNodeMap,uniqueNodeMap,newNodeMap); 215 return new PartialModelMapperDTO(null,relationMap,nodeMap,enumNodeMap,uniqueNodeMap,newNodeMap);