diff --git a/src/absinth.py b/src/absinth.py index 02de6f274986ea691d29a0f30ee8d22310415c9d..fb401415ae9cfc362830b8409e44d82f208761fb 100644 --- a/src/absinth.py +++ b/src/absinth.py @@ -148,6 +148,8 @@ def induce(topic_name: str, result_list: list) -> (nx.Graph, list, dict): node_freq_dict = json.load(node_file) edge_freq_dict = json.load(edge_file) + edge_freq_dict = {(key1,key2):value2 for key1,value1 in edge_freq_dict.items() for key2,value2 in value1.items()} + continue if graph_in_existence == False: @@ -157,6 +159,15 @@ def induce(topic_name: str, result_list: list) -> (nx.Graph, list, dict): with open(config.graph+node_dict_name, 'w') as node_file, open(config.graph+edge_dict_name, 'w') as edge_file: json.dump(node_freq_dict, node_file) + + new_dict = dict() + for key,value in edge_freq_dict.items(): + if key[0] in new_dict: + key[0].add({key[1]:value}) + else: + key[0] = {key[1]:value} + + edge_freq_dict = new_dict json.dump(edge_freq_dict, edge_file) #builds graph from these dictionaries, also applies multiple filters diff --git a/src/abstinent.py b/src/abstinent.py index 29201f1608cfd9b57e04910ea53d395666111924..901b99e8ad10aad372371b2f0fe0144f64e439b9 100644 --- a/src/abstinent.py +++ b/src/abstinent.py @@ -366,6 +366,8 @@ def induce(topic_name: str, result_list: list) -> (nx.Graph, list, dict): node_freq_dict = json.load(node_file) edge_freq_dict = json.load(edge_file) + edge_freq_dict = {(key1,key2):value2 for key1,value1 in edge_freq_dict.items() for key2,value2 in value1.items()} + continue if graph_in_existence == False: @@ -375,6 +377,15 @@ def induce(topic_name: str, result_list: list) -> (nx.Graph, list, dict): with open(config.graph+node_dict_name, 'w') as node_file, open(config.graph+edge_dict_name, 'w') as edge_file: json.dump(node_freq_dict, node_file) + + new_dict = dict() + for key,value in edge_freq_dict.items(): + if key[0] in new_dict: + key[0].add({key[1]:value}) + else: + key[0] = {key[1]:value} + + edge_freq_dict = new_dict json.dump(edge_freq_dict, edge_file) #builds graph from these dictionaries, also applies multiple filters