Re: [Neo4j] Spring Data Graph / Neo4j – Problems with OO Inheritance Polymorphism relation semantics
Thank you Michael - wish you 'll have a great conference we're all looking forward for the online materials :-) On Wed, Oct 26, 2011 at 8:14 PM, Michael Hunger michael.hun...@neotechnology.com wrote: Angelos, I'm currently at SpringOne and quite swamped, I get back to you as soon as possible. Michael Am 26.10.2011 um 04:30 schrieb Agelos Pikoulas: On my previous email please excuse my confusing Person, the example should clearly be like this : * * *@NodeEntity public class Content {}* * * *@NodeEntity public class ExtContent extends Content {}* *@NodeEntity public class Person { @RelatedToVia(elementClass = Person.class, type = LIKES, direction = Direction.OUTGOING) private SetPerson likedPersons; public SetPerson getLikedPersons() {return likedPersons;} @RelatedToVia(elementClass = Content.class, type = LIKES, direction = Direction.OUTGOING) private SetContent likedContent; public SetContent getLikedContent() { return likedContent; } } *I am attaching the code, if someone can github it cause my eclipse plugin refuses to do so :-(* * On Wed, Oct 26, 2011 at 12:54 AM, Agelos Pikoulas agelos.pikou...@gmail.com wrote: Hi to all graphistas, I have two issues, a major and a minor : 1) 1) Starting with SDG 1.0/1.1, I have been developing a MetaModel (and a generator hopefully later a MetaMetaModel:) and I have been facing walls in regards to @NodeEntity / NodeBacked classes inheritance and their related @RelatedXXX feature set. To the specifics, when a @NodeEntity class extends another, there is limited support to how these can consistently be related to other nodes (and retrieved) based not just on the RelationShip name, but also on their class (and inheritance/subclass tree). To better describe things, look at this simplistic example : I have @NodeEntity public class Content {} @NodeEntity public class ExtContent extends Content {} and @NodeEntity public class Person { public SetPerson getLikedPersons() {return likedPersons;} @RelatedToVia(elementClass = Person.class, type = LIKES, direction = Direction.OUTGOING) private SetPerson likedPersons; public IterableContent getLikedContent() { return likedContent; } @Query (start n=node({self}) match (n) -[:LIKES]-(content) return content) @RelatedToVia(elementClass = Content.class, type = LIKES, direction = Direction.OUTGOING) private IterableContent likedContent; } As you can see, I want Person object/nodes to 'LIKES' other Person objects, or Content objects (and below in the inheritance tree, such as ExtContent) : @Test public void oo_testing() { Person p1 = new Person().persist(); Person p2 = new Person().persist(); Content c1 = new Content().persist(); ExtContent c2 = new ExtContent().persist(); p1.relateTo(c1, LIKES); p1.relateTo(c2, LIKES); p1.relateTo(p2, LIKES); for (Content cc : p1.getLikedContent()) logger.warn(Class : + cc.getClass().getName() + , __type__ : + cc.getPersistentState().getProperty(__type__)); assertEquals(LikedContent objects are 2, 2, p1.getLikedContent().size()); // fails, cause it returns all of 'LIKES' related nodes } In version 1.1.RELEASE, retrieving any of the collections fails at rutime (can't recall the Exception, but it was the sort of wrong class found). In version 2.0.0.M1 today's 2.0.0.BUILD-SNAPSHOT, getLikedPersons() getLikedContent() both contain ALL nodes that are related via 'LIKES' relationship, irrespective of class. So, this is what p1.getLikedContent() contains : Class : sdnTests.domain.Content, __type__ : sdnTests.domain.Person Class : sdnTests.domain.Content, __type__ : sdnTests.domain.Content Class : sdnTests.domain.ExtContent, __type__ : sdnTests.domain.ExtContent One would expect that since elementClass defines the class of nodes to fill the collection with, this it would be obeyed. To a better extend, IterableContent likedContent should contain all object/nodes of type Content AND Content subclasses (eg ExtContent), since do we have this type information. The same lacking of OO/polymorphism exists with repositories, as discussed here http://lists.neo4j.org/pipermail/user/2011-October/012654.html (haven’t tested this with 2.0.0.M01, I m still on 1.1) One can overcome these problems by hand on top of SDN, but I guess it wouldn't be very elegant efficient - I think SDN should inherently allow these OO/polymorphic features and emerge itself as a lean robust OO + Graph repository. 2) 2) The minor issue I have regards (the otherwise brilliant) @Query, due to
[Neo4j] Transaction and REST API
Hi Ido, How will you go about implement such change using REST interface? With the current default REST interface, you can't. But you can write an extension (either in the managed framework, or if you're brave/desperate in the unmanaged framework through JAX-RS) which can do this. I imagine you might give such a resource the name: .../products When you POST a new product representation to the /products resource, under the covers it creates both a new node that represents your product and inserts the relationship into the DB too. Another example in the same area is suppose I want to change 2 links, say change a category from been sub-category to another sub-category and let's say it involve delete one link and create another. Same deal, although the discovery is a little trickier here. If you were to do this in a sane way, I'd suggest filling in a form, which contains the URI of the relationship to be deleted, plus the information needed to create a new relationship. POST that form to a resource representing the graph and you're done. I'm trying to see if there is a generic way to implement such things of changing multiple resources in generic manager in REST or is it simply to application (or service) specific. I think they're mostly going to be application specific. That's why we have the two ways of extending the server (warning: the JAX-RS way really is a sharp tool, be careful). But if the community notices useful patterns emerging, then we could think about rolling them up into a general extensions package (rather like the very useful graph algos package). So a plea to the community: if you extend the server in any cool and useful way, let the group know and we'll perhaps get a rest-contrib project running. Happy new year everybody! Kristen Eisenberg Billige Flüge Marketing GmbH Emanuelstr. 3, 10317 Berlin Deutschland Telefon: +49 (33) 5310967 Email: utebachmeier at gmail.com Site: http://flug.airego.de - Billige Flüge vergleichen ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
[Neo4j] Primary Like ID Across Class Types
Hi, I noted in playing with spring-data-neo4j that the Node's under neo4j Don't have an ID key like typically we would in an RDBMS scenario. My use case, in short is the application I will be building out will have, a really simple Web Interface with REST type URLs. So .. for example, I will be able to do http://myservice.co.uk/superwebapp/mySpecialThing/detailedView/55 The 55 there will result in a query to Neo4J to locate the MySpecialThing object with ID of type 55 and display it. So to ensure I have a per concrete domain POJO, a set ID, I created a simple ID manager setup. The thought (for the alpha version) is, that on invoking getId() for the object, an aspect wrapper around it looks to see if it has an id (if it's null) and if not, it goes and creates an ID from a singleton bean manager, which in turn loads from neo4j Or looks into a cache, for an IdObject(ClassName) which has getNextId() on it. It's not beautiful but practical. The unit tests work all good. I considered using a UUID as the ID, but I know you do get to use the simpler numbers practically more. I did not want to use NodeId as these are repository wide. Any thoughts ? My one thought is that the getId() Aspect probably should be on persist() or somewhere deeper. Such that the id is actually created on storage. (conjures up needs to check the Id for clashes etc .. ewww). you will find the post over at http://rbtech.blogspot.com with the suitable code. -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Primary-Like-ID-Across-Class-Types-tp3457270p3457270.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Primary Like ID Across Class Types
I have posted the relevant code online, interested to see what people think. like - man you just over-engineered that ! http://rbtech.blogspot.com/2011/10/neo4j-2nd-look-setting-primary-key-on.html -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Primary-Like-ID-Across-Class-Types-tp3457270p3457359.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] neo4j-advanced-1.5.M02 can`t run in Windows 7 64 bit
What JDK are you using ? Where is the path E:\document\neo4j\Neo4j\neo4j-advanced-1.5.M02\data\graph.db\neostore ? Is that a network path as the error message looks a bit suspicious. I do have Windows 7 64bit so can try it later. -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/neo4j-advanced-1-5-M02-can-t-run-in-Windows-7-64-bit-tp3440480p3457394.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] neo4j-advanced-1.5.M02 can`t run in Windows 7 64 bit
The error messages indicates that the database is already open. Is Neoclipse open or another instance of the server running? Or some code that is opening the database in embedded mode? -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of rbuckland Sent: Thursday, October 27, 2011 7:55 AM To: user@lists.neo4j.org Subject: Re: [Neo4j] neo4j-advanced-1.5.M02 can`t run in Windows 7 64 bit What JDK are you using ? Where is the path E:\document\neo4j\Neo4j\neo4j-advanced-1.5.M02\data\graph.db\neostore ? Is that a network path as the error message looks a bit suspicious. I do have Windows 7 64bit so can try it later. -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/neo4j-advanced-1-5-M02-can-t-run-in-Windows-7-64-bit-tp3440480p3457394.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ 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] Function to check whether two nodes are connected?
Hello there! First of all, thanks for the help in all my previous questions, all the answers have been helping me to use Neo4j with success. I have a very simple question, but I haven't found the answer yet... I'd like to have a function, which signature would be more or less like this: public areTheyConnected(Node *n1*,Node *n2*,Relationship *rel*,Direction *dir*) which returns true iff there is an edge of type *rel*, between *n1* and *n2*, in the *dir* direction (the direction has n1 as reference). Example: In my graph, I have: Bob knows Tom, Tom knows Peter, Jack knows Tom areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING) returns true; (Bob knows Tom) areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also returns true; (Jack knows Tom) areTheyConnected(nodeBob,nodeTom,relKnows,Direction.INCOMING) returns false; (Tom doesn't know Bob) Is there an easy method (constant time, or close) for that? Thank you very much, Bruno ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Function to check whether two nodes are connected?
Bruno, There is no such function low level, but toy can use a Shortest path algo to check this. What is the maximum length for a path between the nodes? On Oct 27, 2011 6:14 PM, Bruno Paiva Lima da Silva bplsi...@gmail.com wrote: Hello there! First of all, thanks for the help in all my previous questions, all the answers have been helping me to use Neo4j with success. I have a very simple question, but I haven't found the answer yet... I'd like to have a function, which signature would be more or less like this: public areTheyConnected(Node *n1*,Node *n2*,Relationship *rel*,Direction *dir*) which returns true iff there is an edge of type *rel*, between *n1* and *n2*, in the *dir* direction (the direction has n1 as reference). Example: In my graph, I have: Bob knows Tom, Tom knows Peter, Jack knows Tom areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING) returns true; (Bob knows Tom) areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also returns true; (Jack knows Tom) areTheyConnected(nodeBob,nodeTom,relKnows,Direction.INCOMING) returns false; (Tom doesn't know Bob) Is there an easy method (constant time, or close) for that? Thank you very much, Bruno ___ 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] Transaction and REST API
Yes, + 1 on contributions of useful rest plugins. I would like to see them listed in the manual, and keep the docs somewhere central. Suggestions? On Oct 27, 2011 12:35 PM, Kristen Eisenberg kristen.eisenb...@yahoo.com wrote: Hi Ido, How will you go about implement such change using REST interface? With the current default REST interface, you can't. But you can write an extension (either in the managed framework, or if you're brave/desperate in the unmanaged framework through JAX-RS) which can do this. I imagine you might give such a resource the name: .../products When you POST a new product representation to the /products resource, under the covers it creates both a new node that represents your product and inserts the relationship into the DB too. Another example in the same area is suppose I want to change 2 links, say change a category from been sub-category to another sub-category and let's say it involve delete one link and create another. Same deal, although the discovery is a little trickier here. If you were to do this in a sane way, I'd suggest filling in a form, which contains the URI of the relationship to be deleted, plus the information needed to create a new relationship. POST that form to a resource representing the graph and you're done. I'm trying to see if there is a generic way to implement such things of changing multiple resources in generic manager in REST or is it simply to application (or service) specific. I think they're mostly going to be application specific. That's why we have the two ways of extending the server (warning: the JAX-RS way really is a sharp tool, be careful). But if the community notices useful patterns emerging, then we could think about rolling them up into a general extensions package (rather like the very useful graph algos package). So a plea to the community: if you extend the server in any cool and useful way, let the group know and we'll perhaps get a rest-contrib project running. Happy new year everybody! Kristen Eisenberg Billige Flüge Marketing GmbH Emanuelstr. 3, 10317 Berlin Deutschland Telefon: +49 (33) 5310967 Email: utebachmeier at gmail.com Site: http://flug.airego.de - Billige Flüge vergleichen ___ 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] Function to check whether two nodes are connected?
Easy: just one. For now, I've written this, but I'm still not sure it is the simplest way to write it public boolean areConnected(Node n1,Node n2,Relationship rel,Direction dir) throws Exception { IterableRelationship relationships = n1.getRelationships(dir); for (Relationship r : relationships) { //I am only working with Dynamic Relationships if (r.getType().equals(rel.getType())) { if (dir == Direction.OUTGOING) { if (r.getEndNode().equals(n2)) { return true; } } else { if (r.getStartNode().equals(n2)) { return true; } } } } return false; } Bruno Le 27/10/2011 18:31, Peter Neubauer a écrit : Bruno, There is no such function low level, but toy can use a Shortest path algo to check this. What is the maximum length for a path between the nodes? On Oct 27, 2011 6:14 PM, Bruno Paiva Lima da Silvabplsi...@gmail.com wrote: Hello there! First of all, thanks for the help in all my previous questions, all the answers have been helping me to use Neo4j with success. I have a very simple question, but I haven't found the answer yet... I'd like to have a function, which signature would be more or less like this: public areTheyConnected(Node *n1*,Node *n2*,Relationship *rel*,Direction *dir*) which returns true iff there is an edge of type *rel*, between *n1* and *n2*, in the *dir* direction (the direction has n1 as reference). Example: In my graph, I have: Bob knows Tom, Tom knows Peter, Jack knows Tom areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING) returns true; (Bob knows Tom) areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also returns true; (Jack knows Tom) areTheyConnected(nodeBob,nodeTom,relKnows,Direction.INCOMING) returns false; (Tom doesn't know Bob) Is there an easy method (constant time, or close) for that? Thank you very much, Bruno ___ 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] Function to check whether two nodes are connected?
There is one caveat to this method, you'd have to know which node is most densely connected. Suppose one of the nodes has 100,000 relationships (incoming and outgoing) and the other node has only a few relationships, then you'd want to iterate over the relationships of the second node. A solution could be to iterate over both sets of relationships at the same time: public boolean areConnected(Node n1,Node n2, RelationshipType relType,Direction dir) { IteratorRelatiionship rels1 = n1.getRelationships(relType, dir).iterator(); IteratorRelatiionship rels2 = n2.getRelationships(relType, dir).iterator(); while(rels1.hasNext rels2.hasNext){ Relationship rel1 = rels1.next(); Relationship rel2 = rels2.next(); if (rel1.getEndNode().equals(n2) return true; else if (rel2.getEndNode().equals(n1)) return true; } return false; } Date: Thu, 27 Oct 2011 18:39:01 +0200 From: bplsi...@gmail.com To: user@lists.neo4j.org Subject: Re: [Neo4j] Function to check whether two nodes are connected? Easy: just one. For now, I've written this, but I'm still not sure it is the simplest way to write it public boolean areConnected(Node n1,Node n2,Relationship rel,Direction dir) throws Exception { IterableRelationship relationships = n1.getRelationships(dir); for (Relationship r : relationships) { //I am only working with Dynamic Relationships if (r.getType().equals(rel.getType())) { if (dir == Direction.OUTGOING) { if (r.getEndNode().equals(n2)) { return true; } } else { if (r.getStartNode().equals(n2)) { return true; } } } } return false; } Bruno Le 27/10/2011 18:31, Peter Neubauer a écrit : Bruno, There is no such function low level, but toy can use a Shortest path algo to check this. What is the maximum length for a path between the nodes? On Oct 27, 2011 6:14 PM, Bruno Paiva Lima da Silvabplsi...@gmail.com wrote: Hello there! First of all, thanks for the help in all my previous questions, all the answers have been helping me to use Neo4j with success. I have a very simple question, but I haven't found the answer yet... I'd like to have a function, which signature would be more or less like this: public areTheyConnected(Node *n1*,Node *n2*,Relationship *rel*,Direction *dir*) which returns true iff there is an edge of type *rel*, between *n1* and *n2*, in the *dir* direction (the direction has n1 as reference). Example: In my graph, I have: Bob knows Tom, Tom knows Peter, Jack knows Tom areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING) returns true; (Bob knows Tom) areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also returns true; (Jack knows Tom) areTheyConnected(nodeBob,nodeTom,relKnows,Direction.INCOMING) returns false; (Tom doesn't know Bob) Is there an easy method (constant time, or close) for that? Thank you very much, Bruno ___ 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] Function to check whether two nodes are connected?
I see I made a bit of a mistake with this one. The gist of the solution remains, but I made a mistake dealing with the directions of relationship. It should be something like this. public boolean areConnected(Node n1,Node n2, RelationshipType relType,Direction dir) { Direction dir2 = null; if(dir.equals(Direction.INCOMING)) dir2 = Direction.OUTGOING; else if(dir.equals(Direction.OUTGOING)) dir2 = Direction.INCOMING; else dir2 = Direction.BOTH; IteratorRelationship rels1 = n1.getRelationships(relType, dir).iterator(); IteratorRelationship rels2 = n2.getRelationships(relType, dir2).iterator(); while(rels1.hasNext rels2.hasNext){ Relationship rel1 = rels1.next(); Relationship rel2 = rels2.next(); if (rel1.getEndNode().equals(n2) return true; else if (rel2.getEndNode().equals(n1)) return true; } return false; } From: pd_aficion...@hotmail.com To: user@lists.neo4j.org Date: Thu, 27 Oct 2011 19:05:16 +0200 Subject: Re: [Neo4j] Function to check whether two nodes are connected? There is one caveat to this method, you'd have to know which node is most densely connected. Suppose one of the nodes has 100,000 relationships (incoming and outgoing) and the other node has only a few relationships, then you'd want to iterate over the relationships of the second node. A solution could be to iterate over both sets of relationships at the same time: public boolean areConnected(Node n1,Node n2, RelationshipType relType,Direction dir) { IteratorRelatiionship rels1 = n1.getRelationships(relType, dir).iterator(); IteratorRelatiionship rels2 = n2.getRelationships(relType, dir).iterator(); while(rels1.hasNext rels2.hasNext){ Relationship rel1 = rels1.next(); Relationship rel2 = rels2.next(); if (rel1.getEndNode().equals(n2) return true; else if (rel2.getEndNode().equals(n1)) return true; } return false; } Date: Thu, 27 Oct 2011 18:39:01 +0200 From: bplsi...@gmail.com To: user@lists.neo4j.org Subject: Re: [Neo4j] Function to check whether two nodes are connected? Easy: just one. For now, I've written this, but I'm still not sure it is the simplest way to write it public boolean areConnected(Node n1,Node n2,Relationship rel,Direction dir) throws Exception { IterableRelationship relationships = n1.getRelationships(dir); for (Relationship r : relationships) { //I am only working with Dynamic Relationships if (r.getType().equals(rel.getType())) { if (dir == Direction.OUTGOING) { if (r.getEndNode().equals(n2)) { return true; } } else { if (r.getStartNode().equals(n2)) { return true; } } } } return false; } Bruno Le 27/10/2011 18:31, Peter Neubauer a écrit : Bruno, There is no such function low level, but toy can use a Shortest path algo to check this. What is the maximum length for a path between the nodes? On Oct 27, 2011 6:14 PM, Bruno Paiva Lima da Silvabplsi...@gmail.com wrote: Hello there! First of all, thanks for the help in all my previous questions, all the answers have been helping me to use Neo4j with success. I have a very simple question, but I haven't found the answer yet... I'd like to have a function, which signature would be more or less like this: public areTheyConnected(Node *n1*,Node *n2*,Relationship *rel*,Direction *dir*) which returns true iff there is an edge of type *rel*, between *n1* and *n2*, in the *dir* direction (the direction has n1 as reference). Example: In my graph, I have: Bob knows Tom, Tom knows Peter, Jack knows Tom areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING) returns true; (Bob knows Tom) areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also returns true; (Jack knows Tom) areTheyConnected(nodeBob,nodeTom,relKnows,Direction.INCOMING) returns false; (Tom doesn't know Bob) Is there an easy method (constant time, or close) for that? Thank you very much, Bruno ___ 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 ___ Neo4j mailing list User@lists.neo4j.org
Re: [Neo4j] Function to check whether two nodes are connected?
Good catch Niels, thanks - my brain is in jet lag mode :-\ On Oct 27, 2011 7:26 PM, Niels Hoogeveen pd_aficion...@hotmail.com wrote: I see I made a bit of a mistake with this one. The gist of the solution remains, but I made a mistake dealing with the directions of relationship. It should be something like this. public boolean areConnected(Node n1,Node n2, RelationshipType relType,Direction dir) { Direction dir2 = null; if(dir.equals(Direction.INCOMING)) dir2 = Direction.OUTGOING; else if(dir.equals(Direction.OUTGOING)) dir2 = Direction.INCOMING; else dir2 = Direction.BOTH; IteratorRelationship rels1 = n1.getRelationships(relType, dir).iterator(); IteratorRelationship rels2 = n2.getRelationships(relType, dir2).iterator(); while(rels1.hasNext rels2.hasNext){ Relationship rel1 = rels1.next(); Relationship rel2 = rels2.next(); if (rel1.getEndNode().equals(n2) return true; else if (rel2.getEndNode().equals(n1)) return true; } return false; } From: pd_aficion...@hotmail.com To: user@lists.neo4j.org Date: Thu, 27 Oct 2011 19:05:16 +0200 Subject: Re: [Neo4j] Function to check whether two nodes are connected? There is one caveat to this method, you'd have to know which node is most densely connected. Suppose one of the nodes has 100,000 relationships (incoming and outgoing) and the other node has only a few relationships, then you'd want to iterate over the relationships of the second node. A solution could be to iterate over both sets of relationships at the same time: public boolean areConnected(Node n1,Node n2, RelationshipType relType,Direction dir) { IteratorRelatiionship rels1 = n1.getRelationships(relType, dir).iterator(); IteratorRelatiionship rels2 = n2.getRelationships(relType, dir).iterator(); while(rels1.hasNext rels2.hasNext){ Relationship rel1 = rels1.next(); Relationship rel2 = rels2.next(); if (rel1.getEndNode().equals(n2) return true; else if (rel2.getEndNode().equals(n1)) return true; } return false; } Date: Thu, 27 Oct 2011 18:39:01 +0200 From: bplsi...@gmail.com To: user@lists.neo4j.org Subject: Re: [Neo4j] Function to check whether two nodes are connected? Easy: just one. For now, I've written this, but I'm still not sure it is the simplest way to write it public boolean areConnected(Node n1,Node n2,Relationship rel,Direction dir) throws Exception { IterableRelationship relationships = n1.getRelationships(dir); for (Relationship r : relationships) { //I am only working with Dynamic Relationships if (r.getType().equals(rel.getType())) { if (dir == Direction.OUTGOING) { if (r.getEndNode().equals(n2)) { return true; } } else { if (r.getStartNode().equals(n2)) { return true; } } } } return false; } Bruno Le 27/10/2011 18:31, Peter Neubauer a écrit : Bruno, There is no such function low level, but toy can use a Shortest path algo to check this. What is the maximum length for a path between the nodes? On Oct 27, 2011 6:14 PM, Bruno Paiva Lima da Silva bplsi...@gmail.com wrote: Hello there! First of all, thanks for the help in all my previous questions, all the answers have been helping me to use Neo4j with success. I have a very simple question, but I haven't found the answer yet... I'd like to have a function, which signature would be more or less like this: public areTheyConnected(Node *n1*,Node *n2*,Relationship *rel*,Direction *dir*) which returns true iff there is an edge of type *rel*, between *n1* and *n2*, in the *dir* direction (the direction has n1 as reference). Example: In my graph, I have: Bob knows Tom, Tom knows Peter, Jack knows Tom areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING) returns true; (Bob knows Tom) areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also returns true; (Jack knows Tom) areTheyConnected(nodeBob,nodeTom,relKnows,Direction.INCOMING) returns false; (Tom doesn't know Bob) Is there an easy method (constant time, or close) for that? Thank you very much, Bruno ___ 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
Re: [Neo4j] Function to check whether two nodes are connected?
You know me and my obsession for densely connected nodes :-) Date: Thu, 27 Oct 2011 17:37:07 + From: peter.neuba...@neotechnology.com To: user@lists.neo4j.org Subject: Re: [Neo4j] Function to check whether two nodes are connected? Good catch Niels, thanks - my brain is in jet lag mode :-\ On Oct 27, 2011 7:26 PM, Niels Hoogeveen pd_aficion...@hotmail.com wrote: I see I made a bit of a mistake with this one. The gist of the solution remains, but I made a mistake dealing with the directions of relationship. It should be something like this. public boolean areConnected(Node n1,Node n2, RelationshipType relType,Direction dir) { Direction dir2 = null; if(dir.equals(Direction.INCOMING)) dir2 = Direction.OUTGOING; else if(dir.equals(Direction.OUTGOING)) dir2 = Direction.INCOMING; else dir2 = Direction.BOTH; IteratorRelationship rels1 = n1.getRelationships(relType, dir).iterator(); IteratorRelationship rels2 = n2.getRelationships(relType, dir2).iterator(); while(rels1.hasNext rels2.hasNext){ Relationship rel1 = rels1.next(); Relationship rel2 = rels2.next(); if (rel1.getEndNode().equals(n2) return true; else if (rel2.getEndNode().equals(n1)) return true; } return false; } From: pd_aficion...@hotmail.com To: user@lists.neo4j.org Date: Thu, 27 Oct 2011 19:05:16 +0200 Subject: Re: [Neo4j] Function to check whether two nodes are connected? There is one caveat to this method, you'd have to know which node is most densely connected. Suppose one of the nodes has 100,000 relationships (incoming and outgoing) and the other node has only a few relationships, then you'd want to iterate over the relationships of the second node. A solution could be to iterate over both sets of relationships at the same time: public boolean areConnected(Node n1,Node n2, RelationshipType relType,Direction dir) { IteratorRelatiionship rels1 = n1.getRelationships(relType, dir).iterator(); IteratorRelatiionship rels2 = n2.getRelationships(relType, dir).iterator(); while(rels1.hasNext rels2.hasNext){ Relationship rel1 = rels1.next(); Relationship rel2 = rels2.next(); if (rel1.getEndNode().equals(n2) return true; else if (rel2.getEndNode().equals(n1)) return true; } return false; } Date: Thu, 27 Oct 2011 18:39:01 +0200 From: bplsi...@gmail.com To: user@lists.neo4j.org Subject: Re: [Neo4j] Function to check whether two nodes are connected? Easy: just one. For now, I've written this, but I'm still not sure it is the simplest way to write it public boolean areConnected(Node n1,Node n2,Relationship rel,Direction dir) throws Exception { IterableRelationship relationships = n1.getRelationships(dir); for (Relationship r : relationships) { //I am only working with Dynamic Relationships if (r.getType().equals(rel.getType())) { if (dir == Direction.OUTGOING) { if (r.getEndNode().equals(n2)) { return true; } } else { if (r.getStartNode().equals(n2)) { return true; } } } } return false; } Bruno Le 27/10/2011 18:31, Peter Neubauer a écrit : Bruno, There is no such function low level, but toy can use a Shortest path algo to check this. What is the maximum length for a path between the nodes? On Oct 27, 2011 6:14 PM, Bruno Paiva Lima da Silva bplsi...@gmail.com wrote: Hello there! First of all, thanks for the help in all my previous questions, all the answers have been helping me to use Neo4j with success. I have a very simple question, but I haven't found the answer yet... I'd like to have a function, which signature would be more or less like this: public areTheyConnected(Node *n1*,Node *n2*,Relationship *rel*,Direction *dir*) which returns true iff there is an edge of type *rel*, between *n1* and *n2*, in the *dir* direction (the direction has n1 as reference). Example: In my graph, I have: Bob knows Tom, Tom knows Peter, Jack knows Tom areTheyConnected(nodeBob,nodeTom,relKnows,Direction.OUTGOING) returns true; (Bob knows Tom) areTheyConnected(nodeTom,nodeJack,relKnows,Direction.INCOMING) also returns true; (Jack knows Tom) areTheyConnected(nodeBob,nodeTom,relKnows,Direction.INCOMING) returns false; (Tom doesn't know Bob) Is there an easy method (constant time, or close) for that? Thank you very much, Bruno ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] 1.5M02 failed to start on reboot
Chris, my servers are not in HA, i have two dev servers and one uat server all running the community edition with one dev server running two services at the same time. the issue was on the uat server. i will send you the files you requested i deleted the data directory because i had an issue moving from 1.4 to 1.5.01 (completely separate from this issue) and noticed that if i deleted the directory a new one would be generated and the server started. so i gave it a try again to see if the data files were the cause this time, no magic here. thanks -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/1-5M02-failed-to-start-on-reboot-tp3455296p3458588.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Spring Data Graph / Neo4j – Problems with OO Inheritance Polymorphism relation semantics
Hi Agelos Regarding your 2nd point: 2) 2) The minor issue I have regards (the otherwise brilliant) @Query, due to its constraint of annotating (mainly) Iterable and NOT allowing Set, List etc (a runtime exception is thrown org.springframework.data.neo4j.conversion.QueryResultBuilder$1 cannot be cast to java.util.List). This wouldn’t be a huge problem, but the JSP/JSLT forEach tag DOESNOT iterate Iterable (!!!), nor you can directly call .iterator() from within JSP, making life hard on both ends. From the controller, just pass the iterator of the iterable to your JSP. With Spring MVC, this would look like: @RequestMapping(method = RequestMethod.GET) public String list(Model uiModel) { uiModel.addAttribute(kpis, kpiRepository.findAll().iterator()); return secure/kpis/list; } In your JSP, you then can use this iterator as expected: c:forEach items=${kpis} var=kpi tr tdc:out value=${kpi.uuid} //td tdc:out value=${kpi.name} //td /tr /c:forEach Best regards, James ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
[Neo4j] REST api get list of all relationship properties (unique)
Dear All, I would like to extract a list of unique properties used for all relationships using the REST API. I created a relationship index and indexed all properties. When I query for * using the REST API for the lucene query, I receive lots of relationships, so it's difficult to get a unique set of properties from the query. Is there a good way to achieve this? Thanks Jure -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/REST-api-get-list-of-all-relationship-properties-unique-tp3458852p3458852.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] REST api get list of all relationship properties (unique)
Jure, if you know the Lucene query in Java, you could write a Groovy/Java script directly accessing the IndexAPI and thus do your own Lucene magic, see http://docs.neo4j.org/chunked/snapshot/gremlin-plugin.html#rest-api-send-an-arbitrary-groovy-script---lucene-sorting for an example with custom sorting in Lucene via the REST API. Does that help? 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 Thu, Oct 27, 2011 at 7:33 PM, jure j...@gmx.de wrote: Dear All, I would like to extract a list of unique properties used for all relationships using the REST API. I created a relationship index and indexed all properties. When I query for * using the REST API for the lucene query, I receive lots of relationships, so it's difficult to get a unique set of properties from the query. Is there a good way to achieve this? Thanks Jure -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/REST-api-get-list-of-all-relationship-properties-unique-tp3458852p3458852.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ 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] REST api get list of all relationship properties (unique)
Hello Peter, many thanks for the quick reply, this will help! Regards Jure -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/REST-api-get-list-of-all-relationship-properties-unique-tp3458852p3458999.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Primary Like ID Across Class Types
Hi Ramon, We faced a similar problem on our current project using neo4j. Our requirements were: * 64-bit integer * mostly-sequential * custom scopes so we could have URLs like /agencies/1/clients/1/addresses/1 * web farm friendly * mostly decentralized * no node-specific configuration * guaranteed uniqueness Having solved all these problems, we released it as an open source library called SnowMaker. We are working with .NET and Azure, but you might found our approach useful nonetheless. I have blogged about it at http://l.tath.am/snowmaker Of most interest to you will be the explanation towards the end and the sequence diagrams. HTH! -- Tatham -Original Message- From: user-boun...@lists.neo4j.org [mailto:user-boun...@lists.neo4j.org] On Behalf Of rbuckland Sent: Thursday, 27 October 2011 10:37 PM To: user@lists.neo4j.org Subject: Re: [Neo4j] Primary Like ID Across Class Types I have posted the relevant code online, interested to see what people think. like - man you just over-engineered that ! http://rbtech.blogspot.com/2011/10/neo4j-2nd-look-setting-primary-key-on.html -- View this message in context: http://neo4j-community-discussions.438527.n3.nabble.com/Primary-Like-ID-Across-Class-Types-tp3457270p3457359.html Sent from the Neo4j Community Discussions mailing list archive at Nabble.com. ___ 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