diff --git a/src/main/java/org/fujaba/graphengine/PatternEngine.java b/src/main/java/org/fujaba/graphengine/PatternEngine.java index 742519b..14c03ae 100644 --- a/src/main/java/org/fujaba/graphengine/PatternEngine.java +++ b/src/main/java/org/fujaba/graphengine/PatternEngine.java @@ -476,7 +476,15 @@ private static ArrayList>> findPossibleMatchesForPosit // TODO verify: we shouldn't mind edges from positive to negative nodes here (yet): boolean dontMind = !"!=".equals(patternEdge.getSource().getAction()) && "!=".equals(patternEdge.getTarget().getAction()); if (!dontMind) { + boolean exists = !(node.getEdges(patternEdge.getName()) == null || node.getEdges(patternEdge.getName()).size() == 0); + + //##### NEW TTC2017 FEATURE: + if (patternEdge.getName() == null) { + exists = node.getEdges().keySet().size() > 0; + } + //##### + if (("!=".equals(patternEdge.getAction()) && exists) || !"!=".equals(patternEdge.getAction()) && !exists) { continue nodeMatch; } @@ -554,7 +562,25 @@ public static boolean doesntMatchNegativeNodes(HashMap map, G continue; } if (patternEdge.getTarget() == otherSubNode) { - boolean exists = mapping.get(currentSubNode).getEdges(patternEdge.getName()) != null && mapping.get(currentSubNode).getEdges(patternEdge.getName()).contains(mapping.get(otherSubNode)); + + boolean exists = false; + + if (mapping.get(currentSubNode).getEdges(patternEdge.getName()) != null) { + exists = mapping.get(currentSubNode).getEdges(patternEdge.getName()) != null && mapping.get(currentSubNode).getEdges(patternEdge.getName()).contains(mapping.get(otherSubNode)); + } + + //##### NEW TTC2017 FEATURE: + if (patternEdge.getName() == null) { + exists = false; + for (String ttcTestString: mapping.get(currentSubNode).getEdges().keySet()) { + if (mapping.get(currentSubNode).getEdges(ttcTestString).contains(mapping.get(otherSubNode))) { + exists = true; + break; + } + } + } + //##### + if (("!=".equals(patternEdge.getAction()) && exists) || (!"!=".equals(patternEdge.getAction()) && !exists)) { fail = true; // failure at outgoing edge break match; @@ -567,7 +593,25 @@ public static boolean doesntMatchNegativeNodes(HashMap map, G continue; } if (patternEdge.getTarget() == currentSubNode) { - boolean exists = mapping.get(otherSubNode).getEdges(patternEdge.getName()) != null && mapping.get(otherSubNode).getEdges(patternEdge.getName()).contains(mapping.get(currentSubNode)); + + boolean exists = false; + + if (mapping.get(otherSubNode).getEdges(patternEdge.getName()) != null) { + exists = mapping.get(otherSubNode).getEdges(patternEdge.getName()) != null && mapping.get(otherSubNode).getEdges(patternEdge.getName()).contains(mapping.get(currentSubNode)); + } + + //##### NEW TTC2017 FEATURE: + if (patternEdge.getName() == null) { + exists = false; + for (String ttcTestString: mapping.get(otherSubNode).getEdges().keySet()) { + if (mapping.get(otherSubNode).getEdges(ttcTestString).contains(mapping.get(currentSubNode))) { + exists = true; + break; + } + } + } + //##### + if (("!=".equals(patternEdge.getAction()) && exists) || (!"!=".equals(patternEdge.getAction()) && !exists)) { fail = true; // failure at incoming edge break match; @@ -589,7 +633,25 @@ public static boolean doesntMatchNegativeNodes(HashMap map, G continue; } if (patternEdge.getTarget() == nodeMatchLists.get(0).get(k)) { - boolean exists = mapping.get(currentSubNode).getEdges(patternEdge.getName()) != null && mapping.get(currentSubNode).getEdges(patternEdge.getName()).contains(mapping.get(nodeMatchLists.get(0).get(k))); + + boolean exists = false; + + if (mapping.get(currentSubNode).getEdges(patternEdge.getName()) != null) { + exists = mapping.get(currentSubNode).getEdges(patternEdge.getName()) != null && mapping.get(currentSubNode).getEdges(patternEdge.getName()).contains(mapping.get(nodeMatchLists.get(0).get(k))); + } + + //##### NEW TTC2017 FEATURE: + if (patternEdge.getName() == null) { + exists = false; + for (String ttcTestString: mapping.get(currentSubNode).getEdges().keySet()) { + if (mapping.get(currentSubNode).getEdges(ttcTestString).contains(mapping.get(nodeMatchLists.get(0).get(k)))) { + exists = true; + break; + } + } + } + //##### + if (("!=".equals(patternEdge.getAction()) && exists) || (!"!=".equals(patternEdge.getAction()) && !exists)) { fail = true; // failure at outgoing edge break; @@ -604,7 +666,25 @@ public static boolean doesntMatchNegativeNodes(HashMap map, G continue; } if (patternEdge.getTarget() == currentSubNode) { - boolean exists = mapping.get(nodeMatchLists.get(0).get(k)).getEdges(patternEdge.getName()) != null && mapping.get(nodeMatchLists.get(0).get(k)).getEdges(patternEdge.getName()).contains(mapping.get(currentSubNode)); + + boolean exists = false; + + if (mapping.get(nodeMatchLists.get(0).get(k)).getEdges(patternEdge.getName()) != null) { + exists = mapping.get(nodeMatchLists.get(0).get(k)).getEdges(patternEdge.getName()) != null && mapping.get(nodeMatchLists.get(0).get(k)).getEdges(patternEdge.getName()).contains(mapping.get(currentSubNode)); + } + + //##### NEW TTC2017 FEATURE: + if (patternEdge.getName() == null) { + exists = false; + for (String ttcTestString: mapping.get(nodeMatchLists.get(0).get(k)).getEdges().keySet()) { + if (mapping.get(nodeMatchLists.get(0).get(k)).getEdges(ttcTestString).contains(mapping.get(currentSubNode))) { + exists = true; + break; + } + } + } + //##### + if (("!=".equals(patternEdge.getAction()) && exists) || (!"!=".equals(patternEdge.getAction()) && !exists)) { fail = true; // failure at incoming edge break; @@ -680,7 +760,25 @@ public static ArrayList matchPattern(Graph graph, PatternGraph pattern, b continue; } if (patternEdge.getTarget() == otherSubNode) { - boolean exists = mapping.get(currentSubNode).getEdges(patternEdge.getName()).contains(mapping.get(otherSubNode)); + + boolean exists = false; + + if (mapping.get(currentSubNode).getEdges(patternEdge.getName()) != null) { + exists = mapping.get(currentSubNode).getEdges(patternEdge.getName()).contains(mapping.get(otherSubNode)); + } + + //##### NEW TTC2017 FEATURE: + if (patternEdge.getName() == null) { + exists = false; + for (String ttcTestString: mapping.get(currentSubNode).getEdges().keySet()) { + if (mapping.get(currentSubNode).getEdges(ttcTestString).contains(mapping.get(otherSubNode))) { + exists = true; + break; + } + } + } + //##### + if (("!=".equals(patternEdge.getAction()) && exists) || (!"!=".equals(patternEdge.getAction()) && !exists)) { fail = true; // failure at outgoing edge break match; @@ -692,7 +790,25 @@ public static ArrayList matchPattern(Graph graph, PatternGraph pattern, b continue; } if (patternEdge.getTarget() == currentSubNode) { - boolean exists = mapping.get(otherSubNode).getEdges(patternEdge.getName()).contains(mapping.get(currentSubNode)); + + boolean exists = false; + + if (mapping.get(otherSubNode).getEdges(patternEdge.getName()) != null) { + exists = mapping.get(otherSubNode).getEdges(patternEdge.getName()).contains(mapping.get(currentSubNode)); + } + + //##### NEW TTC2017 FEATURE: + if (patternEdge.getName() == null) { + exists = false; + for (String ttcTestString: mapping.get(otherSubNode).getEdges().keySet()) { + if (mapping.get(otherSubNode).getEdges(ttcTestString).contains(mapping.get(currentSubNode))) { + exists = true; + break; + } + } + } + //##### + if (("!=".equals(patternEdge.getAction()) && exists) || (!"!=".equals(patternEdge.getAction()) && !exists)) { fail = true; // failure at incoming edge break match; diff --git a/src/test/java/org/fujaba/graphengine/unitTests/TestLoadingTTCStateCaseData.java b/src/test/java/org/fujaba/graphengine/unitTests/TestLoadingTTCStateCaseData.java index 97f10e1..cb55de4 100644 --- a/src/test/java/org/fujaba/graphengine/unitTests/TestLoadingTTCStateCaseData.java +++ b/src/test/java/org/fujaba/graphengine/unitTests/TestLoadingTTCStateCaseData.java @@ -1,6 +1,12 @@ package org.fujaba.graphengine.unitTests; +import java.util.ArrayList; + +import org.fujaba.graphengine.Match; +import org.fujaba.graphengine.PatternEngine; import org.fujaba.graphengine.graph.Graph; +import org.fujaba.graphengine.pattern.PatternGraph; +import org.fujaba.graphengine.pattern.PatternNode; import org.fujaba.graphengine.stateelimination.TTCStateCaseGraphLoader; import org.junit.Assert; import org.junit.Test; @@ -19,6 +25,8 @@ public void testLoadingTTCStateCaseData() { g = TTCStateCaseGraphLoader.load(taskMainPath + "leader3_2.xmi"); Assert.assertEquals(26, g.getNodes().size()); + System.out.println(g); + g = TTCStateCaseGraphLoader.load(taskMainPath + "leader3_3.xmi"); Assert.assertEquals(69, g.getNodes().size()); @@ -43,4 +51,33 @@ public void testLoadingTTCStateCaseData() { g = TTCStateCaseGraphLoader.load(taskMainPath + "leader6_2.xmi"); Assert.assertEquals(335, g.getNodes().size()); } + + + @Test + public void testTransformingTTCStateCaseData() { + + String taskMainPath = "src/main/resources/ExperimentalData/testdata/emf/task-main/"; + Graph g = TTCStateCaseGraphLoader.load(taskMainPath + "leader3_2.xmi"); + + PatternGraph gtr1 = new PatternGraph("gtr1"); + + PatternNode p = new PatternNode(); + PatternNode k = new PatternNode(); + PatternNode q = new PatternNode(); + + gtr1.addPatternNode(p, k, q); + + p.addPatternEdge("-", (String)null, k); + k.addPatternEdge("-", (String)null, q); + p.addPatternEdge("+", "calculated", q); + + ArrayList matches = PatternEngine.matchPattern(g, gtr1, false); + + Assert.assertTrue(matches.size() > 0); + + System.out.println("yay, " + matches.size() + " matches!"); + + } + + } \ No newline at end of file