Common properties of unconnected nodes

13 views
Skip to first unread message

Udit Sharma

unread,
Jun 21, 2018, 2:12:52 AM6/21/18
to Gremlin-users
Sample Graph
g=TinkerGraph.open().traversal()
g.addV().property('type','student').property('id','student1').property('age','20').property('course','A').property('class','X'). addV().property('type','student').property('id','student2').property('age','20').property('course','A').property('class','Y')

Find the properties which are common among the nodes having id as 'student1' and 'student2'.

Expected Output
[key:course,value:A]
[key:type, value:student]
[key:age, value:20]

Robert Dale

unread,
Jun 21, 2018, 6:55:19 AM6/21/18
to gremli...@googlegroups.com

g.V().properties().unfold().group().by(key).by(value).unfold().project('k','v').by(keys).by(local(select(values).unfold().group().by().by(count()).order(local).by(values,decr).unfold().limit(1).select(keys)))
==>[k:course,v:A]
==>[k:id,v:student2]
==>[k:type,v:student]
==>[k:class,v:X]
==>[k:age,v:20]


Robert Dale


--
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-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/f7179aaf-4f3f-47c0-beb7-5dd4be1b7d08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Udit Sharma

unread,
Jun 21, 2018, 7:17:10 AM6/21/18
to gremli...@googlegroups.com
Thanks Robert,
But, the expected output is different from the actual output. Let me rephrase the problem again. Given id of two nodes as 'student1' and 'student2', find the properties where both the key and value pair matches. So in this case, the traversal should not generate [k:id,v:student2] and [k:class,v:X] as class and id are different for student1 and student2. 

Also assume that graph may have more than two nodes.

On Thu, Jun 21, 2018 at 4:25 PM, Robert Dale <rob...@gmail.com> wrote:

g.V().properties().unfold().group().by(key).by(value).unfold().project('k','v').by(keys).by(local(select(values).unfold().group().by().by(count()).order(local).by(values,decr).unfold().limit(1).select(keys)))
==>[k:course,v:A]
==>[k:id,v:student2]
==>[k:type,v:student]
==>[k:class,v:X]
==>[k:age,v:20]


Robert Dale

On Thu, Jun 21, 2018 at 2:12 AM Udit Sharma <ushar...@gmail.com> wrote:
Sample Graph
g=TinkerGraph.open().traversal()
g.addV().property('type','student').property('id','student1').property('age','20').property('course','A').property('class','X'). addV().property('type','student').property('id','student2').property('age','20').property('course','A').property('class','Y')

Find the properties which are common among the nodes having id as 'student1' and 'student2'.

Expected Output
[key:course,value:A]
[key:type, value:student]
[key:age, value:20]

--
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.

--
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/CABed_4rmN45-C77dFcKeWXLyrS0cDF_8MrW%2BHoiH6U%3D_L%3DxOBg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Thanks and Regards
Udit Sharma
MTech CSE, IITR

Robert Dale

unread,
Jun 21, 2018, 8:13:04 AM6/21/18
to gremli...@googlegroups.com

g.V().or(has('id','student1'), has('id','student2')).properties().
    group().by(key).by(value).unfold().
    project('k','v').by(keys).by(select(values).unfold().groupCount()).
    filter(select('v').select(values).unfold().is(gte(2))).
    select('k','v').by().by(select(keys).unfold())
==>[k:course,v:A]
==>[k:type,v:student]
==>[k:age,v:20]


Robert Dale

On Thu, Jun 21, 2018 at 7:17 AM Udit Sharma <ushar...@gmail.com> wrote:
Thanks Robert,
But, the expected output is different from the actual output. Let me rephrase the problem again. Given id of two nodes as 'student1' and 'student2', find the properties where both the key and value pair matches. So in this case, the traversal should not generate [k:id,v:student2] and [k:class,v:X] as class and id are different for student1 and student2. 

Also assume that graph may have more than two nodes.
On Thu, Jun 21, 2018 at 4:25 PM, Robert Dale <rob...@gmail.com> wrote:

g.V().properties().unfold().group().by(key).by(value).unfold().project('k','v').by(keys).by(local(select(values).unfold().group().by().by(count()).order(local).by(values,decr).unfold().limit(1).select(keys)))
==>[k:course,v:A]
==>[k:id,v:student2]
==>[k:type,v:student]
==>[k:class,v:X]
==>[k:age,v:20]


Robert Dale

On Thu, Jun 21, 2018 at 2:12 AM Udit Sharma <ushar...@gmail.com> wrote:
Sample Graph
g=TinkerGraph.open().traversal()
g.addV().property('type','student').property('id','student1').property('age','20').property('course','A').property('class','X'). addV().property('type','student').property('id','student2').property('age','20').property('course','A').property('class','Y')

Find the properties which are common among the nodes having id as 'student1' and 'student2'.

Expected Output
[key:course,value:A]
[key:type, value:student]
[key:age, value:20]

--
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-user...@googlegroups.com.

--
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-user...@googlegroups.com.



--
Thanks and Regards
Udit Sharma
MTech CSE, IITR

--
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-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/CAJtjf0Mn3bjL7v0ZBP2Yhpbz5Oyhb9D8Wj091WdhYP9a2Qv_wg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages