Skip to content

Commit

Permalink
Remove items called node and edges.
Browse files Browse the repository at this point in the history
  • Loading branch information
everaldorodrigo committed Oct 23, 2024
1 parent 5a9b0fa commit c7e0761
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/hub/dataload/sources/civic/civic_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,27 @@ def merge_dicts(d1, d2):

def remove_nodes_and_edges(data):
if isinstance(data, dict):
# If the current data is a dictionary, iterate through its keys
new_data = {}
for key, value in data.items():
if key in ['node', 'nodes', 'edge', 'edges']:
# If the value is a list (like 'edges'), process each item and keep them in a list
# If the key is 'nodes' or 'edges', recursively process the value
if isinstance(value, list):
new_data = remove_nodes_and_edges(value) # Keep all items as a list
# If 'edges' is a list, take each element (each 'nodes') and process
for item in value:
new_data.update(remove_nodes_and_edges(item.get(key, item)))
else:
# If 'nodes' is a dictionary, just update with its content
new_data.update(remove_nodes_and_edges(value))
else:
# Process the value recursively for other keys
new_data[key] = remove_nodes_and_edges(value)
return new_data
elif isinstance(data, list):
# If it's a list, return a list of processed items
# If it's a list, apply the function recursively to each element
return [remove_nodes_and_edges(item) for item in data]
else:
# If it's neither a dict nor a list, return the value as is
# If it's neither a dict nor a list, return the value
return data


Expand Down

0 comments on commit c7e0761

Please sign in to comment.