public int getEdgeCount() { int count = 0; for (final Edge edge : this.graph.getEdges()) { count++; } return count; }
@Override public Iterable<Edge> getEdges() { return graph.getEdges(); }
@Override public Iterable<Edge> getEdges(final String key, final Object value) { return graph.getEdges(key, value); }
public Collection<Edge> getEdges() { final Iterable<Edge> itty = this.graph.getEdges(); if (itty instanceof Collection) { return (Collection<Edge>) itty; } else { final List<Edge> edges = new ArrayList<Edge>(); for (final Edge e : itty) { edges.add(e); } return edges; } }
private void populateLists(final List<Vertex> vertices, final List<Edge> edges) { for (Vertex v : graph.getVertices()) { vertices.add(v); } for (Edge e : graph.getEdges()) { edges.add(e); } }
private void writeGraphEdges(OutputStream os) throws IOException { IOUtils.write(GexfConstants.EDGES_OPEN, os); for(Edge edge : graph.getEdges()) { String id = ""+edge.getId().hashCode(); String source = ""+edge.getVertex(Direction.IN).getId().hashCode(); String target = ""+edge.getVertex(Direction.OUT).getId().hashCode(); writeGraphEdge(id, source, target, os); } IOUtils.write(GexfConstants.EDGES_CLOSE, os); }
private void writeGraphEdges(OutputStream os) throws IOException { IOUtils.write(GexfConstants.EDGES_OPEN, os); for(Edge edge : graph.getEdges()) { String id = ""+edge.getId().hashCode(); String source = ""+edge.getVertex(Direction.IN).getId().hashCode(); String target = ""+edge.getVertex(Direction.OUT).getId().hashCode(); writeGraphEdge(id, source, target, os); } IOUtils.write(GexfConstants.EDGES_CLOSE, os); }
private void writeGraphEdges(OutputStream os) throws IOException { for(Edge edge : graph.getEdges()) { String id = ""+edge.getId().hashCode(); String source = ""+edge.getVertex(Direction.IN).getId().hashCode(); String target = ""+edge.getVertex(Direction.OUT).getId().hashCode(); String label = ""+edge.getLabel(); writeGraphEdge(id, source, target, label, os); } }
private void writeGraphEdges(OutputStream os) throws IOException { for(Edge edge : graph.getEdges()) { String label = edge.getLabel(); String source = ""+edge.getVertex(Direction.IN).getId().hashCode(); String target = ""+edge.getVertex(Direction.OUT).getId().hashCode(); writeGraphEdge(label, source, target, os); } }
private void writeGraphEdges(OutputStream os) throws IOException { for(Edge edge : graph.getEdges()) { String label = edge.getLabel(); String source = ""+edge.getVertex(Direction.IN).getId().hashCode(); String target = ""+edge.getVertex(Direction.OUT).getId().hashCode(); writeGraphEdge(label, source, target, os); } }
@Test public void edges_queryIsEntailed() { Graph graph = graphApi.getEdges(OwlRelationships.RDFS_SUBCLASS_OF, true, 0L, 1L); assertThat(size(graph.getVertices()), is(2)); assertThat(size(graph.getEdges()), is(1)); }
@Test @Ignore // Not sorting works in production but not in test public void edges_areSkipped() { Graph graph = graphApi.getEdges(OwlRelationships.RDFS_SUBCLASS_OF, false, Long.MAX_VALUE, 1L); assertThat(size(graph.getVertices()), is(0)); assertThat(size(graph.getEdges()), is(0)); }
@Test public void getReachableNodes_filtersCorrectly() { Graph graph = graphApi.getReachableNodes(c, Lists.newArrayList("*"), Sets.newHashSet("alabel")); assertThat(size(graph.getVertices()), is(1)); assertThat(size(graph.getEdges()), is(0)); }
@Test public void getReachableNodes_traverseAllRels() { Graph graph = graphApi.getReachableNodes(c, Lists.newArrayList(), Sets.newHashSet()); assertThat(size(graph.getVertices()), is(1)); assertThat(size(graph.getEdges()), is(0)); }
@Test public void testPredicate() { Predicate<Node> testPredicate = new Predicate<Node>() { @Override public boolean apply(Node node) { return (node != c); }}; Graph graph = graphApi.getNeighbors(newHashSet(b), 1, Collections.<DirectedRelationshipType>emptySet(), Optional.of(testPredicate)); assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(4)); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(3)); }
@Test public void evidenceIsAdded() { assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(5)); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(1)); aspect.invoke(graph); assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(6)); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(3)); }
@Test public void getReachableNodes_nothingReturnedForFakeLabel() { Graph graph = graphApi.getReachableNodes(c, Lists.newArrayList(OwlRelationships.OWL_EQUIVALENT_CLASS.name(), OwlRelationships.RDFS_SUBCLASS_OF.name()), Sets.newHashSet("fakeLabel")); assertThat(size(graph.getVertices()), is(0)); assertThat(size(graph.getEdges()), is(0)); }
@Test public void testTypedNeighborhood() { Graph graph = graphApi.getNeighbors(newHashSet(b), 2, newHashSet(new DirectedRelationshipType(OwlRelationships.RDFS_SUBCLASS_OF, Direction.INCOMING)), absent); assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(3)); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(2)); }
public static void dumpGraph(com.tinkerpop.blueprints.Graph graphDb) { for (Vertex node: graphDb.getVertices()) { dumpNode(node); } for (Edge relationship: graphDb.getEdges()) { dumpRelationship(relationship); } }
@Test public void testMultiTypedNeighborhood() { Graph graph = graphApi.getNeighbors(newHashSet(b), 1, newHashSet(new DirectedRelationshipType(OwlRelationships.RDFS_SUBCLASS_OF, Direction.INCOMING), new DirectedRelationshipType(fizz, Direction.INCOMING)), absent); assertThat(graph.getVertices(), IsIterableWithSize.<Vertex>iterableWithSize(3)); assertThat(graph.getEdges(), IsIterableWithSize.<Edge>iterableWithSize(2)); }