Message from discussion
Is Neo4J A good choice for these requirements
Date: Sun, 23 Sep 2012 08:02:46 -0700 (PDT)
From: Rehan <rehan.az...@gmail.com>
To: neo4j@googlegroups.com
Message-Id: <8bd2fa85-0c0e-43f2-b7f5-546260f1e4e8@googlegroups.com>
In-Reply-To: <A5504B15-65E4-4768-960D-469212F792A8@neopersistence.com>
References: <278fb0cd-ad04-490d-9989-09f9ed23b593@googlegroups.com> <58f045db-7130-45d4-8323-c73def40a690@googlegroups.com> <319a1628-8e22-43d9-a39a-360adb9dedee@googlegroups.com>
<A5504B15-65E4-4768-960D-469212F792A8@neopersistence.com>
Subject: Re: [Neo4j] Re: Is Neo4J A good choice for these requirements
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_1750_17873866.1348412566490"
------=_Part_1750_17873866.1348412566490
Content-Type: multipart/alternative;
boundary="----=_Part_1751_26800717.1348412566490"
------=_Part_1751_26800717.1348412566490
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Hi Micheal,
please see the attached for implementation of example graph but I am
getting an exception on Cypher query:
*expected where*
*"start n=node(1),m=node(13) match p=allShortestPaths(n-[*]-m) where all(r
in rels(p) : r.value>=200) return p "*
*
^*
* at
org.neo4j.cypher.internal.parser.v1_8.CypherParserImpl.parse(CypherParserImpl.scala:44)
*
* at org.neo4j.cypher.CypherParser.parse(CypherParser.scala:44)*
* at
org.neo4j.cypher.ExecutionEngine$$anonfun$prepare$1.apply(ExecutionEngine.scala:61)
*
* at
org.neo4j.cypher.ExecutionEngine$$anonfun$prepare$1.apply(ExecutionEngine.scala:61)
*
* at org.neo4j.cypher.internal.LRUCache.getOrElseUpdate(LRUCache.scala:31)*
* at org.neo4j.cypher.ExecutionEngine.prepare(ExecutionEngine.scala:61)*
* at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:55)*
* at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:52)*
* at
com.fastwire.carriere.grpah.GaphGeneratorImplTest.initializeGraphDB(GaphGeneratorImplTest.java:95)
*
Any idea how can I resole this issue.
Thanks in advance.
best regards,
Rehan
On Sunday, 23 September 2012 18:28:21 UTC+8, Michael Hunger wrote:
>
> Cool, please share your results
>
> Please use cypher parameters for query caching.
>
> Aka n=node({startNode})
> Etc
>
> Sent from mobile device
>
> Am 23.09.2012 um 06:38 schrieb Rehan <rehan...@gmail.com <javascript:>>:
>
> this is dynamic data, but every time we will refresh the whole database .
> Our goal is to find the shortest paths keeping in mind efficiency while
> filtering those based on given properties.
>
>
> On Sunday, 23 September 2012 04:51:57 UTC+8, Niels Hoogeveen wrote:
>>
>> The data you are using, is that static or does it change over time? If
>> you need update facilities, then having a graph database is certainly not
>> overkill (ACID properties). If however you have a never changing set of
>> 3000 nodes, you may as well load them from a text file into datastructures
>> of your own.
>>
>> On Saturday, September 22, 2012 4:00:27 PM UTC+2, Rehan wrote:
>>
>>> Hi
>>>
>>> I have a very basic Graph requirement , as show in attached example
>>> image.
>>>
>>> I have few questions here:
>>>
>>> - is Neo4J not an over kill for this purpose? as I have nodes less
>>> that 3000.
>>> - do Neo4J supports finding short test path between two given nodes
>>> while specifying criteria for a property of relationship to be met. if yes
>>> can someone give a java example for this.
>>>
>>> Would be great help if some one can illustrate a a small java class for
>>> attached graph as an example.
>>>
>>>
>>> <https://lh3.googleusercontent.com/-TIOLjgtO2ms/UF3EOV4MVwI/AAAAAAAAC8g/_OMzxUdKLYk/s1600/Presentation1.png>
>>> Thanks in advance.
>>>
>>> Rehan
>>>
>>> --
>
>
>
>
------=_Part_1751_26800717.1348412566490
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Hi Micheal, <div><br></div><div>please see the attached for implementa=
tion of example graph but I am getting an exception on Cypher query: <=
/div><div><br></div><div><div><b><font color=3D"#ff0000">expected where</fo=
nt></b></div><div><b><font color=3D"#ff0000">"start n=3Dnode(1),m=3Dnode(13=
) match p=3DallShortestPaths(n-[*]-m) where all(r in rels(p) : r.valu=
e>=3D200) return p "</font></b></div><div><b><font color=3D"#ff0000">&nb=
sp; &=
nbsp; =
&nbs=
p; &n=
bsp; =
 =
