Skip to content
Snippets Groups Projects
Commit f5d21d6c authored by Große, Judith's avatar Große, Judith
Browse files

Json ausgelagert

parent c4ee0fcd
No related branches found
No related tags found
1 merge request!7Main
......@@ -2,10 +2,15 @@
import json
from input_fj import input
def output_to_json(V,E):
"""
Functions that format the computed graph to match the interface to the output-part
"""
# creates a list that contains a dictionary for each node
# the dictionaries store the values for the attributes
def format_nodes(V):
list_of_node_dicts = list()
list_of_edge_dicts = list()
dict_of_all = dict()
for node in V:
new_dict = dict()
new_dict["name"] = node.title
......@@ -15,18 +20,29 @@ def output_to_json(V,E):
new_dict["doi"] = node.doi_url
new_dict["group"] = node.group
list_of_node_dicts.append(new_dict)
return list_of_node_dicts
# creates a list that contains a disctionary for each edge
# the dictionaries contain the source as keys and the target as values
def format_edges(E):
list_of_edge_dicts = list()
for edge in E:
new_dict_2 = dict()
new_dict_2["source"] = edge[0]
new_dict_2["target"] = edge[1]
list_of_edge_dicts.append(new_dict_2)
return list_of_edge_dicts
# combine the lists of nodes and edges to a dictionary and saves it to a json file
def output_to_json(V,E):
dict_of_all = dict()
list_of_node_dicts = format_nodes(V)
list_of_edge_dicts = format_edges(E)
dict_of_all["nodes"] = list_of_node_dicts
dict_of_all["links"] = list_of_edge_dicts
#return(dict_of_all)
with open('json_text.json','w') as outfile:
json.dump(dict_of_all, outfile)
#knoten = ["doi1", "doi2", "doi3"]
#kanten = [[1,2],[3,4],[5,6]]
#output_to_json(knoten,kanten)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment