2
votes

I am fairly certain I have seen it somewhere but all keywords I have tried came up empty.

I have a graph that connects persons and companies via documents:

(:Person/:Company)-[ ]-(:Document)-[ ]-(:Person/:Company)

What I would like to do is return a graph that shows the connection between persons and companies directly with the relationship strength based on the number of connections between them.

I get the data with

MATCH (p)-[]-(d:Document)-[]-(c)
WHERE p:Person or p:Company and c:Person or c:Company
WITH p,c, count(d) as rel
RETURN p,rel,c

However in the Neo4J-Browser, the nodes appear without any relationships. Is there a way to achieve this or do I have to create some kind of meta relationship?

1
Double click a node to pop open the relationships. - Matthew Campbell
But then it opens alle the relationships via the documents. I would like to have the relationships displayed directly between the person/company nodes. - EliasAtBerlin
Match (p:Person)-[]-(d:Document)-[]-(c:Company) to select should be enough since there is no direction on the relationships. - Matthew Campbell
Then you have to have an alias on the relationships and return them as well. - Matthew Campbell
But I don't want to return those relationsships. I have a data model (:Person/:Company)-[ ]-(:Document)-[ ]-(:Person/:Company) and would like to visualize in the Neo4J-Browser als (:Person/:Company)-[ number of connections]-(:Person/:Company) without actually changing the underlying data model. - EliasAtBerlin

1 Answers

0
votes

If you install APOC Procedures, you'll be able to create virtual relationships which are used for visualization but aren't actually stored in the db.

MATCH (p)-[]-(d:Document)-[]-(c)
WHERE (p:Person or p:Company AND c:Person or c:Company)
 AND  id(p) < id(c)
WITH p,c, count(d) as relStrength
CALL apoc.create.vRelationship(p,'REL',{strength:relStrength}, c) YIELD rel
RETURN p,rel,c

I also added a predicate on ids of p and c so you don't repeat the same two nodes with p and c switched.