Search in sources :

Example 91 with Edge

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

the class Neo4j2GraphSpecificTestSuite method testAutoStartTxOnEdgeIterables.

public void testAutoStartTxOnEdgeIterables() throws Exception {
    Neo4j2Graph graph = (Neo4j2Graph) graphTest.generateGraph();
    Vertex a = graph.addVertex(null);
    Vertex b = graph.addVertex(null);
    Neo4j2Edge edge = graph.addEdge(null, a, b, "testEdge");
    edge.setProperty("foo", "bar");
    Iterable<Edge> iterable = graph.getEdges();
    graph.commit();
    try {
        assertTrue(iterable.iterator().hasNext());
        assertNotNull(iterable.iterator().next());
        assertNotNull(graph.getEdges("foo", "bar").iterator().hasNext());
    } catch (NotInTransactionException e) {
        fail("Iterating edge iterable does not auto-start transaction");
    } finally {
        graph.shutdown();
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) NotInTransactionException(org.neo4j.graphdb.NotInTransactionException) Edge(com.tinkerpop.blueprints.Edge)

Example 92 with Edge

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

the class Neo4jGraphSpecificTestSuite method testQueryIndex.

public void testQueryIndex() throws Exception {
    Neo4jGraph graph = (Neo4jGraph) graphTest.generateGraph();
    Index<Vertex> vertexIndex = graph.createIndex("vertices", Vertex.class);
    Index<Edge> edgeIndex = graph.createIndex("edges", Edge.class);
    Vertex a = graph.addVertex(null);
    a.setProperty("name", "marko");
    vertexIndex.put("name", "marko", a);
    Iterator itty = graph.getIndex("vertices", Vertex.class).query("name", "*rko").iterator();
    int counter = 0;
    while (itty.hasNext()) {
        counter++;
        assertEquals(itty.next(), a);
    }
    assertEquals(counter, 1);
    Vertex b = graph.addVertex(null);
    Edge edge = graph.addEdge(null, a, b, "knows");
    edge.setProperty("weight", 0.75);
    edgeIndex.put("weight", 0.75, edge);
    itty = graph.getIndex("edges", Edge.class).query("label", "k?ows").iterator();
    counter = 0;
    while (itty.hasNext()) {
        counter++;
        assertEquals(itty.next(), edge);
    }
    assertEquals(counter, 0);
    itty = graph.getIndex("edges", Edge.class).query("weight", "[0.5 TO 1.0]").iterator();
    counter = 0;
    while (itty.hasNext()) {
        counter++;
        assertEquals(itty.next(), edge);
    }
    assertEquals(counter, 1);
    assertEquals(count(graph.getIndex("edges", Edge.class).query("weight", "[0.1 TO 0.5]")), 0);
    graph.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) Iterator(java.util.Iterator) Edge(com.tinkerpop.blueprints.Edge)

Example 93 with Edge

use of com.tinkerpop.blueprints.Edge in project incubator-atlas by apache.

the class AtlasEntityTagQuery method getQueryPipe.

@Override
protected Pipe getQueryPipe() {
    GremlinPipeline p;
    if (guid.equals("*")) {
        p = new GremlinPipeline().has(Constants.ENTITY_TEXT_PROPERTY_KEY).hasNot(Constants.ENTITY_TYPE_PROPERTY_KEY, "Taxonomy").outE();
    } else {
        p = new GremlinPipeline().has(Constants.GUID_PROPERTY_KEY, guid).outE();
    }
    // todo: this is basically the same pipeline used in TagRelation.asPipe()
    p.add(new FilterFunctionPipe<>(new PipeFunction<Edge, Boolean>() {

        @Override
        public Boolean compute(Edge edge) {
            String type = edge.getVertex(Direction.OUT).getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY);
            VertexWrapper v = new TermVertexWrapper(edge.getVertex(Direction.IN));
            return edge.getLabel().startsWith(type) && v.getPropertyKeys().contains("available_as_tag");
        }
    }));
    return p.inV();
}
Also used : GremlinPipeline(com.tinkerpop.gremlin.java.GremlinPipeline) TermVertexWrapper(org.apache.atlas.catalog.TermVertexWrapper) TermVertexWrapper(org.apache.atlas.catalog.TermVertexWrapper) VertexWrapper(org.apache.atlas.catalog.VertexWrapper) PipeFunction(com.tinkerpop.pipes.PipeFunction) Edge(com.tinkerpop.blueprints.Edge)

Example 94 with Edge

use of com.tinkerpop.blueprints.Edge in project incubator-atlas by apache.

the class TraitRelation method traverse.

@Override
public Collection<RelationSet> traverse(VertexWrapper vWrapper) {
    Vertex v = vWrapper.getVertex();
    Collection<VertexWrapper> vertices = new ArrayList<>();
    for (Edge e : v.getEdges(Direction.OUT)) {
        if (e.getLabel().startsWith(v.<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY))) {
            VertexWrapper trait = new TermVertexWrapper(e.getVertex(Direction.IN));
            if (!trait.getPropertyKeys().contains("available_as_tag") && !isDeleted(trait.getVertex())) {
                vertices.add(trait);
            }
        }
    }
    return Collections.singletonList(new RelationSet("traits", vertices));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TermVertexWrapper(org.apache.atlas.catalog.TermVertexWrapper) TermVertexWrapper(org.apache.atlas.catalog.TermVertexWrapper) VertexWrapper(org.apache.atlas.catalog.VertexWrapper) ArrayList(java.util.ArrayList) Edge(com.tinkerpop.blueprints.Edge)

Example 95 with Edge

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

the class TypedGraphModuleTest method testDeserializeEdgeType.

public void testDeserializeEdgeType() {
    Graph graph = new TinkerGraph();
    FramedGraphFactory factory = new FramedGraphFactory(new TypedGraphModuleBuilder().withClass(A.class).withClass(B.class).withClass(C.class).build());
    FramedGraph<Graph> framedGraph = factory.create(graph);
    Vertex v1 = graph.addVertex(null);
    Vertex v2 = graph.addVertex(null);
    Edge cE = graph.addEdge(null, v1, v2, "label");
    cE.setProperty("type", "C");
    Base c = framedGraph.getEdge(cE.getId(), Direction.OUT, Base.class);
    assertTrue(c instanceof C);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) TypedGraphModuleBuilder(com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder) 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