neo4jでsandbox その14

#概要

neo4jでsandboxやってみた。
cypherとsparqlを並べてみた。

#チートシート


| cypher | spaql|
|:--|:--|
|create|insert| 
|return|select|
|with|select in a sub query|
|match|where|
|where|filter|
|label|owl:class or rdfs;class|
|[edge]|predicate\<edge> or Triple << \<subject>\<edge>\<object> >>|
|(node)|a graph node(blank or iri node)|
|var:Person|?var a :Person|
|var:name|?name assuming a match ?var \<name> ?name|
|nodeVar:label {key value}|?nodeVar a label:<key>|
|(n)-[:r {a:b}]->m|<< ?u \<r>\<m>>>\<a> b|
|create(ee:Person {name:"Emil", from:"Sweden", klout:99 })|INSERT DATA {\<ee> a \<Person>; \<name>"Email"; \<from>"Sweden"; \<klout>99 }|
|MATCH (ee:Person) WHERE ee.name="Emil" RETURN ee;|SELECT ?ee WHERE {?ee a \<Person>; \<name>?name. Filter(name="Emil") }|
|Match (ee:Person) where ee.name = "Emil" Create (js:Person {neme:"Johan", from:"Sweden", learn:"surfing"}), (ir:Person {neme:"Ian", from:"England", title:"author"}), (rvb:Person {neme:"Rik", from:"Belgium", pet:"Orval"}), (ally:Person {neme:"Allison", from:"California", hobby:"surfing"}), (ee)-[:KNOWS {since:2001}]->(js), (ee)-[:KNOWS {rating:5}]->(ir), (js)-[:KNOWS]->(ir), (js)-[:KNOWS]->(rvb), (ir)-[:KNOWS]->(js) (ee)-[:KNOWS]->(ally), (rvb)-[:KNOWS]->(ally) | INSERT {\<js>a\<Person>; \<name>"Johan"; \<from>"Sweden"; \<lean>"surfing".\<ir>a\<Person>; \<name>"Ian"; \<from>"England"; \<title>"author". \<rvb>a\<Person>; \<name>"Rik"; \<from>"Belgium"; \<pet>"Orval". \<ally>a\<Person>; \<name>"Allison"; \<from>"California"; \<hobby>"surfing". \<<?ee\<knows>\<ir>>>\<since>"2001"^^xsd:string. <<?ee\<knows>\<ir>>>\<rating>"5"^^xsd:string. \<js>\<knows>\<ir>. \<js>\<knows>\<rvb>. \<ir>\<knows>\<js>. \<ir>\<knows>\<ally>. \<rvb>\<knows>\<ally> } where {?ee a \<Person>; \<name>"Emil" } |
|Match (ee:Person)-[:KNOWS]-(friends) WHERE ee.name="Emil" RETURN ee, friends | SELECT ?ee ?friends WHERE { ?ee a \<person>; \<neme>"Emil"; \<knows>?friends } |
|Match (js:Person)-[:KNOWS]-()-[:KNOWS]-(surfer) WHERE js.name = "Johan" AND suefer.hobby = "surfing" RETURN distinct surfer | SELECT distinct ?surfer WHERE { ?js a \<Person>; \<name>"johan";\<knows>/\<knows>?surfer; ?surfer\<hobby>"surfing". } |
|Match(tom {name:"Tom Hanks"}) return tom|select ?tom where {?tom \<name>"Tom Hanks" } |
|Match(cloundAtlas {title:"Clound Atlas"}) return cloudAtlas|select ?cloundAtlas where {?cloundAtlas \<title>"Clound Atlas" } |
|Match(people:Person) return people.name limit 10|select ?name where {?people a\<person>; \<name>?name. } limit 10|
|Match (nineties:Movie) WHERE nineties.released > 1990 AND nineties.released < 2000 return nineties.title|select ?title where { ?nineties a \<Movie>; \<released> ?released; \<title>?title. FILTER (?released > 1990 && ?released < 2000) }|
|MATCH (tom:Person{name:"Tom Hanks"})-[:ACTED_IN]-(tomHanksMovies) RETURN tom, tomHanksMovies | SELECT ?tom?tomHanksMovies WHERE {?tom a \<Person>; \<name>"Tom Hanks";	\<ACTED_IN>?tomHanksMovies }|
|MATCH (cloudAtlas {title:"Cloud Atlas"})-[:DIRECTED]-(direstors) RETURN directors.name|SELECT ?name WHERE { ?cloudAtlas\<title>"Cloud Atlas"; ^\<DIRECTED>?directors. directors\<name>?name }|
|MATCH(tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors)RETURN coActors.name|SELECT ?name WHERE { ?tom a \<Person>; \<ACTED_IN>?m. ?coActors\<ACTED_IN>?m; <name>?name. FILTER(?tom != ?coActors) }|
|MATCH (people:Person)-[relatedTo]-(:Movie {title:"Cloud Atlas"}) RETURN people.name, Type(relateTo), relatedTo|SELECT ?name ?relateTo WHERE {?people a \<Person>. ?people?relatedTo?movie. ?movie\<title>"Cloud Atlas". }|




以上。