Skip to content

Commit

Permalink
#36 added feature to set edge labels by expression
Browse files Browse the repository at this point in the history
  • Loading branch information
hoechp committed May 20, 2017
1 parent fe40a13 commit fccac4e
Show file tree
Hide file tree
Showing 3 changed files with 371 additions and 300 deletions.
26 changes: 25 additions & 1 deletion src/main/java/org/fujaba/graphengine/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.fujaba.graphengine.pattern.PatternGraph;
import org.fujaba.graphengine.pattern.PatternNode;

import net.sourceforge.jeval.Evaluator;

/**
* A Match is a single match of a PatternGraph in a Graph.
* Every PatternNode, PatternEdge and PatternAttribute is mapped to a Node,
Expand All @@ -28,17 +30,31 @@ public class Match {
* the mapping from pattern nodes to graph nodes
*/
private HashMap<PatternNode, Node> nodeMatch;

/**
* the evaluator that's used for wildcard labels within the GTR
*/
private Evaluator labelEvaluator;

public static Evaluator buildLabelEvaluator(HashMap<String, String> labelMatches) {
Evaluator evaluator = new Evaluator();
for (String key: labelMatches.keySet()) {
evaluator.putVariable(key, "" + labelMatches.get(key));
}
return evaluator;
}

/**
* the constructor for this Match.
* @param graph the graph, this match did match on
* @param pattern the pattern that was matched
* @param nodeMatch the mapping from pattern nodes to graph nodes
*/
public Match(Graph graph, PatternGraph pattern, HashMap<PatternNode, Node> nodeMatch) {
public Match(Graph graph, PatternGraph pattern, HashMap<PatternNode, Node> nodeMatch, HashMap<String, String> labelMatches) {
this.graph = graph;
this.pattern = pattern;
this.nodeMatch = nodeMatch;
this.labelEvaluator = buildLabelEvaluator(labelMatches);
}

public Graph getGraph() {
Expand All @@ -60,4 +76,12 @@ public void setNodeMatch(HashMap<PatternNode, Node> nodeMatch) {
this.nodeMatch = nodeMatch;
}

public Evaluator getLabelEvaluator() {
return labelEvaluator;
}

public void setLabelEvaluator(Evaluator labelEvaluator) {
this.labelEvaluator = labelEvaluator;
}

}
Loading

0 comments on commit fccac4e

Please sign in to comment.