Skip to content
Snippets Groups Projects
Commit 38b99391 authored by Malte Schokolowski's avatar Malte Schokolowski
Browse files

removed Processing_test_doi_ueberarbeitet.py

parent 5b246d2c
No related branches found
No related tags found
2 merge requests!7Main,!5Main
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 3 16:54:43 2021
@author: Malte Schokolowski
"""
from bs4 import BeautifulSoup as bs
import requests as req
import sys
from pathlib import Path
from input_fj import input
from json_demo import output_to_json
def process_main(doi_input_array, depth):
# ERROR-Handling doi_array = NULL
if (len(doi_input_array) == 0):
print("Error, no input data")
# ERROR- wenn für die Tiefe eine negative Zahl eingegeben wird
if (depth < 0):
print("Error, depth of search must be positive")
# Leeres Array für die Knoten(nodes) wird erstellt.
# Leeres Array für die Kanten(edges) wird erstellt.
global nodes, edges
nodes = []
edges = []
# Jede Publikation aus dem Input-Array wird in den Knoten-Array(nodes) eingefügt.
for pub_doi in doi_input_array:
pub = input(pub_doi)
not_in_nodes = True
for node in nodes:
if (pub.doi_url == node.doi_url):
not_in_nodes = False
break
if (not_in_nodes):
nodes.append(pub)
else:
doi_input_array.remove(pub_doi)
process_rec_depth(doi_input_array, 0, depth)
output_to_json(nodes,edges)
return(nodes,edges)
def process_rec_depth(array, depth, depth_max):
# Die Tiefe wird bei jedem rekursiven Aufruf um 1 erhöht.
depth += 1
# Für jede Publikation im Input-Array wird ein Klassenobjekt erstellt.
for pub_doi in array:
pub = input(pub_doi)
# Für jede citation, die in der entsprecheneden Klasseninstanz der Publikation gespeichert sind,
# wird geprüft, ob diese bereits als Knoten existiert.
for citation in pub._citations:
# Wenn die citation noch nicht im Knoten-Array(nodes) existiert UND die maximale Tiefe
# noch nicht erreicht wurde, wird diese als Knoten im Knoten-Array gespeichert. Zusätzlich
# wird die Verbindung zur Publikation als Tupel im Kanten-Array(edges) gespeichert.
not_in_nodes = True
for node in nodes:
if (citation.doi_url == node.doi_url):
not_in_nodes = False
break
if (not_in_nodes):
if (depth <= depth_max):
nodes.append(citation)
edges.append([pub.doi_url,citation.doi_url])
# Wenn die citaion bereits im Knoten-Array existiert, wird nur die Verbindung zur Publikation
# als Tupel im Kanten-Array(edges) gespeichert.
else:
edges.append([pub.doi_url,citation.doi_url])
# Wenn die maximale Tiefe noch nicht erreicht wurde, werden alle citations aus der Publikation
# in ein Array geschrieben und mit diesem die Funktion erneut aufgerufen.
if (depth < depth_max):
cit_arr = []
for citation in pub._citations:
# Momentan werden nur die citations mit acs in der URL gespeichert, da wir von anderen
# Quellen die Infotmationen nicht extrahieren können.
if ("acs" in citation.doi_url):
cit_arr.append(citation.doi_url)
# Rekusriver Aufruf der Funktion.
process_rec_depth(cit_arr, depth, depth_max)
# Programmtest, weil noch keine Verbindung zum Input besteht.
arr = []
arr.append('https://pubs.acs.org/doi/10.1021/acs.jcim.9b00249')
arr.append('https://pubs.acs.org/doi/10.1021/acs.jcim.9b00249')
arr.append('https://doi.org/10.1021/acs.jmedchem.0c01332')
#arr.append('https://doi.org/10.1021/acs.jcim.0c00741')
#arr.append('https://doi.org/10.1021/ci700007b')
#arr.append('https://doi.org/10.1021/acs.jcim.5b00292')
#url = sys.argv[1]
#arr.append[url]
nodes,edges = process_main(arr,1)
print("Knoten:\n")
for node in nodes:
print(node.title, "\n")
print("\nKanten:\n")
for edge in edges:
print(edge,"\n")
\ No newline at end of file
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