; ^</font></b></div><div><b><font color=3D"#ff0000"><span class=3D"A=
pple-tab-span" style=3D"white-space:pre">=09</span>at org.neo4j.cypher.inte=
rnal.parser.v1_8.CypherParserImpl.parse(CypherParserImpl.scala:44)</font></=
b></div><div><b><font color=3D"#ff0000"><span class=3D"Apple-tab-span" styl=
e=3D"white-space:pre">=09</span>at org.neo4j.cypher.CypherParser.parse(Cyph=
erParser.scala:44)</font></b></div><div><b><font color=3D"#ff0000"><span cl=
ass=3D"Apple-tab-span" style=3D"white-space:pre">=09</span>at org.neo4j.cyp=
her.ExecutionEngine$$anonfun$prepare$1.apply(ExecutionEngine.scala:61)</fon=
t></b></div><div><b><font color=3D"#ff0000"><span class=3D"Apple-tab-span" =
style=3D"white-space:pre">=09</span>at org.neo4j.cypher.ExecutionEngine$$an=
onfun$prepare$1.apply(ExecutionEngine.scala:61)</font></b></div><div><b><fo=
nt color=3D"#ff0000"><span class=3D"Apple-tab-span" style=3D"white-space:pr=
e">=09</span>at org.neo4j.cypher.internal.LRUCache.getOrElseUpdate(LRUCache=
.scala:31)</font></b></div><div><b><font color=3D"#ff0000"><span class=3D"A=
pple-tab-span" style=3D"white-space:pre">=09</span>at org.neo4j.cypher.Exec=
utionEngine.prepare(ExecutionEngine.scala:61)</font></b></div><div><b><font=
color=3D"#ff0000"><span class=3D"Apple-tab-span" style=3D"white-space:pre"=
>=09</span>at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scal=
a:55)</font></b></div><div><b><font color=3D"#ff0000"><span class=3D"Apple-=
tab-span" style=3D"white-space:pre">=09</span>at org.neo4j.cypher.Execution=
Engine.execute(ExecutionEngine.scala:52)</font></b></div><div><b><font colo=
r=3D"#ff0000"><span class=3D"Apple-tab-span" style=3D"white-space:pre">=09<=
/span>at com.fastwire.carriere.grpah.GaphGeneratorImplTest.initializeGraphD=
B(GaphGeneratorImplTest.java:95)</font></b></div><br>Any idea how can I res=
ole this issue. </div><div><br></div><div>Thanks in advance. </di=
v><div><br></div><div>best regards, </div><div><br></div><div>Rehan</d=
iv><div><br></div><div><br></div><div>On Sunday, 23 September 2012 18:28:21=
UTC+8, Michael Hunger wrote:<blockquote class=3D"gmail_quote" style=3D"ma=
rgin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">=
<div dir=3D"auto"><div>Cool, please share your results</div><div><br></div>=
<div>Please use cypher parameters for query caching.</div><div><br></div><d=
iv>Aka n=3Dnode({startNode})</div><div>Etc<br><br>Sent from mobile device</=
div><div><br>Am 23.09.2012 um 06:38 schrieb Rehan <<a href=3D"javascript=
:" target=3D"_blank" gdf-obfuscated-mailto=3D"Hyu-CVGmd4cJ">rehan...@gmail.=
com</a>>:<br><br></div><blockquote type=3D"cite"><div>this is dynamic da=
ta, but every time we will refresh the whole database . Our goal is t=
o find the shortest paths keeping in mind efficiency while filtering those =
based on given properties.<div><br></div><div><br>On Sunday, 23 September 2=
012 04:51:57 UTC+8, Niels Hoogeveen wrote:<blockquote class=3D"gmail_quote=
" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-le=
ft:1ex"><div>The data you are using, is that static or does it change over =
time? If you need update facilities, then having a graph database is certai=
nly not overkill (ACID properties). If however you have a never changing se=
t of 3000 nodes, you may as well load them from a text file into datas=
tructures of your own. </div><div><br>On Saturday, September 22, 2012 4:00:=
27 PM UTC+2, Rehan wrote:</div><blockquote style=3D"margin:0px 0px 0px 0.8e=
x;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px=
;border-left-style:solid" class=3D"gmail_quote">Hi <div><br></div><div=
>I have a very basic Graph requirement , as show in attached ex=
ample image. </div><div><br></div><div>I have few questions here:</div=
><div><ul><li>is Neo4J not an over kill for this purpose? as I have nodes l=
ess that 3000.<br></li><li>do Neo4J supports finding short test path betwee=
n two given nodes while specifying criteria for a property of relationship =
to be met. if yes can someone give a java example for this.<br></li><=
/ul></div><div>Would be great help if some one can illustrate a a small jav=
a class for attached graph as an example. </div><div><br></div><p styl=
e=3D"text-align:center;clear:both"><a style=3D"margin-right:1em;margin-left=
:1em" href=3D"https://lh3.googleusercontent.com/-TIOLjgtO2ms/UF3EOV4MVwI/AA=
AAAAAAC8g/_OMzxUdKLYk/s1600/Presentation1.png" target=3D"_blank"><img borde=
r=3D"0"></a></p>Thanks in advance. <div><br></div><div>Rehan<br><div><=
br></div></div></blockquote></blockquote></div>
<p></p>
-- <br>
<br>
<br>
</div></blockquote></div></blockquote></div>
------=_Part_1751_26800717.1348412566490--
------=_Part_1750_17873866.1348412566490
Content-Type: text/x-java; charset=US-ASCII; name=GaphGeneratorImplTest.java
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=GaphGeneratorImplTest.java
X-Attachment-Id: d600471a-85c7-4ad5-b2a0-8551c27ddd5d
package com.fastwire.carriere.grpah;
import org.neo4j.cypher.ExecutionEngine;
import org.neo4j.cypher.ExecutionResult;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Relationship;
import org.neo4j.graphdb.RelationshipType;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.index.Index;
import org.testng.annotations.Test;
public class GaphGeneratorImplTest {
private Index<Node> indexService;
private GraphDatabaseService graphDB ;
public enum relType implements RelationshipType
{
CONNECTED
}
@Test
public void f() {
initializeGraphDB();
}
//GraphDatabase Object Initializer
private GraphDatabaseService getUniqueGraphDB(){
if (graphDB==null){
GraphDB gDB = new GraphDB();
graphDB = gDB.getGraphDB();
indexService = graphDB.index().forNodes("name");
}
return graphDB;
}
//Initialize Graph Class
public Boolean initializeGraphDB() {
if (graphDB==null){
getUniqueGraphDB();
}
Transaction tx = graphDB.beginTx();
try {
Node A = getOrCreateNode("A");
A.setProperty("name", "A");
Node B = getOrCreateNode("B");
A.setProperty("name", "B");
Node C = getOrCreateNode("C");
A.setProperty("name", "C");
Node D = getOrCreateNode("D");
A.setProperty("name", "D");
Node E = getOrCreateNode("E");
A.setProperty("name", "E");
Node F = getOrCreateNode("F");
A.setProperty("name", "F");
Node G = getOrCreateNode("G");
A.setProperty("name", "G");
Node H = getOrCreateNode("H");
A.setProperty("name", "H");
Node I = getOrCreateNode("I");
A.setProperty("name", "I");
Node J = getOrCreateNode("J");
A.setProperty("name", "J");
Node K = getOrCreateNode("K");
A.setProperty("name", "K");
Node L = getOrCreateNode("L");
A.setProperty("name", "L");
Node M = getOrCreateNode("M");
A.setProperty("name", "M");
System.out.println("Nodes Created");
getOrCreateRelationShip(A, B, "400");
getOrCreateRelationShip(A, C, "200");
getOrCreateRelationShip(B, M, "10");
getOrCreateRelationShip(C, D, "1000");
getOrCreateRelationShip(C, E, "1000");
getOrCreateRelationShip(C, F, "300");
getOrCreateRelationShip(D, I, "1000");
getOrCreateRelationShip(E, H, "1000");
getOrCreateRelationShip(E, G, "500");
getOrCreateRelationShip(F, G, "500");
getOrCreateRelationShip(G, J, "1000");
getOrCreateRelationShip(H, J, "0");
getOrCreateRelationShip(I, L, "500");
getOrCreateRelationShip(J, K, "200");
getOrCreateRelationShip(J, M, "1000");
getOrCreateRelationShip(K, L, "500");
getOrCreateRelationShip(L, M, "800");
tx.success();
long aID = A.getId();
long mID = M.getId();
ExecutionEngine exEngine = new ExecutionEngine(graphDB);
ExecutionResult eReuslt = exEngine.execute("start n=node("+aID+"),m=node("+mID+") match p=allShortestPaths(n-[*]-m) where all(r in rels(p): r.value>=200) return p ");
System.out.println(eReuslt);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
tx.finish();
graphDB.shutdown();
}
return true;
}
/* Get or Create Node
* Return Node if already exists
* Else create a New node
*
* */
private Node getOrCreateNode( String neName){
if (graphDB==null)
getUniqueGraphDB();
Node node = indexService.get( "name", neName).getSingle();
if ( node == null ){
System.out.println("Creating Node: "+neName);
node = graphDB.createNode();
node.setProperty("name", neName);
indexService.add( node, "name", node);
}
return node;
}
/* Get or Create Relationship
* Return Relationship if already exists
* Else create a New Relationship
*
* */
private Relationship getOrCreateRelationShip(Node sourceNode, Node targetNode, String value){
if (graphDB==null){
getUniqueGraphDB();
}
// Check if Already Connected
Relationship rel = isRelated(sourceNode, targetNode, relType.CONNECTED);
if (rel!=null){
Relationship relationship = sourceNode.createRelationshipTo(targetNode, relType.CONNECTED);
relationship.setProperty("value", value);
return relationship;
}
return rel;
}
/* Check if Relationship Exists
* Return Relationship if already exists
* */
private Relationship isRelated(Node a, Node b, RelationshipType type) {
if (a.hasRelationship()){
Iterable<Relationship> rels = a.getRelationships();
if (rels!=null){
for(Relationship r : rels) {
if (r.getType().equals(type)){
return r;
}
}
}
}
return null;
}
}
------=_Part_1750_17873866.1348412566490--