Search in sources :

Example 81 with Edge

use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.

the class GraphBasedMatcher method match.

public Iterable<Edge> match(final Resource subject, final URI predicate, final Value object, final Resource context, final boolean includeInferred) {
    // System.out.println("+ spoc: " + s + " " + p + " " + o + " " + c);
    // System.out.println("+ \ts: " + subject + ", p: " + predicate + ", o: " + object + ", c: " + context);
    final String contextStr = null == context ? GraphSail.NULL_CONTEXT_NATIVE : store.resourceToNative(context);
    if (s && o) {
        Vertex vs = store.getVertex(subject);
        Vertex vo = store.getVertex(object);
        if (null == vs || null == vo) {
            return new IteratorCloseableIterable<Edge>(new EmptyIterator<Edge>());
        } else {
            // Right now, we arbitrarily choose the subject as the starting point.
            return new FilteredIterator<Edge>(vs.getEdges(Direction.OUT), new FilteredIterator.Criterion<Edge>() {

                public boolean fulfilledBy(final Edge edge) {
                    return store.matches(edge.getVertex(Direction.IN), object) && (!p || edge.getLabel().equals(predicate.stringValue())) && (!c || edge.getProperty(GraphSail.CONTEXT_PROP).equals(contextStr)) && (includeInferred || null == edge.getProperty(GraphSail.INFERRED));
                }
            });
        }
    } else if (s) {
        Vertex vs = store.getVertex(subject);
        return null == vs ? new IteratorCloseableIterable<Edge>(new EmptyIterator<Edge>()) : new FilteredIterator<Edge>(vs.getEdges(Direction.OUT), new FilteredIterator.Criterion<Edge>() {

            public boolean fulfilledBy(final Edge edge) {
                return (!p || edge.getLabel().equals(predicate.stringValue())) && (!c || edge.getProperty(GraphSail.CONTEXT_PROP).equals(contextStr)) && (includeInferred || null == edge.getProperty(GraphSail.INFERRED));
            }
        });
    } else {
        Vertex vo = store.getVertex(object);
        return null == vo ? new IteratorCloseableIterable<Edge>(new EmptyIterator<Edge>()) : new FilteredIterator<Edge>(vo.getEdges(Direction.IN), new FilteredIterator.Criterion<Edge>() {

            public boolean fulfilledBy(final Edge edge) {
                return (!p || edge.getLabel().equals(predicate.stringValue())) && (!c || edge.getProperty(GraphSail.CONTEXT_PROP).equals(contextStr)) && (includeInferred || null == edge.getProperty(GraphSail.INFERRED));
            }
        });
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) Edge(com.tinkerpop.blueprints.Edge)

Example 82 with Edge

use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.

the class PartitionEdgeIterable method iterator.

public Iterator<Edge> iterator() {
    return new Iterator<Edge>() {

        private Iterator<Edge> itty = iterable.iterator();

        private PartitionEdge nextEdge;

        public void remove() {
            this.itty.remove();
        }

        public boolean hasNext() {
            if (null != this.nextEdge) {
                return true;
            }
            while (this.itty.hasNext()) {
                final Edge edge = this.itty.next();
                if (graph.isInPartition(edge)) {
                    nextEdge = new PartitionEdge(edge, graph);
                    return true;
                }
            }
            return false;
        }

        public Edge next() {
            if (null != this.nextEdge) {
                final PartitionEdge temp = this.nextEdge;
                this.nextEdge = null;
                return temp;
            } else {
                while (this.itty.hasNext()) {
                    final Edge edge = this.itty.next();
                    if (graph.isInPartition(edge)) {
                        return new PartitionEdge(edge, graph);
                    }
                }
                throw new NoSuchElementException();
            }
        }
    };
}
Also used : Iterator(java.util.Iterator) Edge(com.tinkerpop.blueprints.Edge) NoSuchElementException(java.util.NoSuchElementException)

Example 83 with Edge

use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.

the class EventTransactionalGraphTest method testTransactionSeriesWithSuccess.

public void testTransactionSeriesWithSuccess() {
    graph.addListener(graphChangedListener);
    createEdge();
    Edge e = createEdge();
    e.setProperty("test", "it");
    e.setProperty("test", "that");
    Vertex v = createVertex();
    v.setProperty("test", "it");
    assertEquals(0, graphChangedListener.addEdgeEventRecorded());
    assertEquals(0, graphChangedListener.addVertexEventRecorded());
    assertEquals(0, graphChangedListener.edgePropertyChangedEventRecorded());
    assertEquals(0, graphChangedListener.vertexPropertyChangedEventRecorded());
    ((EventTransactionalGraph) graph).commit();
    assertEquals(2, graphChangedListener.addEdgeEventRecorded());
    assertEquals(5, graphChangedListener.addVertexEventRecorded());
    assertEquals(2, graphChangedListener.edgePropertyChangedEventRecorded());
    assertEquals(1, graphChangedListener.vertexPropertyChangedEventRecorded());
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) Edge(com.tinkerpop.blueprints.Edge)

Example 84 with Edge

use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.

the class EventTransactionalGraphTest method testTransactionSeriesOrder.

public void testTransactionSeriesOrder() {
    graph.addListener(graphChangedListener);
    graph.addListener(new ConsoleGraphChangedListener(graph));
    Vertex v1 = graph.addVertex(10);
    v1.setProperty("aaa", "bbb");
    v1.setProperty("ccc", "ddd");
    v1.removeProperty("aaa");
    Vertex v2 = graph.addVertex(20);
    Vertex v3 = graph.addVertex(30);
    Edge e1 = graph.addEdge(100, v1, v2, "friend");
    e1.setProperty("eee", "fff");
    e1.setProperty("ggg", "hhh");
    e1.setProperty("ggg", "hhhh");
    e1.removeProperty("eee");
    Edge e2 = graph.addEdge(101, v1, v2, "enemy");
    graph.removeEdge(e2);
    graph.removeVertex(v3);
    assertEquals(0, graphChangedListener.getOrder().size());
    ((EventTransactionalGraph) graph).commit();
    List<String> order = graphChangedListener.getOrder();
    assertEquals("v-added-10", order.get(0));
    assertEquals("v-property-changed-10-aaa:null->bbb", order.get(1));
    assertEquals("v-property-changed-10-ccc:null->ddd", order.get(2));
    assertEquals("v-property-removed-10-aaa:bbb", order.get(3));
    assertEquals("v-added-20", order.get(4));
    assertEquals("v-added-30", order.get(5));
    assertEquals("e-added-100", order.get(6));
    assertEquals("e-property-changed-100-eee:null->fff", order.get(7));
    assertEquals("e-property-changed-100-ggg:null->hhh", order.get(8));
    assertEquals("e-property-changed-100-ggg:hhh->hhhh", order.get(9));
    assertEquals("e-property-removed-100-eee:fff", order.get(10));
    assertEquals("e-added-101", order.get(11));
    assertEquals("e-removed-101", order.get(12));
    assertEquals("v-removed-30", order.get(13));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) ConsoleGraphChangedListener(com.tinkerpop.blueprints.util.wrappers.event.listener.ConsoleGraphChangedListener) Edge(com.tinkerpop.blueprints.Edge)

Example 85 with Edge

use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.

the class IdGraphTest method testDefaultIdFactory.

public void testDefaultIdFactory() throws Exception {
    Graph graph = this.generateGraph();
    Vertex v = graph.addVertex(null);
    String id = (String) v.getId();
    assertEquals(36, id.length());
    assertEquals(5, id.split("-").length);
    Vertex v2 = graph.addVertex(null);
    Edge e = graph.addEdge(null, v, v2, "knows");
    id = (String) e.getId();
    assertEquals(36, id.length());
    assertEquals(5, id.split("-").length);
    graph.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) WrapperGraph(com.tinkerpop.blueprints.util.wrappers.WrapperGraph) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) Edge(com.tinkerpop.blueprints.Edge)

Aggregations

Edge (com.tinkerpop.blueprints.Edge)214 Vertex (com.tinkerpop.blueprints.Vertex)141 Test (org.junit.Test)53 Graph (com.tinkerpop.blueprints.Graph)49 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)49 HashSet (java.util.HashSet)28 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)13 ArrayList (java.util.ArrayList)13 Collection (java.util.Collection)11 JSONObject (org.codehaus.jettison.json.JSONObject)11 HashMap (java.util.HashMap)10 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)9 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)8 Map (java.util.Map)8 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)7 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)6 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)6 URI (org.openrdf.model.URI)6