use of com.tinkerpop.blueprints.Edge in project hale by halestudio.
the class GraphMLLabelProvider method getText.
/**
* @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
*/
@Override
public String getText(Object element) {
String result = "";
if (element instanceof Vertex) {
Vertex vex = (Vertex) element;
result = result + vex.getProperty("name");
if (vex.getProperty("type").equals("source")) {
if (vex.getProperty("group") != null) {
result = result + "\n" + vex.getProperty("group");
}
if (vex.getProperty("value") != null) {
result = result + "\n" + vex.getProperty("value");
}
}
return result;
}
if (element instanceof Edge) {
return ((Edge) element).getLabel();
}
// TODO FIX.ME
throw new RuntimeException("Wrong input type in for GraphML Label Provider: " + element.getClass().toString());
}
use of com.tinkerpop.blueprints.Edge in project hale by halestudio.
the class TGraphFactory method create.
/**
* Create a transformation graph from a transformation tree.
*
* @param ttree the transformation tree
* @param functionService the function service
* @return an in-memory graph created from the transformation tree
*/
public static Graph create(TransformationTree ttree, FunctionService functionService) {
TreeToGraphVisitor graphVisitor = new TreeToGraphVisitor(functionService);
ttree.accept(graphVisitor);
SetMultimap<String, String> connections = graphVisitor.getAllConnections();
Set<String> ids = graphVisitor.getAllIds();
Graph graph = new TinkerGraph();
// add nodes to the graph
for (String key : ids) {
// create a vertex for each transformation node
TransformationNode node = graphVisitor.getNode(key);
Vertex vertex = graph.addVertex(key);
setVertexProperties(vertex, node);
}
for (String key : connections.keySet()) {
for (String value : connections.get(key)) {
Vertex targetSide = graph.getVertex(key);
Vertex sourceSide = graph.getVertex(value);
TransformationNode targetSideNode = graphVisitor.getNode(key);
TransformationNode sourceSideNode = graphVisitor.getNode(value);
String edgeLabel;
if (sourceSideNode instanceof SourceNode && targetSideNode instanceof SourceNode) {
edgeLabel = EDGE_CHILD;
} else if (sourceSideNode instanceof SourceNode && targetSideNode instanceof CellNode) {
edgeLabel = EDGE_VARIABLE;
} else if (sourceSideNode instanceof CellNode && targetSideNode instanceof GroupNode) {
edgeLabel = EDGE_RESULT;
} else if (sourceSideNode instanceof GroupNode && targetSideNode instanceof GroupNode) {
edgeLabel = EDGE_PARENT;
} else {
throw new IllegalStateException("Invalid relation in transformation tree");
}
Edge edge = graph.addEdge(null, sourceSide, targetSide, edgeLabel);
setEdgeProperties(edge, sourceSideNode, targetSideNode);
}
}
return graph;
}
use of com.tinkerpop.blueprints.Edge in project pentaho-metaverse by pentaho.
the class BlueprintsGraphMetaverseReader method findLink.
@Override
public IMetaverseLink findLink(String leftNodeID, String linkType, String rightNodeID, Direction direction) {
Vertex vertex = getGraph().getVertex(leftNodeID);
if (vertex == null) {
return null;
}
Iterable<Edge> edges = linkType == null ? vertex.getEdges(direction) : vertex.getEdges(direction, linkType);
IMetaverseLink link = new MetaverseLink();
IMetaverseNode node1 = new MetaverseNode(vertex);
Direction opDirection = direction == Direction.IN ? Direction.OUT : Direction.IN;
Vertex vertex2 = null;
if (rightNodeID != null) {
Iterator<Edge> it = edges.iterator();
while (it.hasNext()) {
Edge edge = it.next();
if (rightNodeID.equals((String) edge.getVertex(opDirection).getId())) {
vertex2 = edge.getVertex(opDirection);
IMetaverseNode node2 = new MetaverseNode(vertex2);
String label = edge.getLabel();
link.setLabel(label);
String localized = Messages.getString(MetaverseUtil.MESSAGE_PREFIX_LINKTYPE + label);
if (!localized.startsWith("!")) {
link.setProperty(DictionaryConst.PROPERTY_TYPE_LOCALIZED, localized);
}
if (direction == Direction.OUT) {
link.setFromNode(node1);
link.setToNode(node2);
} else {
link.setFromNode(node2);
link.setToNode(node1);
}
return link;
}
}
}
return null;
}
use of com.tinkerpop.blueprints.Edge in project pentaho-metaverse by pentaho.
the class BlueprintsGraphMetaverseReader method enhanceGraph.
/**
* Adds localized types and categories, add node color information
*
* @param g The graph to enhance
* @return The enhanced graph
*/
protected Graph enhanceGraph(Graph g) {
// TODO should we clone the graph?
Iterator<Vertex> vertices = g.getVertices().iterator();
// enhance the vertixes
while (vertices.hasNext()) {
Vertex vertex = vertices.next();
MetaverseUtil.enhanceVertex(vertex);
}
Iterator<Edge> edges = g.getEdges().iterator();
// enhance the vertixes
while (edges.hasNext()) {
Edge edge = edges.next();
MetaverseUtil.enhanceEdge(edge);
}
return g;
}
use of com.tinkerpop.blueprints.Edge in project pentaho-metaverse by pentaho.
the class GraphPath method addToGraph.
/**
* Adds this path to a graph.
*
* @param g The graph to add this path to.
*/
public void addToGraph(Graph g) {
for (Object item : path) {
if (item instanceof Vertex) {
Vertex vertex = (Vertex) item;
Vertex v = g.getVertex(vertex.getId());
if (v == null) {
v = GraphUtil.cloneVertexIntoGraph(vertex, g);
}
} else if (item instanceof Edge) {
Edge edge = (Edge) item;
Edge e = g.getEdge(edge.getId());
if (e == null) {
Vertex v1 = g.getVertex(edge.getVertex(Direction.OUT));
if (v1 == null) {
v1 = GraphUtil.cloneVertexIntoGraph(edge.getVertex(Direction.OUT), g);
}
Vertex v2 = g.getVertex(edge.getVertex(Direction.IN));
if (v2 == null) {
v2 = GraphUtil.cloneVertexIntoGraph(edge.getVertex(Direction.IN), g);
}
e = g.addEdge(edge.getId(), v1, v2, edge.getLabel());
}
}
}
}
Aggregations