This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MATCH (m1:Movie), (m2:Movie) | |
WHERE NOT (m1)-[:SHARE]-(m2) AND id(m1) <> id(m2) | |
WITH m1, m2, apoc.coll.intersection(m1.keywords, m2.keywords) as sameKeys | |
WITH m1, m2, sameKeys, size(sameKeys) as total | |
WHERE total > 3 | |
MERGE (m1)-[:SHARE { keywords: sameKeys }]->(m2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MATCH (m1:Movie)-[s:SHARE]->(m2:Movie) | |
WITH apoc.coll.removeAll(s.keywords, ["about", "though", "their", "takes", "which", "around", "other", "makes", "films", "scene", "often", "while", "another", "after", "perphaps", "should" ]) as valids, m1.title as film1, m2.title as film2 | |
WITH film1, film2, valids, size(valids) as total | |
WHERE total > 3 | |
RETURN film1, film2, valids, total | |
ORDER BY total DESC | |
LIMIT 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH "https://en.wikipedia.org" as url | |
CALL apoc.load.html(url + "/wiki/List_of_museums_in_Moscow", { data: "div.mw-content-ltr > div > ul a" }) YIELD value | |
UNWIND value.data as item | |
WITH { name: item.text, url: item.attributes.href } as m, url | |
CALL apoc.load.html(url + m.url, { data: "table.infobox.vcard span.geo" }) YIELD value | |
UNWIND value.data as coord | |
WITH apoc.text.split(coord.text, "; ") as coords, m | |
WITH { name: m.name, latitude: toFloat(coords[0]), longitude: toFloat(coords[1]) } as n | |
MERGE (:Museum { name: n.name, location: point({ latitude: n.latitude, longitude: n.longitude }) }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MATCH (m1:Museum), (m2:Museum) | |
WHERE id(m1) <> id(m2) | |
WITH m1, collect({ toId: id(m2), dist: apoc.math.round(distance(m1.location, m2.location) / 1000, 1) }) as distances | |
WITH m1, filter(x IN distances WHERE x.dist > 0.0) as needToWalk | |
WITH m1, apoc.coll.sortMaps(needToWalk, '^dist') as sorted | |
UNWIND sorted[0..3] as nearm | |
MATCH (m:Museum) | |
WHERE NOT (m1)-[:WALK]-(m) AND id(m) = nearm.toId | |
MERGE (m1)-[:WALK { distanceKm: nearm.dist }]->(m) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MATCH (from:Museum) | |
MATCH (to:Museum) | |
WHERE id(from) < id(to) | |
CALL algo.kShortestPaths.stream(from, to, 1, 'distanceKm') YIELD index, nodeIds, costs | |
WITH [node in algo.getNodesById(nodeIds) | node.name] AS museums, | |
duration({ minutes: reduce(acc = 0.0, cost in costs | acc + (cost / 4 * 60)) }) AS walkDuration, | |
duration({ minutes: reduce(acc = 20.0, cost in costs | acc + 20) }) AS visitDuration | |
WITH museums, walkDuration, visitDuration, duration({ minutes: walkDuration.minutes + visitDuration.minutes }) as totalDuration | |
WHERE totalDuration.minutes <= 300 | |
RETURN DISTINCT museums, size(museums) as totalMuseums, walkDuration.hours + "h " + walkDuration.minutesOfHour + "m" as walkDuration, visitDuration.hours + "h " + visitDuration.minutesOfHour + "m" as visitDuration, totalDuration.hours + "h " + totalDuration.minutesOfHour + "m" as totalDuration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Enable multi statement query editor in Database Settings (!) | |
MATCH (n) DETACH DELETE n; | |
LOAD CSV WITH HEADERS FROM 'https://vbatushkov.bitbucket.io/log_of_calls.csv' AS line | |
MERGE (c1:City { name: line.from_city }) | |
MERGE (p1:Person { name: line.from_name, number: line.from_number, gender: line.from_gender }) | |
MERGE (p1)-[:FROM]->(c1) | |
MERGE (c2:City { name: line.to_city }) | |
MERGE (p2:Person { name: line.to_name, number: line.to_number, gender: line.to_gender }) | |
MERGE (p2)-[:FROM]->(c2) | |
CREATE (c:Call { from: datetime(line.from_dt), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MATCH (p:Person)-[:OUT]->(c:Call) | |
WHERE p.name = "Liam" | |
RETURN p.name, count(c) as calls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MATCH (c:Call) | |
WHERE c.from.month = 5 | |
RETURN count(c) as calls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MATCH (p1:Person)-[:OUT]->(:Call)<-[:IN]-(p2:Person) | |
WHERE p1.name = "Robert" | |
RETURN p2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// How to use NOT: https://neo4j.com/docs/cypher-manual/current/clauses/where/#filter-on-patterns-using-not | |
MATCH (c:Call) | |
WHERE c.from.month = 2 | |
RETURN date(c.from), count(c) as calls | |
ORDER BY calls | |
LIMIT 10 |