[Neo4j] Cypher questions
Hello, I have some questions regarding Cypher. 1. I have an ontology that defines classes and individuals. I store this ontology into Neo4J REST db. Is there any ways to find all individuals that have some given class? In SPARQL, it can be done like ...WHERE { ?u a :User.}... to find all instances that have a type of User. 2. Similar to the question#1, if I understand correctly in Cypher I always have to start with a known node either by its ID or name. If so how to find any nodes that have some given relationship? For example, I want to find any nodes that have the the relationship type go_to_school. (x)-[:go_to_school]-(n) where (n.name= NotreDame) return x Thank you, ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Cypher questions
Both your questions would be answered with indexing: for the 1) you would add the user nodes them to a User index and then use start user=node:User(id:*) ... For 2) you would index the relationships-similarly (for the interesting types). e.g. create an index for only the rel-type you're interested in: index().forRelationships(go_to_school).add(rel, key,value) key and value are arbitrary things, but you might leverage them with sensible data in your domain model. start r = relationship:go_to_school(field:*) match (x)-[r]-(n) where n.name = Notre Dame return x !! usually you would probably rather index the schools, and look them up directly start school = node:schools(name,{school_name}) match pupil-[:go_to_school]-school return pupil (You could use auto-indexing for both if that is useful for you, the index-names would then be node_auto_index and relationship_auto_index, see : http://docs.neo4j.org/chunked/snapshot/auto-indexing.htmlhttp://docs.neo4j.org/chunked/snapshot/rest-api-auto-indexes.html ) Am 03.11.2011 um 00:35 schrieb andrew ton: Hello, I have some questions regarding Cypher. 1. I have an ontology that defines classes and individuals. I store this ontology into Neo4J REST db. Is there any ways to find all individuals that have some given class? In SPARQL, it can be done like ...WHERE { ?u a :User.}... to find all instances that have a type of User. 2. Similar to the question#1, if I understand correctly in Cypher I always have to start with a known node either by its ID or name. If so how to find any nodes that have some given relationship? For example, I want to find any nodes that have the the relationship type go_to_school. (x)-[:go_to_school]-(n) where (n.name= NotreDame) return x Thank you, ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Cypher questions
Andrew, we have been trying to keep things very tight and document most of the functionality in the manual. See even some domain examples that have Cypher in them, http://docs.neo4j.org/chunked/snapshot/domain-modeling-gallery.html What else would you like to see? Cheers, /peter neubauer GTalk: neubauer.peter Skype peter.neubauer Phone +46 704 106975 LinkedIn http://www.linkedin.com/in/neubauer Twitter http://twitter.com/peterneubauer http://www.neo4j.org - NOSQL for the Enterprise. http://startupbootcamp.org/ - Öresund - Innovation happens HERE. On Wed, Nov 2, 2011 at 7:32 PM, andrew ton andrewt...@yahoo.com wrote: Hi Michael, Thank you very much! Your answers are very helpful to me. Although I have read the manual enclosed in the neo4j package I downloaded I did not know that we can use * wildcard for any ids or names. Besides the manual what other resources can I find to understand more about Cypher? Appreciated your help. A. From: Michael Hunger michael.hun...@neotechnology.com To: Neo4j user discussions user@lists.neo4j.org Sent: Wednesday, November 2, 2011 5:31 PM Subject: Re: [Neo4j] Cypher questions Both your questions would be answered with indexing: for the 1) you would add the user nodes them to a User index and then use start user=node:User(id:*) ... For 2) you would index the relationships-similarly (for the interesting types). e.g. create an index for only the rel-type you're interested in: index().forRelationships(go_to_school).add(rel, key,value) key and value are arbitrary things, but you might leverage them with sensible data in your domain model. start r = relationship:go_to_school(field:*) match (x)-[r]-(n) where n.name = Notre Dame return x !! usually you would probably rather index the schools, and look them up directly start school = node:schools(name,{school_name}) match pupil-[:go_to_school]-school return pupil (You could use auto-indexing for both if that is useful for you, the index-names would then be node_auto_index and relationship_auto_index, see : http://docs.neo4j.org/chunked/snapshot/auto-indexing.htmlhttp://docs.neo4j.org/chunked/snapshot/rest-api-auto-indexes.html ) Am 03.11.2011 um 00:35 schrieb andrew ton: Hello, I have some questions regarding Cypher. 1. I have an ontology that defines classes and individuals. I store this ontology into Neo4J REST db. Is there any ways to find all individuals that have some given class? In SPARQL, it can be done like ...WHERE { ?u a :User.}... to find all instances that have a type of User. 2. Similar to the question#1, if I understand correctly in Cypher I always have to start with a known node either by its ID or name. If so how to find any nodes that have some given relationship? For example, I want to find any nodes that have the the relationship type go_to_school. (x)-[:go_to_school]-(n) where (n.name= NotreDame) return x Thank you, ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Cypher questions
the Neo4j-indexing provider (which is also used by Cypher) is lucene, so the default lucene query syntax works in the neo4j core API and Cypher queries. http://lucene.apache.org/java/3_4_0/queryparsersyntax.html Michael Am 03.11.2011 um 03:32 schrieb andrew ton: Hi Michael, Thank you very much! Your answers are very helpful to me. Although I have read the manual enclosed in the neo4j package I downloaded I did not know that we can use * wildcard for any ids or names. Besides the manual what other resources can I find to understand more about Cypher? Appreciated your help. A. From: Michael Hunger michael.hun...@neotechnology.com To: Neo4j user discussions user@lists.neo4j.org Sent: Wednesday, November 2, 2011 5:31 PM Subject: Re: [Neo4j] Cypher questions Both your questions would be answered with indexing: for the 1) you would add the user nodes them to a User index and then use start user=node:User(id:*) ... For 2) you would index the relationships-similarly (for the interesting types). e.g. create an index for only the rel-type you're interested in: index().forRelationships(go_to_school).add(rel, key,value) key and value are arbitrary things, but you might leverage them with sensible data in your domain model. start r = relationship:go_to_school(field:*) match (x)-[r]-(n) where n.name = Notre Dame return x !! usually you would probably rather index the schools, and look them up directly start school = node:schools(name,{school_name}) match pupil-[:go_to_school]-school return pupil (You could use auto-indexing for both if that is useful for you, the index-names would then be node_auto_index and relationship_auto_index, see : http://docs.neo4j.org/chunked/snapshot/auto-indexing.htmlhttp://docs.neo4j.org/chunked/snapshot/rest-api-auto-indexes.html ) Am 03.11.2011 um 00:35 schrieb andrew ton: Hello, I have some questions regarding Cypher. 1. I have an ontology that defines classes and individuals. I store this ontology into Neo4J REST db. Is there any ways to find all individuals that have some given class? In SPARQL, it can be done like ...WHERE { ?u a :User.}... to find all instances that have a type of User. 2. Similar to the question#1, if I understand correctly in Cypher I always have to start with a known node either by its ID or name. If so how to find any nodes that have some given relationship? For example, I want to find any nodes that have the the relationship type go_to_school. (x)-[:go_to_school]-(n) where (n.name= NotreDame) return x Thank you, ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user