From e0522cbe2104dd09c489a608a2177c9bf1a85795 Mon Sep 17 00:00:00 2001
From: Malte Schokolowski <baw8441@uni-hamburg.de>
Date: Thu, 23 Dec 2021 14:18:23 +0100
Subject: [PATCH] bug fixed for max cit/ref not found while updating

---
 .../construct_new_graph/initialize_graph.py   |  2 +-
 verarbeitung/start_script.py                  | 12 -----
 verarbeitung/update_graph/update_depth.py     | 44 +++++++++++--------
 verarbeitung/update_graph/update_graph.py     |  2 +-
 4 files changed, 27 insertions(+), 33 deletions(-)
 delete mode 100644 verarbeitung/start_script.py

diff --git a/verarbeitung/construct_new_graph/initialize_graph.py b/verarbeitung/construct_new_graph/initialize_graph.py
index ef17df6..bfc7df2 100644
--- a/verarbeitung/construct_new_graph/initialize_graph.py
+++ b/verarbeitung/construct_new_graph/initialize_graph.py
@@ -75,7 +75,7 @@ def initialize_nodes_list(doi_input_list, search_depth_max, search_height_max, t
     for pub_doi in doi_input_list: #iterates over every incoming doi
         pub = get_pub(pub_doi, test_var)
         if (type(pub) != Publication):
-            print(pub)
+            #print(pub)
             continue       
 
         # checks if publication already exists in nodes
diff --git a/verarbeitung/start_script.py b/verarbeitung/start_script.py
deleted file mode 100644
index 6e5854f..0000000
--- a/verarbeitung/start_script.py
+++ /dev/null
@@ -1,12 +0,0 @@
-import sys
-from pathlib import Path
-from verarbeitung.process_main import Processing
-from verarbeitung.dev_files.print_graph_test import try_known_publications, try_delete_nodes
-
-
-doi_list = []
-doi_list.append('https://pubs.acs.org/doi/10.1021/acs.jcim.9b00249')
-#doi_list.append('https://doi.org/10.1021/acs.jcim.9b00249')
-doi_list.append('https://pubs.acs.org/doi/10.1021/acs.jcim.1c00203')
-doi_list.append('https://doi.org/10.1021/acs.jmedchem.0c01332')
-Processing(doi_list, 2, 2, 'test.json')
diff --git a/verarbeitung/update_graph/update_depth.py b/verarbeitung/update_graph/update_depth.py
index 40fc687..2f0a1d8 100644
--- a/verarbeitung/update_graph/update_depth.py
+++ b/verarbeitung/update_graph/update_depth.py
@@ -18,7 +18,9 @@ sys.path.append("../../")
 
 from verarbeitung.construct_new_graph.add_citations_rec import add_citations
 from verarbeitung.construct_new_graph.initialize_graph import complete_inner_edges
+from verarbeitung.get_pub_from_input import get_pub
 from .update_edges import back_to_valid_edges
+from input.publication import Publication
 
 
 def reduce_max_height(max_height):
@@ -62,7 +64,7 @@ def get_old_height_depth():
             max_height = max(max_height, pub.group)
     return(max_height, max_depth)
 
-def get_old_max_references(old_depth):
+def get_old_max_references(old_depth, test_var):
     '''
         :param old_depth:       old maximum depth to search for citations
         :type old_depth:        int
@@ -72,13 +74,14 @@ def get_old_max_references(old_depth):
     old_max_references = []
     for pub in processed_input_list:
         if (abs(pub.group) == old_depth):
-            for reference in pub.references:
-                for ref_pub in processed_input_list:
-                    if reference.doi_url == ref_pub.doi_url:
-                        old_max_references.append(ref_pub)
+            pub = get_pub(pub.doi_url, test_var)
+            if (type(pub) != Publication):
+                #print(pub)
+                continue
+            old_max_references.append(pub)
     return(old_max_references)
 
-def get_old_max_citations(old_height):
+def get_old_max_citations(old_height, test_var):
     '''
         :param old_height:      old maximum height to search for citations
         :type old_height:       int
@@ -88,10 +91,11 @@ def get_old_max_citations(old_height):
     old_max_citations = []
     for pub in processed_input_list:
         if (abs(pub.group) == old_height):
-            for citation in pub.citations:
-                for cit_pub in processed_input_list:
-                    if citation.doi_url == cit_pub.doi_url:
-                        old_max_citations.append(cit_pub)
+            pub = get_pub(pub.doi_url, test_var)
+            if (type(pub) != Publication):
+                #print(pub)
+                continue
+            old_max_citations.append(pub)
     return(old_max_citations)
 
 def update_depth(obj_input_list, input_edges, new_depth, new_height, test_var):
@@ -120,20 +124,22 @@ def update_depth(obj_input_list, input_edges, new_depth, new_height, test_var):
 
     old_height, old_depth = get_old_height_depth()
 
-    # removes publications and links from recursion levels which aren't needed anymore
+    # removes publications and links from recursion levels which aren't needed anymore or adds new ones
     if (old_depth > new_depth):
         reduce_max_depth(new_depth)
-    elif (old_height > new_height):
+    elif (old_depth < new_depth):
+        old_max_references = get_old_max_references(old_depth, test_var)
+        add_citations(processed_input_list, valid_edges, old_max_references, old_depth, new_depth, "Reference", test_var)
+    
+    if (old_height > new_height):
         reduce_max_height(new_height)
+    elif (old_height < new_height):
+        old_max_citations = get_old_max_citations(old_height, test_var)
+        add_citations(processed_input_list, valid_edges, old_max_citations, old_height, new_height, "Citation", test_var)
+    
+   
     
     
-    # adds publications and links for new recursion levels
-    elif (old_depth < new_depth):
-        old_max_references = get_old_max_references(old_depth)
-        add_citations(processed_input_list, valid_edges, old_max_references, old_depth+1, new_depth, "Reference", test_var)
-    elif (old_height < new_height):
-        old_max_citations = get_old_max_citations(old_height)
-        add_citations(processed_input_list, valid_edges, old_max_citations, old_height+1, new_height, "Citation", test_var)
     back_to_valid_edges(valid_edges, processed_input_list)
 
     # adds edges between reference group and citation group of known publications
diff --git a/verarbeitung/update_graph/update_graph.py b/verarbeitung/update_graph/update_graph.py
index 7bbb907..7e3ad76 100644
--- a/verarbeitung/update_graph/update_graph.py
+++ b/verarbeitung/update_graph/update_graph.py
@@ -59,7 +59,7 @@ def get_new_input_dois(new_input, test_var):
         # retrieves information and adds to new list if successful 
         pub = get_pub(new_node, test_var)
         if (type(pub) != Publication):
-            print(pub)
+            #print(pub)
             continue
 
         new_input_dois.append(pub.doi_url)
-- 
GitLab