hi, i use node array. i think it is fine now. but i have another question
here.
public static void main( String[] args )
{
final String DB_PATH = "target/neo4j-hello-db";
GraphDatabaseService db = new
GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
TraversalExample op = new TraversalExample( db );
op.createTheGraph();
op.shutdownGraph();
}
public void shutdownGraph()
{
try
{
if ( db != null )
{
db.shutdown();
}
}
finally
{
db = null;
}
}
public Node createTheGraph()
{
try ( Transaction tx = db.beginTx() )
{
// START SNIPPET: createGraph
Node[] newno=new Node[5];
for(int i=0; i<newno.length; i++){
newno[i]=db.createNode();
}
newno[1].createRelationshipTo(newno[2], Rels.KNOWS );
newno[1].createRelationshipTo(newno[4], Rels.KNOWS );
newno[4].createRelationshipTo(newno[2], Rels.KNOWS );
newno[2].createRelationshipTo(newno[3], Rels.KNOWS );
System.out.println(knowsLikesTraverser(newno[1]));
return newno[1];
}
}
public String knowsLikesTraverser( Node node )
{
String output = "";
// START SNIPPET: knowslikestraverser
for ( Path position : db.traversalDescription()
.depthFirst()
.relationships( Rels.KNOWS )
.evaluator( Evaluators.toDepth( 5 ) )
.traverse( node ) )
{
output += position + "\n";
}
// END SNIPPET: knowslikestraverser
return output;
}
while it give me output like this.
(4350)
(4350)--[KNOWS,8328]-->(4351)
(4350)--[KNOWS,8328]-->(4351)--[KNOWS,8331]-->(4352)
(4350)--[KNOWS,8328]-->(4351)<--[KNOWS,8330]--(4353)
why it give the number like 4350 and 8328? this big number. it supposed to
be just 0-4. Thanks.
if i just want to node to traversal forward and backward separately. Right
now the traversal is mixed together.
Thanks.
On Thursday, April 17, 2014 9:44:03 PM UTC-7, Michael Hunger wrote:
>
> You should use a Node[] array
>
> Perhaps you want to rather use cypher from another language than writing
> Java code?
>
> Sent from mobile device
>
> Am 18.04.2014 um 03:21 schrieb TC <[email protected] <javascript:>>:
>
> why cannot i use this way to create node use int array
> int[] newnode=new int[10];
> for(int i=0; i<newnode.length; i++){
> Node newnode[i]=db.createNode();
> }
>
> newnode[1].createRelationshipTo(newnode[2], Rels.KNOWS );
>
> On Thursday, April 17, 2014 3:56:44 AM UTC-7, Anders Nawroth wrote:
>>
>> Hi!
>>
>> Did you initialize the db field?
>>
>> Something like
>> db = new GraphDatabaseFactory().newEmbeddedDatabase( "path/to/db" );
>>
>> /anders
>>
>>
>> On Thu, Apr 17, 2014 at 9:11 AM, Tingting Cui <[email protected]> wrote:
>>
>>> when i try to run TraversalExample.java example and create the graph
>>> like this
>>> it give me error like this
>>> Exception in thread "main" java.lang.NullPointerException
>>> at setupneo4j.TraversalExample.<init>(TraversalExample.java:23)
>>> at setupneo4j.TraversalExample.main(TraversalExample.java:33)
>>> what is the problems here.
>>> public static void main( String[] args )
>>> {
>>>
>>> TraversalExample op = new TraversalExample( db );
>>> op.shutdownGraph();
>>> }
>>> public void shutdownGraph()
>>> {
>>> try
>>> {
>>> if ( db != null )
>>> {
>>> db.shutdown();
>>> }
>>> }
>>> finally
>>> {
>>> db = null;
>>> }
>>> }
>>>
>>> public Node createTheGraph()
>>> {
>>> try ( Transaction tx = db.beginTx() )
>>> {
>>> // START SNIPPET: createGraph
>>> Node A = db.createNode();
>>> Node B = db.createNode();
>>> Node C = db.createNode();
>>> Node D = db.createNode();
>>>
>>> A.createRelationshipTo( C, Rels.KNOWS );
>>> C.createRelationshipTo( D, Rels.KNOWS );
>>> A.createRelationshipTo( B, Rels.KNOWS);
>>> B.createRelationshipTo( C, Rels.KNOWS );
>>> // END SNIPPET: createGraph
>>> A.setProperty( "name", "A" );
>>> B.setProperty( "name", "B" );
>>> C.setProperty( "name", "C" );
>>> D.setProperty( "name", "D" );
>>> tx.success();
>>> return A;
>>> }
>>> }
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Neo4j" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Anders Nawroth [[email protected]]
>> Skype: anders.nawroth
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Neo4j" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected] <javascript:>.
> For more options, visit https://groups.google.com/d/optout.
>
>
--
You received this message because you are subscribed to the Google Groups
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.