diff --git a/src/abstinent.py b/src/abstinent.py index 724eeec19e08e377650c61307f46a7ebb8f417ff..df2696519f2b30ccc21562fcc247ec4368d21af4 100644 --- a/src/abstinent.py +++ b/src/abstinent.py @@ -347,8 +347,34 @@ def induce(topic_name: str, result_list: list) -> (nx.Graph, list, dict): stat_dict['target'] = topic_name - print('[a]', 'Counting nodes and edges.\t('+topic_name+')') - node_freq_dict, edge_freq_dict = frequencies(topic_name, result_list) + print('[a]', 'Counting nodes and edges.\t('+topic_name+')') + + #Check if frequencies were already counted before. + + node_dict_name = topic_name+'_node.json' + edge_dict_name = topic_name+'_edge.json' + + graph_in_existence = False + for graph_name in os.listdir(config.graph): + + if topic_name in graph_name: + + graph_in_existence = True + + with open(config.graph+node_dict_name, 'r') as node_file, open(config.graph+edge_dict_name, 'r') as edge_file: + + node_freq_dict = json.load(node_file) + edge_freq_dict = json.load(edge_file) + + continue + + if graph_in_existence == False: + + node_freq_dict, edge_freq_dict = frequencies(target_string, result_list) + + with open(config.graph+node_dict_name, 'w') as node_file, open(config.graph+edge_dict_name, 'w') as edge_file: + node_file.write(json.dumps(node_freq_dict)) + edge_file.write(json.dumps(edge_freq_dict)) #builds graph from these dictionaries, also applies multiple filters print('[a]', 'Building graph.\t('+topic_name+')')