Question

I am using Titan using JAVA. I have following situation:

There is post vertex,many user write comments on this post same user can post multiple comments on it.

U(email, name, sex)

What I have to do is, I have to send notification to all commenter if any new comment is posted.

Now the thing is how can i filter users i.e if there is situation like

U1 ------COMMENTED ----------> POST
U2 ------COMMENTED ----------> POST
U3 ------COMMENTED ----------> POST
U1 ------COMMENTED ----------> POST

If a new comment is posted, notification should be sent to U1 U2 U3. Now if i iterate through incoming edge COMMENTED it fetch U1 twice. But i need U1 only once just to get their email. How can I achieve that

Was it helpful?

Solution

I know your question was about Java, but the Gremlin Groovy sessions below demonstrate the approach. One way would be to use the dedup step.

http://gremlindocs.com/#filter/dedup

That will ensure that U1 exists only once after that step as shown here:

gremlin> g = TinkerGraphFactory.createTinkerGraph()
==>tinkergraph[vertices:6 edges:6]
gremlin> g.V.out.in
==>v[4]
==>v[6]
==>v[1]
==>v[1]
==>v[1]
==>v[4]
==>v[6]
==>v[1]
==>v[4]
==>v[4]
==>v[6]
==>v[1]
gremlin> g.V.out.in.dedup
==>v[4]
==>v[6]
==>v[1]

Alternatively you could write all users to a Set:

gremlin> x = [] as Set
gremlin> g.V.out.in.fill(x);null
==>null
gremlin> x
==>v[4]
==>v[6]
==>v[1]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top