cancel
Showing results for 
Search instead for 
Did you mean: 

Sending virtual nodes to Gephi for visualisation

Hi Folks,

I have a query which gives me some virtual nodes and relationships. BUt now I want to send this over to gephi using the apoc.gephi.add. Unfortunately, I can't figure out if this is possible with vNodes.

Here is my current query:
MATCH (a:Author)
WITH collect(distinct a.country) as countries
WITH [cName in countries | apoc.create.vNode(['Country'],{name:cName})] as countryNodes
WITH apoc.map.groupBy(countryNodes,'name') as countries
MATCH (a1:Author)-->(p:Paper)<--(a2:Author)
WHERE a1.country < a2.country
WITH a1.country AS countryName1, a2.country as countryName2, count(distinct p) as numCollabs, countries
WITH countries[countryName1] as country1, countries[countryName2] as country2, apoc.create.vRelationship(countries[countryName1], 'COLLABORATED_WITH', {numCollabs: numCollabs}, countries[countryName2]) as rels
RETURN country1, country2, rels limit 25

This works fine, but the examples in the documentation for gephi.add use a MATCH, but I can't seem to do that here.

Similarly, I can't even export the properties from Neo4j to csv because something like this doesn't work:
RETURN country1.name

This just returns null (because the nodes are virtual I guess) even though RETURN country1 returns a correct looking JSON object I can't return individual properties.

Any ideas?
Thanks.

1 REPLY 1

giuseppe_villan
Graph Fellow

@gary.frewin
With Gephi you can pass, as a 3rd parameter, a list of entities.
So, in your case, you could execute after your query:

// previous query substituting RETURN with WITH...
WITH [rels, country1, country2] as data // list of virtual start node, virtual end node and virtual rel
CALL apoc.gephi.add(null, 'workspace1',data) 
YIELD nodes, relationships, format 
RETURN *

Regarding the properties, you're right, country1.name return null because is a virtual node.
To return your properties, you have to use the apoc.any.properties function, for example apoc.any.properties(country1).name.

In general, with virtual entities, there are some apoc functions to use instead of "classic" neo4j functions:

  • apoc.any.properties
  • apoc.node.id
  • apoc.node.labels
  • apoc.rel.type
  • apoc.rel.endNode
  • apoc.rel.startNode
  • apoc.rel.id

and some procedures:

  • apoc.create.setProperty
  • apoc.create.setProperties
  • apoc.create.setRelProperty
  • apoc.create.setRelProperties
Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.