Java Code Examples for org.apache.tinkerpop.gremlin.structure.Edge#inVertex()
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.Edge#inVertex() .
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: QueryServiceImpl.java From janusgraph-visualization with Apache License 2.0 | 6 votes |
private GraphEdge convert(Edge edge) { GraphEdge graphEdge = new GraphEdge(); graphEdge.setId(edge.id().toString()); graphEdge.setLabel(edge.label()); Vertex inVertex = edge.inVertex(); Vertex outVertex = edge.outVertex(); graphEdge.setFrom(outVertex.id().toString()); graphEdge.setTo(inVertex.id().toString()); GraphVertex intGraphVertex = new GraphVertex(); intGraphVertex.setId(inVertex.id().toString()); intGraphVertex.setLabel(inVertex.label()); GraphVertex outGraphVertex = new GraphVertex(); outGraphVertex.setId(outVertex.id().toString()); outGraphVertex.setLabel(outVertex.id().toString()); graphEdge.setSource(convert(outVertex)); graphEdge.setTarget(convert(inVertex)); return graphEdge; }
Example 2
Source File: ShortestPathVertexProgram.java From tinkerpop with Apache License 2.0 | 6 votes |
private void processEdges(final Vertex vertex, final Path currentPath, final Number currentDistance, final Messenger<Triplet<Path, Edge, Number>> messenger) { final Traversal.Admin<Vertex, Edge> edgeTraversal = this.edgeTraversal.getPure(); edgeTraversal.addStart(edgeTraversal.getTraverserGenerator().generate(vertex, edgeTraversal.getStartStep(), 1)); while (edgeTraversal.hasNext()) { final Edge edge = edgeTraversal.next(); final Number distance = getDistance(edge); Vertex otherV = edge.inVertex(); if (otherV.equals(vertex)) otherV = edge.outVertex(); // only send message if the adjacent vertex is not yet part of the current path if (!currentPath.objects().contains(otherV)) { messenger.sendMessage(MessageScope.Global.of(otherV), Triplet.with(currentPath, this.includeEdges ? edge : null, NumberHelper.add(currentDistance, distance))); } } }
Example 3
Source File: D3GraphGeneratorService.java From timbuctoo with GNU General Public License v3.0 | 6 votes |
private void loadLinks(String relationTypeName, String vreId, D3Graph d3Graph, List<String> relationNames, int depth, int currentDepth, Edge edge) { Vertex source = edge.inVertex(); Vertex target = edge.outVertex(); final Optional<Collection> sourceCollection = GraphReadUtils.getCollectionByVreId(source, mappings, vreId); final Optional<Collection> targetCollection = GraphReadUtils.getCollectionByVreId(target, mappings, vreId); if (sourceCollection.isPresent() && targetCollection.isPresent()) { final String sourceEntityTypeName = sourceCollection.get().getEntityTypeName(); final String targetEntityTypeName = targetCollection.get().getEntityTypeName(); d3Graph.addNode(source, sourceEntityTypeName); d3Graph.addNode(target, targetEntityTypeName); d3Graph.addLink(edge, source, target, sourceEntityTypeName, targetEntityTypeName); if (currentDepth < depth) { generateD3Graph(relationTypeName, vreId, d3Graph, source, relationNames, depth, currentDepth + 1); generateD3Graph(relationTypeName, vreId, d3Graph, target, relationNames, depth, currentDepth + 1); } } }
Example 4
Source File: GraphUtil.java From janusgraph-visualization with Apache License 2.0 | 5 votes |
public static GraphEdge convert(Edge edge) { GraphEdge graphEdge = new GraphEdge(); graphEdge.setId(edge.id().toString()); graphEdge.setLabel(edge.label()); Vertex inVertex = edge.inVertex(); Vertex outVertex = edge.outVertex(); GraphVertex inGraphVertex = convert(inVertex); GraphVertex outGraphVertex = convert(outVertex); graphEdge.setSource(outGraphVertex); graphEdge.setTarget(inGraphVertex); return graphEdge; }
Example 5
Source File: HBaseBulkLoaderTest.java From hgraphdb with Apache License 2.0 | 5 votes |
@Test public void testBulkLoader() throws Exception { HBaseBulkLoader loader = new HBaseBulkLoader(graph); Vertex v1 = loader.addVertex(T.id, "A"); Vertex v2 = loader.addVertex(T.id, "B", "P1", "V1", "P2", "2"); loader.setProperty(v2, "P4", "4"); Edge e = loader.addEdge(v1, v2, "edge", "P3", "V3"); loader.setProperty(e, "P5", "5"); loader.close(); v1 = graph.vertex("A"); assertNotNull(v1); Iterator<Edge> it = v1.edges(Direction.OUT); assertTrue(it.hasNext()); e = it.next(); assertEquals("edge", e.label()); assertEquals("V3", e.property("P3").value()); assertEquals("5", e.property("P5").value()); v2 = e.inVertex(); assertEquals("B", v2.id()); assertEquals("V1", v2.property("P1").value()); assertEquals("2", v2.property("P2").value()); assertEquals("4", v2.property("P4").value()); }
Example 6
Source File: TinkerGraphQuerySemaphoreNeighborInject.java From trainbenchmark with Eclipse Public License 1.0 | 5 votes |
@Override public Collection<TinkerGraphSemaphoreNeighborInjectMatch> evaluate() { final Collection<TinkerGraphSemaphoreNeighborInjectMatch> matches = new ArrayList<>(); final Collection<Vertex> routes = driver.getVertices(ModelConstants.ROUTE); for (final Vertex route : routes) { final Iterable<Edge> entries = () -> route.edges(Direction.OUT, ModelConstants.ENTRY); for (final Edge edge : entries) { final Vertex semaphore = edge.inVertex(); matches.add(new TinkerGraphSemaphoreNeighborInjectMatch(route, semaphore)); } } return matches; }
Example 7
Source File: TinkerGraphQueryRouteSensorInject.java From trainbenchmark with Eclipse Public License 1.0 | 5 votes |
@Override public Collection<TinkerGraphRouteSensorInjectMatch> evaluate() { final Collection<TinkerGraphRouteSensorInjectMatch> matches = new ArrayList<>(); final Collection<Vertex> routes = driver.getVertices(ModelConstants.ROUTE); for (final Vertex route : routes) { final Iterable<Edge> edges = () -> route.edges(Direction.OUT, ModelConstants.REQUIRES); for (final Edge requires : edges) { final Vertex sensor = requires.inVertex(); matches.add(new TinkerGraphRouteSensorInjectMatch(route, sensor)); } } return matches; }
Example 8
Source File: WomenWritersJsonCrudService.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
@Override public void execute(ReadEntityImpl entity, Vertex entityVertex) { Set<String> languages = new HashSet<>(); final Iterator<Edge> isCreatorOf = entityVertex.edges(Direction.IN, "isCreatedBy"); while (isCreatorOf.hasNext()) { final Edge next = isCreatorOf.next(); final Boolean creatorOfIsAccepted = next.property("wwrelation_accepted").isPresent() ? (Boolean) next.property("wwrelation_accepted").value() : false; final Boolean creatorOfIsLatest = next.property("isLatest").isPresent() ? (Boolean) next.property("isLatest").value() : false; if (creatorOfIsAccepted && creatorOfIsLatest) { final Vertex publication = next.outVertex(); final Iterator<Edge> hasWorkLanguage = publication.edges(Direction.OUT, "hasWorkLanguage"); while (hasWorkLanguage.hasNext()) { final Edge nextLanguage = hasWorkLanguage.next(); final Boolean languageIsAccepted = nextLanguage.property("wwrelation_accepted").isPresent() ? (Boolean) nextLanguage.property("wwrelation_accepted").value() : false; final Boolean languageIsLatest = nextLanguage.property("isLatest").isPresent() ? (Boolean) nextLanguage.property("isLatest").value() : false; if (languageIsAccepted && languageIsLatest) { final Vertex languageVertex = nextLanguage.inVertex(); final String language = getProp(languageVertex, "wwlanguage_name", String.class).orElse(null); if (language != null) { languages.add(language); } } } } } entity.addExtraPoperty("languages", languages); }
Example 9
Source File: WomenWritersJsonCrudService.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
private List<Tuple<String, String>> getAuthorsForPublication(GraphTraversalSource traversalSource, Vre vre, Vertex vertex) { List<Tuple<String, String>> authors = new ArrayList<>(); final Iterator<Edge> isCreatedBy = vertex.edges(Direction.OUT, "isCreatedBy"); while (isCreatedBy.hasNext()) { final Edge next = isCreatedBy.next(); final Boolean isAccepted = (Boolean) next.property("wwrelation_accepted").isPresent() ? (Boolean) next.property("wwrelation_accepted").value() : false; final Object isLatest = next.property("isLatest").isPresent() ? (Boolean) next.property("isLatest").value() : false; if (isAccepted && (Boolean) isLatest) { final Vertex author1 = next.inVertex(); final Collection personCollection = vre.getCollectionForTypeName("wwperson"); final String authorName = getDisplayname(traversalSource, author1, personCollection).orElse(null); String authorGender = getProp(author1, "wwperson_gender", String.class).orElse(null); if (authorGender != null) { authorGender = authorGender.replaceAll("\"", ""); } if (authorName != null) { authors.add(tuple(authorName, authorGender)); } } } return authors; }
Example 10
Source File: GraphOMRSMetadataStore.java From egeria with Apache License 2.0 | 4 votes |
synchronized Relationship getRelationshipFromStore(String guid) throws RepositoryErrorException { String methodName = "getRelationshipFromStore"; Relationship relationship = null; GraphTraversalSource g = instanceGraph.traversal(); Iterator<Edge> edgeIt = g.E().hasLabel("Relationship").has(PROPERTY_KEY_RELATIONSHIP_GUID, guid); if (edgeIt.hasNext()) { Edge edge = edgeIt.next(); log.debug("{} found existing edge {}", methodName, edge); relationship = new Relationship(); // Map the properties relationshipMapper.mapEdgeToRelationship(edge, relationship); // Set the relationship ends... Vertex vertex = null; try { vertex = edge.outVertex(); // Could test here whether each vertex is for a proxy, but it doesn't matter whether the vertex represents a full entity // (i.e. EntityDetail of a local/reference copy) as opposed to an EntityProxy. It can be retrieved as a proxy anyway... if (vertex != null) { log.debug("{} entity vertex {}", methodName, vertex); EntityProxy entityOneProxy = new EntityProxy(); entityMapper.mapVertexToEntityProxy(vertex, entityOneProxy); log.debug("{} entityOneProxy {}", methodName, entityOneProxy); relationship.setEntityOneProxy(entityOneProxy); } vertex = edge.inVertex(); if (vertex != null) { log.debug("{} entity vertex {}", methodName, vertex); EntityProxy entityTwoProxy = new EntityProxy(); entityMapper.mapVertexToEntityProxy(vertex, entityTwoProxy); log.debug("{} entityTwoProxy {}", methodName, entityTwoProxy); relationship.setEntityTwoProxy(entityTwoProxy); } } catch (Exception e) { log.error("{} Caught exception from entity mapper {}", methodName, e.getMessage()); g.tx().rollback(); throw new RepositoryErrorException(GraphOMRSErrorCode.RELATIONSHIP_NOT_FOUND.getMessageDefinition(entityMapper.getEntityGUID(vertex), methodName, this.getClass().getName(), repositoryName), this.getClass().getName(), methodName, e); } } g.tx().commit(); return relationship; }
Example 11
Source File: GraphOMRSMetadataStore.java From egeria with Apache License 2.0 | 4 votes |
synchronized void removeEntityFromStore(String entityGUID) { final String methodName = "removeEntityFromStore"; // Look in the graph String guid = entityGUID; GraphTraversalSource g = instanceGraph.traversal(); GraphTraversal<Vertex, Vertex> gt = g.V().hasLabel("Entity").has(PROPERTY_KEY_ENTITY_GUID, entityGUID); // Only looking for non-proxy entities: gt = gt.has(PROPERTY_KEY_ENTITY_IS_PROXY, false); if (gt.hasNext()) { Vertex vertex = gt.next(); Boolean isProxy = entityMapper.isProxy(vertex); if (!isProxy) { log.debug("{} found entity vertex {} to be removed", methodName, vertex); // Look for associated classifications. Iterator<Edge> classifierEdges = vertex.edges(Direction.OUT, "Classifier"); while (classifierEdges.hasNext()) { Edge classifierEdge = classifierEdges.next(); Vertex classificationVertex = classifierEdge.inVertex(); // Get the classification's name for debug/info only Classification existingClassification = new Classification(); try { classificationMapper.mapVertexToClassification(classificationVertex, existingClassification); } catch (Exception e) { log.error("{} caught exception from classification mapper for classification {}", methodName, existingClassification.getName()); // Nothing you can do - just keep going } log.debug("{} removing classification {} from entity", methodName, existingClassification.getName()); classifierEdge.remove(); classificationVertex.remove(); } // Finally remove the entity vertex... vertex.remove(); log.debug("{} removed entity vertex with guid {}", methodName, entityGUID); } } g.tx().commit(); }
Example 12
Source File: GraphOMRSMetadataStore.java From egeria with Apache License 2.0 | 4 votes |
synchronized void removeEntityProxyFromStore(String entityGUID) { final String methodName = "removeEntityProxyFromStore"; // TODO - could capture existing entity and move it to 'history' // Look in the graph GraphTraversalSource g = instanceGraph.traversal(); GraphTraversal<Vertex, Vertex> gt = g.V().hasLabel("Entity").has(PROPERTY_KEY_ENTITY_GUID, entityGUID); // Only looking for proxy entities: gt = gt.has(PROPERTY_KEY_ENTITY_IS_PROXY, true); if (gt.hasNext()) { Vertex vertex = gt.next(); Boolean isProxy = entityMapper.isProxy(vertex); if (isProxy) { log.debug("{} found entity proxy vertex {} to be removed", methodName, vertex); // Look for associated classifications. Iterator<Edge> classifierEdges = vertex.edges(Direction.OUT, "Classifier"); while (classifierEdges.hasNext()) { Edge classifierEdge = classifierEdges.next(); Vertex classificationVertex = classifierEdge.inVertex(); // Get the classification's name for debug/info only Classification existingClassification = new Classification(); try { classificationMapper.mapVertexToClassification(classificationVertex, existingClassification); } catch (Exception e) { log.error("{} caught exception from classification mapper for classification {}", methodName, existingClassification.getName()); // Nothing you can do - just keep going } log.debug("{} removing classification {} from entity proxy", methodName, existingClassification.getName()); classifierEdge.remove(); classificationVertex.remove(); } // Finally remove the entity vertex... vertex.remove(); log.debug("{} removed entity proxy vertex with guid {}", methodName, entityGUID); } } g.tx().commit(); }
Example 13
Source File: GraphOMRSMetadataStore.java From egeria with Apache License 2.0 | 4 votes |
synchronized List<Relationship> getRelationshipsForEntity(String entityGUID) throws TypeErrorException, RepositoryErrorException { final String methodName = "getRelationshipsForEntity"; List<Relationship> relationships = new ArrayList<>(); // Look in the graph GraphTraversalSource g = instanceGraph.traversal(); Iterator<Vertex> vi = g.V().hasLabel("Entity").has(PROPERTY_KEY_ENTITY_GUID, entityGUID); if (vi.hasNext()) { Vertex vertex = vi.next(); log.debug("{} found entity vertex {}", methodName, vertex); Iterator<Edge> edges = vertex.edges(Direction.BOTH, "Relationship"); log.debug("{} entity has these edges {}", methodName, edges); while (edges.hasNext()) { Edge edge = edges.next(); log.debug("{} entity has edge {}", methodName, edge); Relationship relationship = new Relationship(); relationshipMapper.mapEdgeToRelationship(edge, relationship); // Set the relationship ends... try { vertex = edge.outVertex(); // Could test here whether each vertex is for a proxy, but it doesn't matter whether the vertex represents a full entity // (i.e. EntityDetail of a local/reference copy) as opposed to an EntityProxy. It can be retrieved as a proxy anyway... if (vertex != null) { log.debug("{} entity vertex {}", methodName, vertex); EntityProxy entityOneProxy = new EntityProxy(); entityMapper.mapVertexToEntityProxy(vertex, entityOneProxy); log.debug("{} entityOneProxy {}", methodName, entityOneProxy); relationship.setEntityOneProxy(entityOneProxy); } vertex = edge.inVertex(); if (vertex != null) { log.debug("{} entity vertex {}", methodName, vertex); EntityProxy entityTwoProxy = new EntityProxy(); entityMapper.mapVertexToEntityProxy(vertex, entityTwoProxy); log.debug("{} entityTwoProxy {}", methodName, entityTwoProxy); relationship.setEntityTwoProxy(entityTwoProxy); } } catch (Exception e) { log.error("{} Caught exception from entity mapper {}", methodName, e.getMessage()); g.tx().rollback(); throw new RepositoryErrorException(GraphOMRSErrorCode.RELATIONSHIP_NOT_FOUND.getMessageDefinition(entityMapper.getEntityGUID(vertex), methodName, this.getClass().getName(), repositoryName), this.getClass().getName(), methodName, e); } relationships.add(relationship); } } g.tx().commit(); return relationships; }
Example 14
Source File: ReferenceEdge.java From tinkerpop with Apache License 2.0 | 4 votes |
public ReferenceEdge(final Edge edge) { super(edge); this.inVertex = new ReferenceVertex(edge.inVertex()); this.outVertex = new ReferenceVertex(edge.outVertex()); }
Example 15
Source File: EdgeManipulator.java From timbuctoo with GNU General Public License v3.0 | 4 votes |
private static Edge createDuplicate(Edge edgeToDuplicate) { Vertex sourceOfEdge = edgeToDuplicate.outVertex(); Vertex targetOfEdge = edgeToDuplicate.inVertex(); return sourceOfEdge.addEdge(edgeToDuplicate.label(), targetOfEdge); }