Skip to content

Commit

Permalink
#29 #35 #36 #38 #39 new feature for matching any edge
Browse files Browse the repository at this point in the history
  • Loading branch information
hoechp committed May 18, 2017
1 parent 77496db commit 9c20677
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 6 deletions.
128 changes: 122 additions & 6 deletions src/main/java/org/fujaba/graphengine/PatternEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,15 @@ private static ArrayList<ArrayList<ArrayList<Node>>> 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;
}
Expand Down Expand Up @@ -554,7 +562,25 @@ public static boolean doesntMatchNegativeNodes(HashMap<PatternNode, Node> 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;
Expand All @@ -567,7 +593,25 @@ public static boolean doesntMatchNegativeNodes(HashMap<PatternNode, Node> 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;
Expand All @@ -589,7 +633,25 @@ public static boolean doesntMatchNegativeNodes(HashMap<PatternNode, Node> 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;
Expand All @@ -604,7 +666,25 @@ public static boolean doesntMatchNegativeNodes(HashMap<PatternNode, Node> 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;
Expand Down Expand Up @@ -680,7 +760,25 @@ public static ArrayList<Match> 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;
Expand All @@ -692,7 +790,25 @@ public static ArrayList<Match> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());

Expand All @@ -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<Match> matches = PatternEngine.matchPattern(g, gtr1, false);

Assert.assertTrue(matches.size() > 0);

System.out.println("yay, " + matches.size() + " matches!");

}


}

0 comments on commit 9c20677

Please sign in to comment.