Author: Not specified Language: java
Description: Not specified Timestamp: 2018-04-19 17:31:14 +0000
View raw paste Reply
// 1
g = TinkerGraph.open().traversal()

g.addV("course").property(T.id, 'CS101').addV("course").property(T.id, 'CS201').addV("course").property(T.id, 'CS220').addV("course").property(T.id, 'CS334').addV("course").property(T.id, 'CS400').addV("course").property(T.id, 'CS420').addV("course").property(T.id, 'CS526').addV("course").property(T.id, 'CS681').addE("requires pre-req").from(V('CS201')).to(V('CS101')).addE("requires pre-req").from(V('CS220')).to(V('CS201')).addE("requires pre-req").from(V('CS420')).to(V('CS220')).addE("is a co-req of").from(V('CS420')).to(V('CS220')).addE("requires pre-req").from(V('CS334')).to(V('CS201')).addE("requires pre-req").from(V('CS681')).to(V('CS334')).addE("requires pre-req").from(V('CS400')).to(V('CS334')).addE("requires pre-req").from(V('CS526')).to(V('CS400')).addE("is a co-req of").from(V('CS526')).to(V('CS400'))


// 2
g.V().as('a').out().as('b').select('a','b').groupCount().unfold().where(select(values).is(2)).select(keys)


// 3
g.V("CS526").repeat(out().dedup()).until(out().count().is(0)).emit()

// 4
g.V("CS101").repeat(__.in().dedup()).until(__.in().count().is(0)).path().count(local).max()

// bonus
g = TinkerGraph.open().traversal()

g.addV("node").property(T.id, 1).addV("node").property(T.id, 2).addV("node").property(T.id, 3).addV("node").property(T.id, 4).addE("path").from(V(1)).to(V(2)).addE("path").from(V(1)).to(V(2)).addE("path").from(V(1)).to(V(3)).addE("path").from(V(2)).to(V(3)).addE("path").from(V(2)).to(V(4)).addE("path").from(V(2)).to(V(4)).addE("path").from(V(3)).to(V(4))


g.V().where(bothE().count().filter{d = it.get(); d % 2 == 1;}).count().is(lte(2)).hasNext()
View raw paste Reply