Neo4j Graph Data Modeling based on Reverse Engineering approach

May 17: World Telecom Day, One Month Graph Challenge

Welcome word

Domain model

Graph

MATCH (n) DETACH DELETE n;
CALL apoc.generate.er(100, 75, 'Spot', 'CONNECT');
MATCH (s:Spot)
WHERE NOT (s)--()
DELETE s
MATCH (s1)-[*]-(s2)
WITH COUNT(DISTINCT s2) AS size, s1
WITH s1, size
SET s1.size = size
WITH max(size) - 1 as max
MATCH (s:Spot)
WHERE s.size < max
DETACH DELETE s
CALL algo.louvain.stream('Spot', 'CONNECT', {})
YIELD nodeId, community
CALL apoc.create.setProperty([nodeId], 'subnetwork', community + 1) YIELD node as n1
CALL apoc.create.addLabels([n1], ['Subnetwork' + toString(community + 1)]) YIELD node as n2
WITH collect(n2.uuid) as spots, community as subnetwork
RETURN subnetwork, size(spots) as numberOfSports
MATCH (s:Spot)
WHERE apoc.node.degree(s, '') = 1
SET s:PC
MATCH (s1:PC)-[:CONNECT]-(s2:Spot)
SET s2:Switch
MATCH (s:Spot)
WHERE apoc.node.degree(s, '') > 2 AND NOT (s:PC OR s:Switch)
SET s:Router
MATCH (s:Spot)
WHERE NOT (s:PC OR s:Switch OR s:Router)
SET s:Repeater
PC (Orange), Switch (Yellow), Router (Red), Repeater (Blue)

Resume

Resources

Engineering Technical Lead @ Agoda. Neo4j Featured Community Member. Certified Neo4j Professional. Articles brewed on web, hops and indie rock’n’roll.