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

added test functunality

parent 3fa1104f
No related branches found
No related tags found
1 merge request!7Main
...@@ -25,9 +25,13 @@ from json_demo import output_to_json ...@@ -25,9 +25,13 @@ from json_demo import output_to_json
# doi_input_list: list of publication dois from user # doi_input_list: list of publication dois from user
# TO-DO: Listenelemente auf Korrektheit überprüfen # TO-DO: Listenelemente auf Korrektheit überprüfen
def initialize_nodes_list(doi_input_list): def initialize_nodes_list(doi_input_list, test_var):
for pub_doi in doi_input_list: for pub_doi in doi_input_list:
pub = input_test_func(pub_doi) if(test_var):
pub = input_test_func(pub_doi)
else:
pub = input(pub_doi)
not_in_nodes = True not_in_nodes = True
for node in nodes: # checks if a pub is already in nodes for node in nodes: # checks if a pub is already in nodes
if (pub.doi_url == node.doi_url): if (pub.doi_url == node.doi_url):
...@@ -35,6 +39,7 @@ def initialize_nodes_list(doi_input_list): ...@@ -35,6 +39,7 @@ def initialize_nodes_list(doi_input_list):
break break
if (not_in_nodes): if (not_in_nodes):
nodes.append(pub) nodes.append(pub)
#print(pub.doi_url)
pub.group = "input" pub.group = "input"
else: else:
doi_input_list.remove(pub_doi) doi_input_list.remove(pub_doi)
...@@ -55,11 +60,11 @@ def create_graph_structure_citations(pub, search_height, search_height_max): ...@@ -55,11 +60,11 @@ def create_graph_structure_citations(pub, search_height, search_height_max):
if (search_height <= search_height_max): if (search_height <= search_height_max):
citation.group = "height" citation.group = "height"
nodes.append(citation) nodes.append(citation)
edges.append([pub.doi_url,citation.doi_url]) edges.append([citation.doi_url,pub.doi_url])
# adds only edge if citation already exists # adds only edge if citation already exists
else: else:
edges.append([pub.doi_url,citation.doi_url]) edges.append([citation.doi_url,pub.doi_url])
...@@ -77,11 +82,11 @@ def create_graph_structure_references(pub, search_depth, search_depth_max): ...@@ -77,11 +82,11 @@ def create_graph_structure_references(pub, search_depth, search_depth_max):
if (search_depth <= search_depth_max): if (search_depth <= search_depth_max):
reference.group = "depth" reference.group = "depth"
nodes.append(reference) nodes.append(reference)
edges.append([reference.doi_url,pub.doi_url]) edges.append([pub.doi_url,reference.doi_url])
# adds only edge if citation already exists # adds only edge if citation already exists
else: else:
edges.append([reference.doi_url,pub.doi_url]) edges.append([pub.doi_url,reference.doi_url])
...@@ -89,13 +94,17 @@ def create_graph_structure_references(pub, search_depth, search_depth_max): ...@@ -89,13 +94,17 @@ def create_graph_structure_references(pub, search_depth, search_depth_max):
# doi_citations: input list of citet dois # doi_citations: input list of citet dois
# search_height: current search_height of height-first-search # search_height: current search_height of height-first-search
# search_height_max: maximal search_height for dfs # search_height_max: maximal search_height for dfs
def process_citations_rec(doi_citations, search_height, search_height_max): def process_citations_rec(doi_citations, search_height, search_height_max, test_var):
# height of search is increased by 1 with each recursive call # height of search is increased by 1 with each recursive call
search_height += 1 search_height += 1
# create class object for every citation from list # create class object for every citation from list
for pub_doi in doi_citations: for pub_doi in doi_citations:
pub = input_test_func(pub_doi) if (test_var):
pub = input_test_func(pub_doi)
else:
pub = input(pub_doi)
create_graph_structure_citations(pub, search_height, search_height_max) create_graph_structure_citations(pub, search_height, search_height_max)
# If the maximum height has not yet been reached, all references from the publication # If the maximum height has not yet been reached, all references from the publication
# are written to an array and the function is called again with this array. # are written to an array and the function is called again with this array.
...@@ -109,7 +118,7 @@ def process_citations_rec(doi_citations, search_height, search_height_max): ...@@ -109,7 +118,7 @@ def process_citations_rec(doi_citations, search_height, search_height_max):
citations_list.append(citation.doi_url) citations_list.append(citation.doi_url)
# recursive call of function. # recursive call of function.
process_citations_rec(citations_list, search_height, search_height_max) process_citations_rec(citations_list, search_height, search_height_max, test_var)
...@@ -117,13 +126,17 @@ def process_citations_rec(doi_citations, search_height, search_height_max): ...@@ -117,13 +126,17 @@ def process_citations_rec(doi_citations, search_height, search_height_max):
# doi_references: input list of referenced dois # doi_references: input list of referenced dois
# search_depth: current search_depth of height-first-search # search_depth: current search_depth of height-first-search
# search_depth_max: maximal search_depth for dfs # search_depth_max: maximal search_depth for dfs
def process_references_rec(doi_references, search_depth, search_depth_max): def process_references_rec(doi_references, search_depth, search_depth_max, test_var):
# The depth is increased by 1 with each recursive call # The depth is increased by 1 with each recursive call
search_depth += 1 search_depth += 1
# create class object for every citation from list # create class object for every citation from list
for pub_doi in doi_references: for pub_doi in doi_references:
pub = input_test_func(pub_doi) if (test_var):
pub = input_test_func(pub_doi)
else:
pub = input(pub_doi)
create_graph_structure_references(pub, search_depth, search_depth_max) create_graph_structure_references(pub, search_depth, search_depth_max)
# If the maximum depth has not yet been reached, all references from the publication # If the maximum depth has not yet been reached, all references from the publication
# are written to an array and the function is called again with this array. # are written to an array and the function is called again with this array.
...@@ -133,16 +146,17 @@ def process_references_rec(doi_references, search_depth, search_depth_max): ...@@ -133,16 +146,17 @@ def process_references_rec(doi_references, search_depth, search_depth_max):
# currently only the references with acs are stored in the URL, because we can't # currently only the references with acs are stored in the URL, because we can't
# extract the info from other sources. # extract the info from other sources.
if ("acs" in reference.doi_url): if ("acs" in reference.doi_url or test_var == True):
references_list.append(reference.doi_url) references_list.append(reference.doi_url)
# recursive call of function. # recursive call of function.
process_references_rec(references_list, search_depth, search_depth_max) process_references_rec(references_list, search_depth, search_depth_max, test_var)
def process_main(doi_input_list, search_height, search_depth): def process_main(doi_input_list, search_height, search_depth, test_var = False):
# ERROR-Handling doi_array = NULL # ERROR-Handling doi_array = NULL
if (len(doi_input_list) == 0): if (len(doi_input_list) == 0):
print("Error, no input data") print("Error, no input data")
...@@ -161,16 +175,33 @@ def process_main(doi_input_list, search_height, search_depth): ...@@ -161,16 +175,33 @@ def process_main(doi_input_list, search_height, search_depth):
nodes = [] nodes = []
edges = [] edges = []
initialize_nodes_list(doi_input_list) initialize_nodes_list(doi_input_list,test_var)
process_citations_rec(doi_input_list, 0, search_height) process_citations_rec(doi_input_list, 0, search_height, test_var)
process_references_rec(doi_input_list, 0, search_depth) process_references_rec(doi_input_list, 0, search_depth, test_var)
output_to_json(nodes,edges) output_to_json(nodes,edges)
# only for internal testing # only for internal testing
return(nodes,edges) return(nodes,edges)
def print_graph(nodes, edges):
print("Knoten:\n")
for node in nodes:
print(node.title, "\n")
print("\n Kanten:\n")
for edge in edges:
print(edge,"\n")
# function to test cycles
def test_cycle():
arr = []
arr.append('doiz1')
#arr.append('doiz2')
nodes,edges = process_main(arr,1,1,True)
print_graph(nodes, edges)
# program test, because there is no connection to the input yet. # program test, because there is no connection to the input yet.
def test_print(): def test_print():
...@@ -185,19 +216,11 @@ def test_print(): ...@@ -185,19 +216,11 @@ def test_print():
#url = sys.argv[1] #url = sys.argv[1]
#arr.append[url] #arr.append[url]
arr.append('doi1')
#arr.append('doi2')
#arr.append('doi3')
nodes,edges = process_main(arr,1,1) nodes,edges = process_main(arr,2,2,True)
print("Knoten:\n") print_graph(nodes, edges)
for node in nodes:
print(node.title, "\n")
print("\n Kanten:\n")
for edge in edges:
print(edge,"\n")
test_print() #test_print()
test_cycle()
\ No newline at end of file
File added
No preview for this file type
...@@ -60,4 +60,7 @@ beispiel1 = ['doi1', 'title1', ['contributor1'], 'journal1', 'date1', ['doi2'], ...@@ -60,4 +60,7 @@ beispiel1 = ['doi1', 'title1', ['contributor1'], 'journal1', 'date1', ['doi2'],
beispiel2 = ['doi2', 'title2', ['contributor2'], 'journal2', 'date2', [], ['doi1'], ''] beispiel2 = ['doi2', 'title2', ['contributor2'], 'journal2', 'date2', [], ['doi1'], '']
beispiel3 = ['doi3', 'title3', ['contributor3'], 'journal3', 'date3', ['doi1'], [], ''] beispiel3 = ['doi3', 'title3', ['contributor3'], 'journal3', 'date3', ['doi1'], [], '']
list_of_arrays = [beispiel1, beispiel2, beispiel3] zyklus1 = ['doiz1', 'titlez1', ['contributorz1.1', 'contributorz1.2'], 'journalz1', 'datez1', ['doiz2'], ['doiz2'], '']
zyklus2 = ['doiz2', 'titlez2', ['contributorz2.1', 'contributorz2.2'], 'journalz2', 'datez2', ['doiz1'], ['doiz1'], '']
list_of_arrays = [beispiel1, beispiel2, beispiel3, zyklus1, zyklus2]
{"nodes": [{"name": "title1", "author": ["contributor1"], "year": "date1", "journal": "journal1", "doi": "doi1", "group": "input"}, {"name": "title3", "author": ["contributor3"], "year": "date3", "journal": "journal3", "doi": "doi3", "group": "height"}, {"name": "title2", "author": ["contributor2"], "year": "date2", "journal": "journal2", "doi": "doi2", "group": "depth"}], "links": [{"source": "doi1", "target": "doi3"}, {"source": "doi2", "target": "doi1"}]} {"nodes": [{"name": "titlez1", "author": ["contributorz1.1", "contributorz1.2"], "year": "datez1", "journal": "journalz1", "doi": "doiz1", "group": "input"}, {"name": "titlez2", "author": ["contributorz2.1", "contributorz2.2"], "year": "datez2", "journal": "journalz2", "doi": "doiz2", "group": "depth"}], "links": [{"source": "doiz1", "target": "doiz2"}]}
\ No newline at end of file \ No newline at end of file
Zyklus
großer Zyklus
Innere Kanten vervollständigen
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