Make a simple graph OR add a unique edge between two vertex

174 visningar
Hoppa till det första olästa meddelandet

Vitor Mangaravite

oläst,
1 apr. 2015 08:59:082015-04-01
till aureliu...@googlegroups.com
Hello,

I'm trying make a simple graph, so, make a graph without more than a edge between two vertex. Using gremlin, don't have a query to identify if, considering two vertex, exists any edge between them. To solve this, I implement a simple function to find, by the first vertex, if exists one edge to the second. But, my implemention is too slow. I think that happens because I don't have any properties of both vertex, so, using just titan vertex id. This is my implementation:

boolean has = false;
GremlinPipeline
pipe = new GremlinPipeline();
pipe.start(vertex1);
for(Object t1 : pipe.out()){
   Vertex v1t = (Vertex) t1;
   if(v1t.getId().equals(vertex2.getId()))
       has = true;
}

What can I do?
I'm using thinkaurelius.titan 0.5.4 (core, cassandra and elasticsearch).
Thank you!

Jason Plurad

oläst,
1 apr. 2015 12:28:142015-04-01
till aureliu...@googlegroups.com
Try defining an edge label with Multiplicity.ONE2ONE http://s3.thinkaurelius.com/docs/titan/0.5.4/schema.html#_edge_label_multiplicity

gremlin> conf = new BaseConfiguration()
==>org.apache.commons.configuration.BaseConfiguration@e903e28
gremlin> conf.setProperty('storage.backend', 'inmemory')
==>null
gremlin> g = TitanFactory.open(conf)
==>titangraph[inmemory:[127.0.0.1]]
gremlin> mgmt = g.getManagementSystem()
==>com.thinkaurelius.titan.graphdb.database.management.ManagementSystem@72ca7fc
gremlin> friend = mgmt.makeEdgeLabel('friend').multiplicity(Multiplicity.ONE2ONE).make()
==>friend
gremlin> mgmt.commit()
==>null
gremlin> v0 = g.addVertex()
==>v[256]
gremlin> v1 = g.addVertex()
==>v[512]
gremlin> v0.addEdge('friend', v1)
==>e[dc-74-1lh-e8][256-friend->512]
gremlin> v0.addEdge('friend', v1)
An edge with the given label already exists on the out-vertex and the label [friend] is out-unique
Display stack trace? [yN] 
Svara alla
Svara författaren
Vidarebefordra
0 nya meddelanden