Java Code Examples for org.apache.tinkerpop.gremlin.structure.Graph#edges()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.Graph#edges() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainGraphConnectorHelper.java    From egeria with Apache License 2.0 6 votes vote down vote up
/**
 * Map a tinkerpop Graph object to an Open Lineage specific format.
 *
 * @param subGraph The graph to be mapped.
 * @return The graph in in an Open Lineage specific format.
 */
private LineageVerticesAndEdges getLineageVerticesAndEdges(Graph subGraph) {
    Iterator<Vertex> originalVertices = subGraph.vertices();
    Iterator<Edge> originalEdges = subGraph.edges();

    Set<LineageVertex> lineageVertices = new HashSet<>();
    Set<LineageEdge> lineageEdges = new HashSet<>();

    while (originalVertices.hasNext()) {
        LineageVertex newVertex = abstractVertex(originalVertices.next());
        lineageVertices.add(newVertex);
    }
    while (originalEdges.hasNext()) {
        LineageEdge newLineageEdge = abstractEdge(originalEdges.next());
        lineageEdges.add(newLineageEdge);
    }
    LineageVerticesAndEdges lineageVerticesAndEdges = new LineageVerticesAndEdges(lineageVertices, lineageEdges);
    return lineageVerticesAndEdges;
}
 
Example 2
Source File: Attachable.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
public static Property createProperty(final Attachable<Property> attachableProperty, final Graph hostGraph) {
    final Property baseProperty = attachableProperty.get();
    final Element baseElement = baseProperty.element();
    if (baseElement instanceof Vertex) {
        return Method.createVertexProperty((Attachable) attachableProperty, hostGraph);
    } else if (baseElement instanceof Edge) {
        final Iterator<Edge> edgeIterator = hostGraph.edges(baseElement.id());
        if (edgeIterator.hasNext())
            return edgeIterator.next().property(baseProperty.key(), baseProperty.value());
        throw new IllegalStateException("Could not find edge to create the attachable property on");
    } else { // vertex property
        final Iterator<Vertex> vertexIterator = hostGraph.vertices(((VertexProperty) baseElement).element().id());
        if (vertexIterator.hasNext()) {
            final Vertex vertex = vertexIterator.next();
            final Iterator<VertexProperty<Object>> vertexPropertyIterator = vertex.properties(((VertexProperty) baseElement).key());
            while (vertexPropertyIterator.hasNext()) {
                final VertexProperty<Object> vp = vertexPropertyIterator.next();
                if (ElementHelper.areEqual(vp, baseElement))
                    return vp.property(baseProperty.key(), baseProperty.value());
            }
        }
        throw new IllegalStateException("Could not find vertex property to create the attachable property on");
    }
}
 
Example 3
Source File: GraphMLWriter.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
private static Map<String, String> determineEdgeTypes(final Graph graph) {
    final Map<String, String> edgeKeyTypes = new HashMap<>();
    final Iterator<Edge> edges = graph.edges();
    try {
        while (edges.hasNext()) {
            final Edge edge = edges.next();
            for (String key : edge.keys()) {
                if (!edgeKeyTypes.containsKey(key))
                    edgeKeyTypes.put(key, GraphMLWriter.getStringType(edge.property(key).value()));
            }
        }
    } finally {
        CloseableIterator.closeIterator(edges);
    }

    return edgeKeyTypes;
}
 
Example 4
Source File: BitsyGraphIT.java    From bitsy with Apache License 2.0 5 votes vote down vote up
private Edge getEdge(Graph graph, Object id) {
	Iterator<Edge> iter = graph.edges(id);
	if (iter.hasNext()) {
		return iter.next();
	} else {
		return null;
	}
}
 
Example 5
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkergraph-gremlin with Apache License 2.0 4 votes vote down vote up
/**
 * Checks sequentially vertices and edges of both graphs. Will check sequentially Vertex IDs, Vertex Properties IDs
 * and values and classes. Then same for edges. To use when serializing a Graph and deserializing the supposedly
 * same Graph.
 */
private boolean approximateGraphsCheck(Graph g1, Graph g2) {
    final Iterator<Vertex> itV = g1.vertices();
    final Iterator<Vertex> itVRead = g2.vertices();

    while (itV.hasNext()) {
        final Vertex v = itV.next();
        final Vertex vRead = itVRead.next();

        // Will only check IDs but that's 'good' enough.
        if (!v.equals(vRead)) {
            return false;
        }

        final Iterator itVP = v.properties();
        final Iterator itVPRead = vRead.properties();
        while (itVP.hasNext()) {
            final VertexProperty vp = (VertexProperty) itVP.next();
            final VertexProperty vpRead = (VertexProperty) itVPRead.next();
            if (!vp.value().equals(vpRead.value())
                    || !vp.equals(vpRead)) {
                return false;
            }
        }
    }

    final Iterator<Edge> itE = g1.edges();
    final Iterator<Edge> itERead = g2.edges();

    while (itE.hasNext()) {
        final Edge e = itE.next();
        final Edge eRead = itERead.next();
        // Will only check IDs but that's good enough.
        if (!e.equals(eRead)) {
            return false;
        }

        final Iterator itEP = e.properties();
        final Iterator itEPRead = eRead.properties();
        while (itEP.hasNext()) {
            final Property ep = (Property) itEP.next();
            final Property epRead = (Property) itEPRead.next();
            if (!ep.value().equals(epRead.value())
                    || !ep.equals(epRead)) {
                return false;
            }
        }
    }
    return true;
}
 
Example 6
Source File: Attachable.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
public static Optional<Edge> getEdge(final Attachable<Edge> attachableEdge, final Graph hostGraph) {
    final Iterator<Edge> edgeIterator = hostGraph.edges(attachableEdge.get().id());
    return edgeIterator.hasNext() ? Optional.of(edgeIterator.next()) : Optional.empty();
}
 
Example 7
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
/**
 * Checks sequentially vertices and edges of both graphs. Will check sequentially Vertex IDs, Vertex Properties IDs
 * and values and classes. Then same for edges. To use when serializing a Graph and deserializing the supposedly
 * same Graph.
 */
private boolean approximateGraphsCheck(Graph g1, Graph g2) {
    final Iterator<Vertex> itV = g1.vertices();
    final Iterator<Vertex> itVRead = g2.vertices();

    while (itV.hasNext()) {
        final Vertex v = itV.next();
        final Vertex vRead = itVRead.next();

        // Will only check IDs but that's 'good' enough.
        if (!v.equals(vRead)) {
            return false;
        }

        final Iterator itVP = v.properties();
        final Iterator itVPRead = vRead.properties();
        while (itVP.hasNext()) {
            final VertexProperty vp = (VertexProperty) itVP.next();
            final VertexProperty vpRead = (VertexProperty) itVPRead.next();
            if (!vp.value().equals(vpRead.value())
                    || !vp.equals(vpRead)) {
                return false;
            }
        }
    }

    final Iterator<Edge> itE = g1.edges();
    final Iterator<Edge> itERead = g2.edges();

    while (itE.hasNext()) {
        final Edge e = itE.next();
        final Edge eRead = itERead.next();
        // Will only check IDs but that's good enough.
        if (!e.equals(eRead)) {
            return false;
        }

        final Iterator itEP = e.properties();
        final Iterator itEPRead = eRead.properties();
        while (itEP.hasNext()) {
            final Property ep = (Property) itEP.next();
            final Property epRead = (Property) itEPRead.next();
            if (!ep.value().equals(epRead.value())
                    || !ep.equals(epRead)) {
                return false;
            }
        }
    }
    return true;
}