5
votes

I'm trying to extract a sub-graph from a global network (sub-networks of specific nodes to a specific depth).

The network is composed of nodes labeled as Account with a property of iban and relationships of TRANSFER_TO_AGG.

The cypher syntax is as followed:

MATCH (a:Account { iban :'FR7618206004274157697300156' }),(b:Account),
p = allShortestPaths((a)-[:TRANSFER_TO_AGG*..3]-(b))
RETURN p limit 250

This works perfectly on the Neo4J web interface. However, when trying to save the results to an R object using the command cypher I get the following error:

"Error in as.data.frame.list(value, row.names = rlabs) : 
  supplied 92 row names for 1 rows"

I believe this is due to the fact that if returning data, you can only query for tabular results. That is, this method has no current functionality for Cypher results containing array properties, collections, nodes, or relationships.

Can anyone offer a solution ?

1
Right, cypher() is only for returning tabular results, whereas you are returning a pathway (which consists of node and relationship entities). You can use EXTRACT() to get the relevant properties out of your pathway. If you'd want to share more about exactly what you're trying to do, I can try to help you find a solution with the current functionality available in RNeo4j. I haven't touched the traversal API or functionality for returning pathways because representing these things as R objects isn't straightforward.Nicole White
Tnx Nicole! I end up using labels and properties to mark the relevant subgraphs and followed it by using extract and return by these marks. Thank you kindly for the answer and for the great package enabling the use of Neo4J with R - it is great and very helpful !!!Yoav Yeled Teva Avneon

1 Answers

3
votes

I've recently added functionality for returning pathways as R objects. First, uninstall / reinstall RNeo4j. Then, see:

?getSinglePath

?getPaths

?shortestPath

?allShortestPaths

?nodes

?rels

?startNode

?endNode

For your query specifically, you would use getPaths():

library(RNeo4j)
graph = startGraph("http://localhost:7474/db/data/")

query = "
MATCH (a:Account { iban :'FR7618206004274157697300156' }),(b:Account),
p = allShortestPaths((a)-[:TRANSFER_TO_AGG*..3]-(b))
RETURN p limit 250
"

p = getPaths(graph, query)

p is a list of path objects. See the docs for examples of using the apply family of functions with a list of path objects.