Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-01-2022 03:14 PM
Hi everyone
I would like to find the adjacency matrix of the following bipartite graph
if the link exists, the matrix takes the value revenue. otherwise, it takes 0.
MATCH (c:customer)
WITH collect(c) AS cust
UNWIND cust AS a
MATCH (p:part)
WITH collect(p) AS par
UNWIND par AS b
RETURN a.id AS cutomer, b.id AS part,
CASE
WHEN EXISTS((a)-[r:customer_to_part]->(b)) THEN r.revenue
ELSE 0
END AS value
But this does not work.
Can you please help me to find the right matrix
Solved! Go to Solution.
12-01-2022 07:15 PM
Just a couple notes. The order of the query operations will cause the 'match(p:part) collect(p)' block to be repeated for each customer node. Also, its not allowed to introduce a variable in a pattern expression, so returning r.revenue isn't allowed. I refactored your query to resolve these two issues.
match(c:customer)
with collect(c) as customers
match(p:part)
with customers, collect(p) as parts
unwind customers as customer
unwind parts as part
optional match (customer)-[r:customer_to_part]->(part)
return customer.id as cust_id, part.id as part_id,
case
when r is not null then r.revenue
else 0
end as value
12-01-2022 07:15 PM
Just a couple notes. The order of the query operations will cause the 'match(p:part) collect(p)' block to be repeated for each customer node. Also, its not allowed to introduce a variable in a pattern expression, so returning r.revenue isn't allowed. I refactored your query to resolve these two issues.
match(c:customer)
with collect(c) as customers
match(p:part)
with customers, collect(p) as parts
unwind customers as customer
unwind parts as part
optional match (customer)-[r:customer_to_part]->(part)
return customer.id as cust_id, part.id as part_id,
case
when r is not null then r.revenue
else 0
end as value
12-03-2022 04:47 AM
Thanks glilienfield
All the sessions of the conference are now available online