Skip to content

Instantly share code, notes, and snippets.

@rich-biker
Created January 22, 2018 18:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rich-biker/f49f044364045b315f6c59e01710ac1b to your computer and use it in GitHub Desktop.
Save rich-biker/f49f044364045b315f6c59e01710ac1b to your computer and use it in GitHub Desktop.
Cypher query to load data from the three Archi tool CSV extracts to create properly labeled nodes and relationships into a blank NEO4J database. Needs APOC plugin.
// Load the Archi CSV export elements as labeled nodes
using periodic commit
load csv with headers from "file:/elements.csv" as e
call apoc.create.node([e.Type], {name: e.Name, doc: e.Documentation, uid: e.ID})
yield node
return count(*);
// Create the uid indexes for my main objects
create index on :ApplicationComponent(uid);
create index on :ApplicationFunction(uid);
create index on :ApplicationInterface(uid);
create index on :ApplicationService(uid);
create index on :ArchimateModel(uid);
create index on :Artifact(uid);
create index on :Assessment(uid);
create index on :BusinessActor(uid);
create index on :BusinessCollaboration(uid);
create index on :BusinessEvent(uid);
create index on :BusinessFunction(uid);
create index on :BusinessObject(uid);
create index on :BusinessProcess(uid);
create index on :BusinessRole(uid);
create index on :BusinessService(uid);
create index on :Capability(uid);
create index on :Constraint(uid);
create index on :CourseOfAction(uid);
create index on :DataObject(uid);
create index on :Device(uid);
create index on :Driver(uid);
create index on :Equipment(uid);
create index on :Gap(uid);
create index on :Goal(uid);
create index on :Grouping(uid);
create index on :Location(uid);
create index on :Node(uid);
create index on :Outcome(uid);
create index on :Plateau(uid);
create index on :Principle(uid);
create index on :Product(uid);
create index on :Requirement(uid);
create index on :Resource(uid);
create index on :Stakeholder(uid);
create index on :TechnologyInterface(uid);
create index on :WorkPackage(uid);
// Load the Archi CSV export relationships as named relationships.
load csv with headers from "file:/relations.csv" as line
match (src {uid: line.Source}), (trg {uid: line.Target})
CALL apoc.create.relationship(src,line.Type,{uid:line.ID},trg)
yield rel return src, trg, count(*)
as relationships;
// Add properties from the Archi CSV export for the named properties (i.e. those that belong to elements - I need to improve this)
// Double beware - I'm not sure why this sometimes never ends - maybe malformed. Doesn't break anything though.
USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "file:/properties.csv" AS line
WITH line WHERE line.Value is not NULL match (element {uid: line.ID})
WHERE line.Key IN ["Level", "MaturityAsIs", "MaturityToBe","Value", "Domain", "Ref", "TechnologyHealth", "icon", "TechnologyHealth", "Process Type", "Project Code", "Type", "Application ID", "Priority"]
CALL apoc.create.setProperty(element, line.Key, line.Value)
YIELD node RETURN element, COUNT(*);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment