Java Code Examples for org.apache.tinkerpop.gremlin.structure.Graph#vertices()
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.Graph#vertices() .
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 |
/** * 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 |
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 |
private static Map<String, String> determineVertexTypes(final Graph graph) { final Map<String, String> vertexKeyTypes = new HashMap<>(); final Iterator<Vertex> vertices = graph.vertices(); try { while (vertices.hasNext()) { final Vertex vertex = vertices.next(); for (String key : vertex.keys()) { if (!vertexKeyTypes.containsKey(key)) { final VertexProperty<Object> currentValue = getCheckedVertexProperty(vertex, key); vertexKeyTypes.put(key, GraphMLWriter.getStringType(currentValue.value())); } } } } finally { CloseableIterator.closeIterator(vertices); } return vertexKeyTypes; }
Example 4
Source File: MinimumClientVersion.java From jaeger-analytics-java with Apache License 2.0 | 5 votes |
@Override public void runWithMetrics(Graph graph) { Iterator<Vertex> vertices = graph.vertices(); while (vertices.hasNext()) { Vertex vertex = vertices.next(); Span span = GraphCreator.toSpan(vertex); String jaegerVersion = span.tags.get(VERSION_TAG); if (jaegerVersion == null || jaegerVersion.isEmpty()) { jaegerVersion = MISSING_VERSION; } boolean result = computeScore(span); counter.labels(Boolean.toString(result), span.serviceName, jaegerVersion) .inc(); } }
Example 5
Source File: BitsyGraphIT.java From bitsy with Apache License 2.0 | 5 votes |
private Vertex getVertex(Graph graph, Object id) { Iterator<Vertex> iter = graph.vertices(id); if (iter.hasNext()) { return iter.next(); } else { return null; } }
Example 6
Source File: Attachable.java From tinkerpop with Apache License 2.0 | 5 votes |
public static Optional<VertexProperty> getVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Graph hostGraph) { final VertexProperty baseVertexProperty = attachableVertexProperty.get(); final Iterator<Vertex> vertexIterator = hostGraph.vertices(baseVertexProperty.element().id()); if (vertexIterator.hasNext()) { final Iterator<VertexProperty<Object>> vertexPropertyIterator = vertexIterator.next().properties(baseVertexProperty.key()); while (vertexPropertyIterator.hasNext()) { final VertexProperty vertexProperty = vertexPropertyIterator.next(); if (ElementHelper.areEqual(vertexProperty, baseVertexProperty)) return Optional.of(vertexProperty); } } return Optional.empty(); }
Example 7
Source File: Attachable.java From tinkerpop with Apache License 2.0 | 5 votes |
public static VertexProperty createVertexProperty(final Attachable<VertexProperty> attachableVertexProperty, final Graph hostGraph) { final VertexProperty<Object> baseVertexProperty = attachableVertexProperty.get(); final Iterator<Vertex> vertexIterator = hostGraph.vertices(baseVertexProperty.element().id()); if (vertexIterator.hasNext()) { final VertexProperty vertexProperty = hostGraph.features().vertex().properties().willAllowId(baseVertexProperty.id()) ? vertexIterator.next().property(hostGraph.features().vertex().getCardinality(baseVertexProperty.key()), baseVertexProperty.key(), baseVertexProperty.value(), T.id, baseVertexProperty.id()) : vertexIterator.next().property(hostGraph.features().vertex().getCardinality(baseVertexProperty.key()), baseVertexProperty.key(), baseVertexProperty.value()); baseVertexProperty.properties().forEachRemaining(p -> vertexProperty.property(p.key(), p.value())); return vertexProperty; } throw new IllegalStateException("Could not find vertex to create the attachable vertex property on"); }
Example 8
Source File: InferenceEngine.java From rya with Apache License 2.0 | 5 votes |
private static Vertex getVertex(final Graph graph, final Object id) { final Iterator<Vertex> it = graph.vertices(id.toString()); if (it.hasNext()) { return it.next(); } return null; }
Example 9
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkergraph-gremlin with Apache License 2.0 | 4 votes |
/** * 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 10
Source File: Attachable.java From tinkerpop with Apache License 2.0 | 4 votes |
public static Optional<Vertex> getVertex(final Attachable<Vertex> attachableVertex, final Graph hostGraph) { final Iterator<Vertex> vertexIterator = hostGraph.vertices(attachableVertex.get().id()); return vertexIterator.hasNext() ? Optional.of(vertexIterator.next()) : Optional.empty(); }
Example 11
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkerpop with Apache License 2.0 | 4 votes |
/** * 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; }