Im using the last version of tinkerpop3 , How can I get all vertex neighbors according to some roles

44 views
Skip to first unread message

Sara

unread,
Aug 18, 2016, 5:07:57 PM8/18/16
to Gremlin-users
Vertex A has neighbors that connected to datetime vertexes

and has neighbors that are not connected to datetime vertex

and vertex A has neighbors which connected to vertex with label dimon

I would like to get all the neighbors of vertex A which connected to datetime between range of dates

and alse to get all the other neighbors which are not connected to datetime vertexes:

 and if a neighbor connected to vertex with label dimon , I would like to get the neighbor and also the vertex dimon

 

for example my query results in case the  range of dates is valid:

    A--->B

A--->C--->F

A-->E

A--->D

in case only E has valid date :


    A--->B

A--->C--->F

A-->E


Daniel Kuppitz

unread,
Aug 18, 2016, 5:41:41 PM8/18/16
to gremli...@googlegroups.com
Hi Sara,

first your graph:

g = TinkerGraph.open().traversal()
g.addV().property("name", "A").as("a").
  addV().property("name", "B").as("b").
  addV().property("name", "C").as("c").
  addV().property("name", "D").as("d").
  addV().property("name", "E").as("e").
  addV("dimon").property("name", "F").as("f").
  addV().property("name", "G").as("g").property("date", 20160818).
  addV().property("name", "H").as("h").property("date", 20160817).
  addE("rel").from("a").to("b").
  addE("rel").from("a").to("c").
  addE("rel").from("a").to("d").
  addE("rel").from("a").to("e").
  addE("rel").from("c").to("f").
  addE("occured_at").from("d").to("g").
  addE("occured_at").from("e").to("h").iterate()

.., and here are the query use-cases:

gremlin> // D and E have a valid date
gremlin> g.V().has("name", "A").out("rel").union(
gremlin>     where(out("occured_at").has("date", gte(20160817))),
gremlin>     __.not(outE("occured_at")).coalesce(out().hasLabel("dimon"), identity())
gremlin>   ).valueMap()
==>[name:[B]]
==>[name:[F]]
==>[name:[D]]
==>[name:[E]]
gremlin>
gremlin> // only E has a valid date
gremlin> g.V().has("name", "A").out("rel").union(
gremlin>     where(out("occured_at").has("date", lte(20160817))),
gremlin>     __.not(outE("occured_at")).coalesce(out().hasLabel("dimon"), identity())
gremlin>   ).valueMap()
==>[name:[B]]
==>[name:[F]]
==>[name:[E]]
gremlin>
gremlin> // only D has a valid date
gremlin> g.V().has("name", "A").out("rel").union(
gremlin>     where(out("occured_at").has("date", gt(20160817))),
gremlin>     __.not(outE("occured_at")).coalesce(out().hasLabel("dimon"), identity())
gremlin>   ).valueMap()
==>[name:[B]]
==>[name:[F]]
==>[name:[D]]
gremlin>
gremlin> // neither D nor E have a valid date
gremlin> g.V().has("name", "A").out("rel").union(
gremlin>     where(out("occured_at").has("date", lt(20160817))),
gremlin>     __.not(outE("occured_at")).coalesce(out().hasLabel("dimon"), identity())
gremlin>   ).valueMap()
==>[name:[B]]
==>[name:[F]]
gremlin>

Cheers,
Daniel



--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/e14cfcd6-0ce4-4427-8576-1e3263b6cd22%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages