neo4jrest client question

61 views
Skip to first unread message

Alex

unread,
Apr 18, 2012, 2:31:20 AM4/18/12
to Neo4j

Hi guys, i use the neo4jrestclient api and looking documentation i
dont know how to visualize all relation
node to node, let me to explain ..

in the documentation i see u can search for incoming or outgoing
relation referred to a node

like this :

rels = node.relationships.incoming()

or

rels = node.relationships.outgoing()

but if i need all the relation referred to two nodes ? like node1
referred to node2, is possible ?



thanks

Nigel Small

unread,
Apr 18, 2012, 2:38:34 AM4/18/12
to ne...@googlegroups.com
Hi Alex

I'm not sure exactly how you would do that from within the neo4jrestclient specifically, but it's certainly possible via the REST interface. Py2neo makes it available as below:

http://py2neo.org/doc/py2neo.html#py2neo.neo4j.Node.get_relationships

Nige

Alex

unread,
Apr 18, 2012, 2:44:41 AM4/18/12
to Neo4j
Hi Nige,

im in search of something of that :

rels = node1.relationships.node2.<direction>

but dunno if this is done with traversal in more simple manner ..

Thanks


On 18 Apr, 08:38, Nigel Small <ni...@nigelsmall.net> wrote:
> Hi Alex
>
> I'm not sure exactly how you would do that from within the neo4jrestclient
> specifically, but it's certainly possible via the REST interface. Py2neo
> makes it available as below:
>
> http://py2neo.org/doc/py2neo.html#py2neo.neo4j.Node.get_relationships
>
> Nige
>

James Thornton

unread,
Apr 18, 2012, 3:50:02 AM4/18/12
to ne...@googlegroups.com


On Wednesday, April 18, 2012 1:44:41 AM UTC-5, Alex wrote:

im in search of something of that :

rels = node1.relationships.node2.<direction>

but dunno if this is done with traversal in more simple manner .. 


You can use a Gremlin script in Bulbs (http://bulbflow.com/) to find all the relationships between nodes "a" and "b"...

>>> from bulbs.neo4jserver import Graph
>>> g = Graph()
>>> script = "g.v(a).bothE().filter{it.outVertex == g.v(b) || it.inVertex == g.v(b)}"
>>> params = dict(a=1, b=2)
>>> edges = g.gremlin.query(script, params)

- James


Alex

unread,
Apr 18, 2012, 5:37:20 AM4/18/12
to Neo4j
Nice !

Ty James

Javier de la Rosa

unread,
Apr 18, 2012, 11:18:56 AM4/18/12
to ne...@googlegroups.com
Hi, Alex,

There is no way to do that in the neo4jrestclient, but you can use the
script Nigel has written also in the library:

>>> gremlin = gdb.extensions.GremlinPlugin.execute_script

>>> relationships = gremlin(script=script)

Or just returning the data as raw:

>>> relationships = gremlin(script=script, returns=client.constants.RAW)

Another less efficient way is just a comprehesion list like this one:

>>> [r for r in n2.relationships.all(type=["KNOWS"]).all() if n2 in [r.start, r.end]]

It returns all the relationships of types "KNOWS" between n1 and n2,
no matters the direction. Or you can even use traversals.

--
Javier de la Rosa
http://versae.es

Reply all
Reply to author
Forward
0 new messages