public int getVertexCount() { final Iterable<Vertex> itty = this.graph.getVertices(); if (itty instanceof Collection) { return ((Collection) itty).size(); } else { int count = 0; for (final Vertex vertex : itty) { count++; } return count; } }
public Collection<Vertex> getVertices() { final Iterable<Vertex> itty = this.graph.getVertices(); if (itty instanceof Collection) { return (Collection<Vertex>) itty; } else { final List<Vertex> vertices = new ArrayList<Vertex>(); for (final Vertex v : itty) { vertices.add(v); } return vertices; } }
@Override public Set<Term> getTerms() { Set<Term> terms = new TreeSet<Term>(); for (Vertex v : this.graph.getVertices("class", "term")) { terms.add(vertexToTerm(v)); } return terms; }
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); } }
/** * Generates a synthetic network connecting all vertices in the provided graph with the expected number * of edges. * * @param graph * @param expectedNumEdges * @return The number of generated edges. Not that this number may not be equal to the expected number of edges */ public int generate(Graph graph, int expectedNumEdges) { return generate(graph,graph.getVertices(),expectedNumEdges); }
/** * Generates a synthetic network connecting all vertices in the provided graph with the expected number * of edges. * * @param graph * @param expectedNumEdges * @return The number of generated edges. Not that this number may not be equal to the expected number of edges */ public int generate(Graph graph, int expectedNumEdges) { return generate(graph,graph.getVertices(),expectedNumEdges); }
private void mergeVertexes(Graph graph1, Graph graph2) { for (Vertex vertex2 : graph2.getVertices()) { mergeVertex(graph1, vertex2); } }
public void project(Collection<String> projection) { if (projection.contains("*")) { return; } for (Vertex vertex : graph.getVertices()) { for (String key : vertex.getPropertyKeys()) { if (!projection.contains(key) && !PROTECTED_PROPERTY_KEYS.contains(key)) { vertex.removeProperty(key); } } } }
@Override public CloseableIterator<Atom> iterator() { GIterator<Vertex> it = new IteratorAdapter<Vertex>(this.graph.getVertices("class", "atom") .iterator()); return new AtomIterator(it); }
private void writeGraphNodes(OutputStream os) throws IOException { //iterate the nodes. for(Vertex vertex : graph.getVertices()) { String id = ""+vertex.getId().hashCode(); String label = vertex.getProperty(vertexLabelProperty); if(StringUtils.isBlank(label)) { label = vertex.toString(); } writeGraphNode(id, label, os); } }
private void writeGraphNodes(OutputStream os) throws IOException { //iterate the nodes. for(Vertex vertex : graph.getVertices()) { String id = ""+vertex.getId().hashCode(); String label = vertex.getProperty(vertexLabelProperty); if(StringUtils.isBlank(label)) { label = vertex.toString(); } writeGraphNode(id, label, os); } }
void addCuries(Graph graph) { for (Vertex vertex: graph.getVertices()) { String iri = (String)vertex.getProperty(CommonProperties.IRI); Optional<String> curie = curieUtil.getCurie(iri); if (curie.isPresent()) { vertex.setProperty(CommonProperties.CURIE, curie.get()); } } }
private void init() { try { this.graph.getVertices("class", ""); } catch (IllegalArgumentException e) { Vertex v = this.graph.addVertex(null); v.setProperty("class", ""); } }
@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 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 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 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 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 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)); }
public static void dumpGraph(com.tinkerpop.blueprints.Graph graphDb) { for (Vertex node: graphDb.getVertices()) { dumpNode(node); } for (Edge relationship: graphDb.getEdges()) { dumpRelationship(relationship); } }