From b3e24fafffe88dc5f0938f0ce7378a36cc29f492 Mon Sep 17 00:00:00 2001
From: zimmermann <zimmermann@cl.uni-heidelberg.de>
Date: Thu, 22 Mar 2018 18:06:49 +0100
Subject: [PATCH] More graph saving.

---
 src/abstinent.py | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/abstinent.py b/src/abstinent.py
index 724eeec..df26965 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+')')
-- 
GitLab