Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update load_and_merge operation to support more than one destination #144

Merged
merged 1 commit into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions kg_covid_19/load_utils/merge_kg.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,20 @@ def load_and_merge(yaml_file: str) -> nx.MultiDiGraph:

# write the merged graph
if 'destination' in config:
destination = config['destination']
if destination['type'] in ['csv', 'tsv', 'ttl', 'json', 'tar']:
destination_transformer = get_transformer(destination['type'])(merged_graph)
destination_transformer.save(destination['filename'], extension=destination['type'])
elif destination['type'] == 'neo4j':
destination_transformer = NeoTransformer(
merged_graph,
uri=destination['uri'],
username=destination['username'],
password=destination['password']
)
destination_transformer.save_with_unwind()
else:
logging.error("type {} not yet supported for KGX load-and-merge operation.".format(destination['type']))
for _, destination in config['destination'].items():
print(destination)
if destination['type'] == 'neo4j':
destination_transformer = NeoTransformer(
merged_graph,
uri=destination['uri'],
username=destination['username'],
password=destination['password']
)
destination_transformer.save_with_unwind()
elif destination['type'] in get_file_types():
destination_transformer = get_transformer(destination['type'])(merged_graph)
destination_transformer.save(destination['filename'], extension=destination['type'])
else:
logging.error("type {} not yet supported for KGX load-and-merge operation.".format(destination['type']))

return merged_graph
13 changes: 11 additions & 2 deletions merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,14 @@ target:
- data/transformed/ontologies/hp_nodes.tsv
- data/transformed/ontologies/hp_edges.tsv
destination:
type: tsv
filename: merged-kg
merged-kg-tsv:
type: tsv
filename: merged-kg
merged-kg-nt:
type: nt
filename: merged-kg.nt
# merged-kg-neo4j:
# type: neo4j
# uri: http://localhost:8484
# username: neo4j
# password: admin