• • • • • • •
Cypher for Gremlin And more... And more... And more...
MATCH (p:Planet)-[orbit:ORBITS]->(:Star {name: 'Sun'}) WHERE orbit.au < 5 RETURN p AS planet; g.V().as('p').hasLabel('Planet') .outE('ORBITS').has('au', lt(5)) .inV().hasLabel('Star').has('name', eq('Sun')) .select('p').project('planet').by(valueMap().with(tokens))
● ● ● ● ● And more...
● ○ ● ○
• gremlin(...) • • • • MATCH (n:person {name: 'marko'}) RETURN gremlin("select('n').outE().label()") as r
Translator<String, GroovyPredicate> translator = Translator.builder() .gremlinGroovy() .enableCypherExtensions() .enable(TranslatorFeature.EXPERIMENTAL_GREMLIN_FUNCTION) .build();
* As suggested in GQL Scope and Features
Prototype QUERY friends($a VERTEX) { MATCH ($a)-[:FRIEND_OF]-(b) RETURN count(b) AS num_friends } CALL friends(a) YIELD num_friends QUERY friends($a VERTEX) { FOREIGN "gremlin" CALL "a.outE('FRIEND_OF').count().as('num_friends')" YIELD num_friends::NUMERIC }
Prototype • MATCH (n) FOREIGN "gremlin" USING n CALL "n.hasLabel('person').as('p').values('age').as('b')" YIELD p, b RETURN labels(p)[0] as a, b LIMIT 1
Prototype MATCH (n) FOREIGN "gremlin" CALL "select('n').hasLabel('person').as('p').values('age').as('b')" YIELD p, b RETURN labels(p)[0] as a, b LIMIT 1
Prototype • MATCH (n) FOREIGN "gremlin" CALL "select('n').hasLabel('person').as('p').values('age').as('b')" YIELD p::NODE, b::NUMERIC RETURN labels(p)[0] as a, b LIMIT 1
Prototype • • WITH 1 as n FOREIGN "gremlin" CALL "constant(2).as('n')" RETURN n //n = 1
• • • • •
• • • • gremlin> g.cypher("MATCH (n) RETURN n").select("n").outE().label().dedup() ==>created ==>knows
1. 2. 3.
SELECT ?a ?b ?c WHERE { ?a v:label "person" . ?a e:knows ?b . ?a e:created ?c . ?b e:created ?c . ?a v:age ?d . FILTER (?d <= 30) } g.V() .match ( match()-step .as(‘a’).hasLabel(‘person’), .as(‘a’).out(‘knows’).as(‘b’), .as(‘a’).out(‘created’).as(‘c’), .as(‘b’).out(‘created’).as(‘c’), .as(‘a’).values(‘age’).as(‘d’). where ('d',lte(30))). select (‘a’,’b’,’c’)
● ● gremlin> :install org.apache.tinkerpop sparql-gremlin 3.4.0 ==>Loaded: [org.apache.tinkerpop, sparql-gremlin, 3.4.0] gremlin> :plugin use tinkerpop.sparql ==>tinkerpop.sparql activated gremlin> graph = TinkerFactory.createModern() ==>tinkergraph[vertices:6 edges:6] gremlin> g = graph.traversal( SparqlTraversalSource ) ==>sparqltraversalsource[tinkergraph[vertices:6 edges:6], standard] gremlin> g.sparql("""SELECT ?name ?age WHERE { ?person v:name ?name . ?person v:age ?age } ORDER BY ASC(?age)""") ==>[name:vadas,age:27] ==>[name:marko,age:29] ==>[name:josh,age:32] ==>[name:peter,age:35]
● ● ● gremlin>g. sparql ("SELECT * WHERE { }").outE().label().dedup() ==>created ==>knows similar to … gremlin> g.cypher("MATCH (n) RETURN n").select("n").outE().label().dedup() ==>created ==>knows
● ● ● conceptual example: SELECT ?a WHERE { ?a v:label "person" . { GREMLIN(select(“a”).values(“name”)) } }
SELECT •
http://gremlinator.iai.uni-bonn.de:8080/Demo/ http://195.201.31.31:8080/Demo/ (mirror)
● ●
Cypher for Gremlin • • •
Recommend
More recommend