Skip to content

Instantly share code, notes, and snippets.

@vladbatushkov
Last active August 21, 2019 16:56
Show Gist options
  • Save vladbatushkov/843502259637bfd5a3038cca4448e07d to your computer and use it in GitHub Desktop.
Save vladbatushkov/843502259637bfd5a3038cca4448e07d to your computer and use it in GitHub Desktop.
Create COMMUNICATE_WITH relationship between persons.
// Check the data
MATCH (p1:Person)-[:OUT]->(c:Call)<-[]-(p2:Person)
WHERE c.duration > 0
RETURN p1.name, p2.name, sum(c.duration) as duration, count(c) as calls
ORDER BY duration DESC
LIMIT 10
// Check one pair
MATCH (p1:Person { name: "Kara" })-[*2]-(p2:Person { name: "Hailee" })
RETURN p1, p2
// Set COMMUNICATE_WITH
MATCH (c1:City { name: "Bangkok" })<-[:FROM]-(p1:Person)-[:OUT]->(c:Call)<-[:IN]-(p2:Person)
WHERE (c1)<-[:FROM]-(p2)
WITH p1, p2, sum(c.duration) as duration_sum
MERGE (p1)-[:COMMUNICATE_WITH { duration: duration_sum }]->(p2)
// SCC
CALL algo.scc.stream('Person', 'COMMUNICATE_WITH')
YIELD nodeId, partition
RETURN partition, count(nodeId) as total
ORDER BY total DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment