Skip to content

Instantly share code, notes, and snippets.

@tomasonjo
Last active February 10, 2018 10:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomasonjo/e6bcdfdedc30cae911cd35735529a9ef to your computer and use it in GitHub Desktop.
Save tomasonjo/e6bcdfdedc30cae911cd35735529a9ef to your computer and use it in GitHub Desktop.
Infer a network
MATCH (a:Address)<-[:registered_address]-(o:Officer)-[:officer_of]->()<-[:officer_of]-(o2:Officer)-[:registered_address]->(a2:Address)
WHERE id(o) > id(o2) AND a.name contains "Zurich" AND a2.name contains "Zurich"
WITH o,o2,count(*) as common_investments
MERGE (o)-[c:COMMON_INVESTMENTS]-(o2)
ON CREATE SET c.weight = common_investments
--------------------------------------------------------------------------------------
find connected components
CALL algo.unionFind.stream('MATCH (o:Officer) WHERE (o)-[:COMMON_INVESTMENTS]-()
RETURN id(o) as id',
'MATCH (o1:Officer)-[:COMMON_INVESTMENTS]-(o2)
RETURN id(o1) as source,id(o2) as target',{graph:'cypher'})
YIELD nodeId,setId
RETURN setId as component,count(*) as componentSize
ORDER BY componentSize desc limit 10
--------------------------------------------------------------------------------------
CALL algo.pageRank.stream('MATCH (o:Officer) WHERE (o)-[:COMMON_INVESTMENTS]-()
RETURN id(o) as id',
'MATCH (o1:Officer)-[:COMMON_INVESTMENTS]-(o2)
RETURN id(o1) as source,id(o2) as target',{graph:'cypher'})
YIELD node,score
WITH node,score order by score desc limit 10
RETURN node.name as officer,score
---------------------------------------------------------------------------------------
CALL algo.closeness.harmonic.stream('MATCH (o:Officer) WHERE (o)-[:COMMON_INVESTMENTS]-()
RETURN id(o) as id',
'MATCH (o1:Officer)-[:COMMON_INVESTMENTS]-(o2)
RETURN id(o1) as source,id(o2) as target',{graph:'cypher'})
YIELD nodeId,centrality
WITH nodeId,centrality order by centrality desc limit 10
MATCH (n) where id(n)=nodeId
RETURN n.name as officer,centrality
-----------------------------------------------------------------------------------
CALL algo.labelPropagation('MATCH (o:Officer) WHERE (o)-[:COMMON_INVESTMENTS]-()
RETURN id(o) as id',
'MATCH (o1:Officer)-[:COMMON_INVESTMENTS]-(o2)
RETURN id(o1) as source,id(o2) as target','OUT',{graph:'cypher',partitionProperty:'lpa'})
MATCH (o:Officer) WHERE exists (o.lpa)
RETURN o.lpa as community, count(*) as communitySize,collect(o.name) as members
ORDER BY communitySize desc limit 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment