Skip to content

Instantly share code, notes, and snippets.

@jvilledieu
jvilledieu / Paradise_enhanced.cql
Last active Aug 22, 2018
Queries to extend the paradise papers dataset with pagrank, community detection, geocoding, etc
View Paradise_enhanced.cql
//Check schema
CALL db.schema()
//Identify countries with limited # of adresses
MATCH (a:Address)
WITH a, a.countries as countries
RETURN countries, count(a) as score
ORDER BY score ASC
LIMIT 50
View relato.cql
//Creating companies
CALL apoc.load.json($url) YIELD value
WITH distinct value.home_domain as domain, value.home_name as name
merge (b:Business {domain:domain}) ON CREATE SET b.name = name;
//Creating more companies
call apoc.load.json($url) yield value
with distinct value.link_domain as domain, value.link_name as name
merge (b:Business {domain:domain}) ON CREATE SET b.name = name;
@jvilledieu
jvilledieu / EA.cql
Last active Apr 13, 2017
Enterprise Architecture dataset for Neo4j
View EA.cql
CREATE (:OrganizationUnit { name: "OrganizationUnit"})
FOREACH (r IN range(0,3)|
CREATE (:ICTObject{ name:"ICTObject" + r}))
FOREACH (r IN range(0,3)|
CREATE (:BusinessActor{ name:"BusinessActor" + r}))
FOREACH (r IN range(0,3)|
CREATE (:ApplicationService{ name:"ApplicationService" + r}))
FOREACH (r IN range(0,3)|
CREATE (:Process{ name:"Process" + r}))
View SupplyChainManagement.cql
CREATE (:BillOfMaterial { name: "BoM", cost: 500})
FOREACH (r IN range(0,10)|
CREATE (:Retailer { name:"Retailer" + r, cost: round(exp(rand()*3)+20), co2: round(exp(rand()*8)+250), lat: tan(rand())*100, long: tan(rand())*100, time: 1}))
FOREACH (r IN range(0,1)|
CREATE (:Wholesaler { name:"Wholesaler" + r, cost: round(exp(rand()*3)+20), co2: round(exp(rand()*8)+250), lat: tan(rand())*100, long: tan(rand())*100, time: round(rand()*5)}))
;
CREATE (:Product { name: "ProductA", lat: tan(rand())*100, long: tan(rand())*100, co2: 200, cost: 100, time: 0 })
FOREACH (r IN range(0,2)|
CREATE (:Supplier { name:"SupplierA" + r, cost: round(exp(rand()*3)+20), co2: round(exp(rand()*8)+250), lat: tan(rand())*100, long: tan(rand())*100, time: round(rand()*5)}))
@jvilledieu
jvilledieu / import_generalsofgold.cql
Created Mar 14, 2017
Import script for the generals' of gold.
View import_generalsofgold.cql
// Verifying the CSV file
// assert correct line count
LOAD CSV FROM "file:/Developer/TGOG/data/person.csv" AS line
RETURN count(*);
// check first few raw lines
LOAD CSV FROM "file:/Developer/TGOG/data/person.csv" AS line WITH line
RETURN line
LIMIT 1;
@jvilledieu
jvilledieu / import_trump_world.cql
Created Jan 16, 2017
Importing the Buzzfeed Trump World data into Neo4j (Based on Michael Hunger's work)
View import_trump_world.cql
//Creating unique constraint
CREATE CONSTRAINT ON (o:Organization) ASSERT o.name IS UNIQUE;
//Importing the organizations and their connections
WITH 'https://docs.google.com/spreadsheets/u/1/d/1Z5Vo5pbvxKJ5XpfALZXvCzW26Cl4we3OaN73K9Ae5Ss/export?format=tsv&id=1Z5Vo5pbvxKJ5XpfALZXvCzW26Cl4we3OaN73K9Ae5Ss&gid=634968401' AS url, ['LOAN','LOBBIED','SALE','SUPPLIER','SHAREHOLDER','LICENSES','AFFILIATED','TIES','NEGOTIATION','INVOLVED','PARTNER'] as terms
load csv with headers from url as row fieldterminator '\t'
MERGE (a:Organization {name:row.`Organization A`})
MERGE (b:Organization {name:row.`Organization B`})
CREATE (a)-[:IS_CONNECTED_TO {type:row.Connection}]->(b);
@jvilledieu
jvilledieu / aml_demo.cql
Last active Jul 22, 2019
Import script for the aml demo
View aml_demo.cql
//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;
@jvilledieu
jvilledieu / updated_crunchbase_script.cql
Last active Aug 18, 2016
New crunchbase import script
View updated_crunchbase_script.cql
/*
https://linkurio.us/the-crunchbase-graph-data-modelling/
https://linkurio.us/crunchbase-graph-importing-data-neo4j/
https://linkurio.us/crunchbase-graph-analysing-graph/
Check also Neo4j csv and etl guide
*/
@jvilledieu
jvilledieu / intelligence_dataset_import.cql
Last active Aug 14, 2017
Import intelligence dataset
View intelligence_dataset_import.cql
//Clean up the db
MATCH (n)
OPTIONAL MATCH (n)-[r]-()
DELETE n,r;
//-----------------------
//Import persons
//-----------------------
CREATE CONSTRAINT ON (a:Person)
ASSERT a.id IS UNIQUE;
@jvilledieu
jvilledieu / import_datagreffe.cql
Last active Nov 27, 2015
Script pour importer les données Datagreffe dans Neo4j
View import_datagreffe.cql
//Load the companies
create index on :Company(CodeSiren);
import-cypher -d";" -i file:c:/infogreffe2014.csv -b 10000 -q create (e:Company {CodeSiren: {Siren}, Denomination: {Denomination}, Geolocalisation: {Geolocalisation}, DateImmatriculation: {DateImmatriculation}, Greffe: {Greffe}, FicheEntreprise: {FicheEntreprise}});
//Load the codes
create index on :FormeJuridique(name);
import-cypher -d";" -i file:c:/infogreffe2014.csv -b 10000 -q with distinct {FormeJuridique} as FormeJuridique merge (:FormeJuridique {name: FormeJuridique});
create index on :CodeAPE(name);
import-cypher -d";" -i file:c:/infogreffe2014.csv -b 10000 -q with distinct {CodeAPE} as CodeAPE, {Secteur} as Secteur merge (:CodeAPE {name: Secteur, code: CodeAPE});