Skip to content

Instantly share code, notes, and snippets.

@jvilledieu
Last active July 22, 2019 12:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvilledieu/667a18c5bd5020310926b8c59abc4a41 to your computer and use it in GitHub Desktop.
Save jvilledieu/667a18c5bd5020310926b8c59abc4a41 to your computer and use it in GitHub Desktop.
Import script for the aml demo
//Creating the companies
CREATE CONSTRAINT ON (a:COMPANY) ASSERT a.id IS UNIQUE;
USING PERIODIC COMMIT 2000
LOAD CSV WITH HEADERS FROM "file:///companies.csv" AS line
FIELDTERMINATOR ','
WITH line
MERGE (a:COMPANY {id: line.id})
ON CREATE SET a.description = line.description,
a.name = line.name;
//Creating the persons
CREATE CONSTRAINT ON (a:PERSON) ASSERT a.id IS UNIQUE;
USING PERIODIC COMMIT 2000
LOAD CSV WITH HEADERS FROM "file:///people.csv" AS line
FIELDTERMINATOR ','
WITH line
MERGE (a:PERSON {id: line.id})
ON CREATE SET a.first_name = line.first_name,
a.last_name = line.last_name,
a.email = line.email,
a.country = line.country
a.watch_list = 'NO;
//Creating the employees
MATCH (a:PERSON)
WITH a
LIMIT 50
SET a:EMPLOYEE;
//Tagging people on watch list
MATCH (a:PERSON)
WITH a
LIMIT 1
SET a.watch_list = 'YES';
//Creating the addresses
CREATE CONSTRAINT ON (a:ADDRESS) ASSERT a.id IS UNIQUE;
USING PERIODIC COMMIT 2000
LOAD CSV WITH HEADERS FROM "file:///addresses.csv" AS line
FIELDTERMINATOR ','
WITH line
MERGE (a:ADDRESS {id: line.id})
ON CREATE SET a.city = line.city,
a.country = line.country,
a.lat = toInt(line.lat),
a.long = toInt(line.long),
a.zip_code = line.zip_code,
a.street = line.street;
//Connecting the persons to addresses
MATCH (a:PERSON), (b:ADDRESS)
WITH a,b
WHERE rand() < 0.005 AND NOT (a)-[:HAS_ADDRESS]->(:ADDRESS)
MERGE (a)-[:HAS_ADDRESS]->(b);
//Connecting the companies to addresses
MATCH (a:COMPANY), (b:ADDRESS)
WITH a,b
WHERE rand() < 0.005 AND NOT (a)-[:HAS_ADDRESS]->(:ADDRESS)
MERGE (a)-[:HAS_ADDRESS]->(b);
//Creating the bank accounts
CREATE CONSTRAINT ON (a:BANK_ACCOUNT) ASSERT a.number IS UNIQUE;
USING PERIODIC COMMIT 2000
LOAD CSV WITH HEADERS FROM "file:///bank_accounts.csv" AS line
FIELDTERMINATOR ','
WITH line
MERGE (a:BANK_ACCOUNT {number: line.number})
ON CREATE SET a.total = toInt(line.total);
//Connecting the persons to bank accounts
MATCH (a:PERSON), (b:BANK_ACCOUNT)
WITH a,b
WHERE rand() < 0.0005 AND NOT (b)<-[:HAS_BANK_ACCOUNT]-() AND NOT (a)-[:HAS_BANK_ACCOUNT]->()
MERGE (a)-[:HAS_BANK_ACCOUNT]->(b);
//Connecting the companies to bank accounts
MATCH (a:COMPANY), (b:BANK_ACCOUNT)
WITH a,b
WHERE rand() < 0.001 AND NOT (b)<-[:HAS_BANK_ACCOUNT]-() AND NOT (a)-[:HAS_BANK_ACCOUNT]->()
MERGE (a)-[:HAS_BANK_ACCOUNT]->(b);
//Creating the shareholder links
MATCH (a:PERSON), (b:COMPANY)
WITH a,b
WHERE rand() < 0.00005
MERGE (a)-[:IS_SHAREHOLDER_OF {value: rand()*100}]->(b);
MATCH (a:COMPANY), (b:COMPANY)
WITH a,b
WHERE rand() < 0.0001
MERGE (a)-[:IS_SHAREHOLDER_OF {value: rand()*100}]->(b);
//Create transactions between bank accounts
MATCH (a:BANK_ACCOUNT),(b:BANK_ACCOUNT)
WITH a,b
LIMIT 100000
WHERE rand() < 0.1
FOREACH (r IN range(0,10) |
CREATE (a)-[:HAS_SENT]->(:TRANSACTION {amount: toInt(rand()*100)})<-[:HAS_RECEIVED]-(b));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment