Search in sources :

Example 1 with Edge

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());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) Edge(com.tinkerpop.blueprints.Edge)

Example 2 with Edge

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;
}
Also used : TransformationNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.TransformationNode) Vertex(com.tinkerpop.blueprints.Vertex) CellNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.CellNode) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) TreeToGraphVisitor(eu.esdihumboldt.hale.common.align.model.transformation.tree.visitor.TreeToGraphVisitor) GroupNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.GroupNode) SourceNode(eu.esdihumboldt.hale.common.align.model.transformation.tree.SourceNode) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) Edge(com.tinkerpop.blueprints.Edge)

Example 3 with Edge

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;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) MetaverseLink(org.pentaho.dictionary.MetaverseLink) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) IMetaverseLink(org.pentaho.metaverse.api.IMetaverseLink) MetaverseNode(org.pentaho.metaverse.impl.MetaverseNode) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) Edge(com.tinkerpop.blueprints.Edge) Direction(com.tinkerpop.blueprints.Direction)

Example 4 with Edge

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;
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) Edge(com.tinkerpop.blueprints.Edge)

Example 5 with Edge

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());
            }
        }
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) Edge(com.tinkerpop.blueprints.Edge)

Aggregations

Edge (com.tinkerpop.blueprints.Edge)214 Vertex (com.tinkerpop.blueprints.Vertex)141 Test (org.junit.Test)53 Graph (com.tinkerpop.blueprints.Graph)49 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)49 HashSet (java.util.HashSet)28 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)13 ArrayList (java.util.ArrayList)13 Collection (java.util.Collection)11 JSONObject (org.codehaus.jettison.json.JSONObject)11 HashMap (java.util.HashMap)10 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)9 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)8 Map (java.util.Map)8 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)7 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)6 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)6 URI (org.openrdf.model.URI)6