Created
October 31, 2019 15:46
-
-
Save derekmcloughlin/65e66e97ac35b7d2f46c96620c683298 to your computer and use it in GitHub Desktop.
Importing lobbyist XML data using APOC
This file contains hidden or 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
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