I create graph from tag nodes, where the relationships in the created graph are not relationships from original database, but some paths which represent tags are tagged on the same videos.
CALL gds.graph.create.cypher(
"tags",
"MATCH (t:Tag) RETURN id(t) AS id, labels(t) AS labels",
"
MATCH (t:Tag)
WITH collect(t) as nodes
UNWIND nodes as n
UNWIND nodes as m
WITH n, m WHERE id(n) < id(m)
MATCH (n)-[:TAGGED_ON]->(v:Video)<-[:TAGGED_ON]-(m)
RETURN id(n) AS source, id(m) AS target, count(v) AS weight
"
)
And then I do this to export to new database:
CALL gds.graph.export("tags", {dbName: "tags"})
CREATE DATABASE tags
However, the relationships in the new tags database will all named __ALL__
.
In the relationshipQuery part of graph creation, docs of neo4j say
Optionally, a type column can be specified to represent relationship type.
However, all examples I found about this are type(r) AS type
, where this cannot work on my case. I still can rename the relationships in the new tags database by this:
MATCH ()-[r]->()
WITH collect(r) AS rels
CALL apoc.refactor.rename.type("__ALL__", "TAGGED_ON_THE_SAME_VIDEO", rels)
YIELD committedOperations
RETURN committedOperations
But can I use the custom relationship name at the gds graph creation time? I tried something like "TAGGED_ON_THE_SAME_VIDEO" AS type
but this cannot work.