Skip to content

Get relationship IDs out of a projection #287

Open
@guangchen811

Description

@guangchen811

Is your feature request related to a problem? Please describe.
After running a random walk algorithm like gds.graph.sample.rwr, I want to get which relationships are visited. The following is an example to clarify what I want.

  1. Create an example graph:
CREATE
(alice:Buyer {name: 'Alice'}),
(instrumentSeller:Seller {name: 'Instrument Seller'}),
(bob:Buyer {name: 'Bob'}),
(carol:Buyer {name: 'Carol'}),
(alice)-[:PAYS { amount: 1.0}]->(instrumentSeller),
(alice)-[:PAYS { amount: 2.0}]->(instrumentSeller),
(alice)-[:PAYS { amount: 3.0}]->(instrumentSeller),
(alice)-[:PAYS { amount: 4.0}]->(instrumentSeller),
(alice)-[:PAYS { amount: 5.0}]->(instrumentSeller),
(alice)-[:PAYS { amount: 6.0}]->(instrumentSeller),

(bob)-[:PAYS { amount: 3.0}]->(instrumentSeller),
(bob)-[:PAYS { amount: 4.0}]->(instrumentSeller),
(carol)-[:PAYS { amount: 5.0}]->(bob),
(carol)-[:PAYS { amount: 6.0}]->(bob)
  1. project it.
MATCH (source)
OPTIONAL MATCH (source)-[r]->(target)
WITH gds.graph.project(
'graph_0',
source,
target,
{
sourceNodeLabels: labels(source),
targetNodeLabels: labels(target),
relationshipType: type(r)
}
) AS g
RETURN g.graphName AS graph, g.nodeCount AS nodes, g.relationshipCount AS rels

// return: 
// graph        nodes   rels
// "graph_0"  4          10
  1. run a random walk algorithm on the example graph
MATCH (start:Buyer {name: 'Alice'})
CALL gds.graph.sample.rwr('mySample', 'graph_0', { samplingRatio: 0.66, startNodes: [id(start)] })
YIELD nodeCount, relationshipCount
RETURN nodeCount, relationshipCount
// return:
// nodeCount    relationshipCount
// 3            8
  1. In this example, there are multiple relations with the same type between two nodes, e.g. PAYS between Alice and InstrumentSeller. I want to know which relationships (identified with relationship ID) are sampled in this sampling process. However, the current provided methods can only figure out which type of relations are sampled, instead of exact relationship IDs.

Describe the solution you would like
Current relationship operations like gds.beta.graph.relationships and gds.graph.relationshipProperties allow us to visit the relationship types and properties in a projection, however, the original relationship IDs are not allowed to visit. I know there are some scenarios in which relationship IDs cannot be provided (e.g., new relationships created in a projection), but can we provide relationship IDs that existed in the original neo4j graph?

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestA suggestion for a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions