Last active
August 29, 2015 14:04
-
-
Save kbastani/3e3ebf5e4adfd8266ff0 to your computer and use it in GitHub Desktop.
Run these Cypher scripts sequentially to generate graph art in Neo4j
This file contains 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 (a), (b) | |
WHERE id(a) = 10484 AND id(b) = 10546 | |
MATCH p=shortestPath((a)-[*]-(b)) | |
RETURN p |
This file contains 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
// Create a matrix of size*size | |
// Change the size range below to change matrix dimensions | |
WITH range(0, 24) as size | |
FOREACH (y in tail(size) | | |
FOREACH (x in tail(size) | | |
MERGE (lastBlock:Pattern { x: x - 1, y: y, pattern: toString(x - 1) + "-" + toString(y) }) | |
MERGE (thisBlock:Pattern { x: x, y: y, pattern: toString(x) + "-" + toString(y) }) | |
MERGE (upBlock:Pattern { x: x, y: y - 1, pattern: toString(x) + "-" + toString(y - 1) }) | |
MERGE (lastUpBlock:Pattern { x: x - 1, y: y - 1, pattern: toString(x - 1) + "-" + toString(y - 1) }) | |
MERGE (dBlock:Pattern { x: x + 1, y: y + 1, pattern: toString(x + 1) + "-" + toString(y + 1) }) | |
MERGE (lastBlock)-[:NEXT]->(thisBlock) | |
MERGE (lastBlock)-[:NEXT]->(lastUpBlock) | |
MERGE (thisBlock)-[:NEXT]->(upBlock) | |
MERGE (lastUpBlock)-[:NEXT]->(upBlock) | |
MERGE (dBlock)-[:NEXT]->(thisBlock)) | |
) | |
RETURN * |
This file contains 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
// Create a branching tree off edges of a matrix | |
// Branching factor is adjustable | |
// Run multiple times to increase depth | |
WITH 3 as BRANCH_FACTOR | |
MATCH (n) WHERE NOT (n)<--() | |
WITH collect(n) as ns, BRANCH_FACTOR | |
FOREACH (x in ns | FOREACH (x2 in range(1, BRANCH_FACTOR) | MERGE (x)<-[:NEXT]-(pattern:Pattern { pattern: toString(x2) + "-" + toString(x.pattern) }))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment