Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Importing lobbyist XML data using APOC
with '2015_1_1_1.xml' as url
CALL apoc.load.xml(url) YIELD value as publicFilings
UNWIND publicFilings._children as filing
MERGE (f:Filing {fid: filing.ID, type: filing.Type})
with filing, f
unwind filing._children as item
with filing, f, item,
[c in item where c._type = "Client" | c] as clients,
[r in item where r._type = "Registrant" | r] as registrants,
[lo in item where lo._type = "Lobbyists" | lo] as lobbyists,
[ge in item where ge._type = "GovernmentEntities" | ge] as governmentEntities,
[i in item where i._type = "Issues" | i] as issues
FOREACH (_ IN clients |
MERGE (c:Client {cid: item.ClientID, name: item.ClientName})
MERGE (f)-[:ON_BEHALF_OF]->(c)
)
FOREACH (_ IN registrants |
MERGE (r:Registrant {rid: item.RegistrantID, name: item.RegistrantName})
MERGE (r)-[:FILED]->(f)
)
with filing, f, item, clients, registrants, lobbyists, governmentEntities, issues
unwind item._children as lobbyist
FOREACH (_ IN lobbyists |
MERGE (lo:Lobbyist {name: lobbyist.LobbyistName})
MERGE (lo)-[:LOBBYING_FOR]->(f)
)
with filing, f, item, clients, registrants, lobbyists, governmentEntities, issues
match(r)-[:FILED]->(f)
match(lo)-[:LOBBYING_FOR]->(f)
create(r)-[:EMPLOYS]->(lo)
with filing, f, item, governmentEntities, issues
unwind item._children as governmentEntity
FOREACH (_ IN governmentEntities |
MERGE (ge:GovernmentEntity {name: governmentEntity.GovEntityName})
MERGE (f)-[:TARGETED_AT]->(ge)
)
with filing, f, item, issues
unwind item._children as issue
FOREACH (_ IN issues |
MERGE (i:Issue {name: issue.Code, specific: issue.SpecificIssue})
MERGE (f)-[:ABOUT]->(i)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.