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

added new tests and fixed height/depth bug

parent 56d69f1c
No related branches found
No related tags found
1 merge request!7Main
...@@ -27,11 +27,14 @@ from json_demo import output_to_json ...@@ -27,11 +27,14 @@ from json_demo import output_to_json
# TO-DO: Listenelemente auf Korrektheit überprüfen # TO-DO: Listenelemente auf Korrektheit überprüfen
def initialize_nodes_list(doi_input_list, test_var): def initialize_nodes_list(doi_input_list, test_var):
for pub_doi in doi_input_list: for pub_doi in doi_input_list:
# checks if its a test and chooses input function accordingly
if(test_var): if(test_var):
pub = input_test_func(pub_doi) pub = input_test_func(pub_doi)
else: else:
pub = input(pub_doi) pub = input(pub_doi)
# checks if publication already exists in nodes
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):
...@@ -43,16 +46,22 @@ def initialize_nodes_list(doi_input_list, test_var): ...@@ -43,16 +46,22 @@ def initialize_nodes_list(doi_input_list, test_var):
else: else:
doi_input_list.remove(pub_doi) doi_input_list.remove(pub_doi)
# adds inner edges between citations and references to edges
def complete_inner_edges(test_var): def complete_inner_edges(test_var):
for node in nodes: for node in nodes:
# checks if its a test and chooses input function accordingly
if (test_var): if (test_var):
pub = input_test_func(node.doi_url) pub = input_test_func(node.doi_url)
else: else:
pub = input(node.doi_url) pub = input(node.doi_url)
if (node.group == "depth"): if (node.group == "depth"):
for citation in pub.citations: for citation in pub.citations:
if (citation in nodes and [citation.doi_url, pub.doi_url] not in edges): if (citation in nodes and [citation.doi_url, pub.doi_url] not in edges):
edges.append([citation.doi_url, pub.doi_url]) edges.append([citation.doi_url, pub.doi_url])
if (node.group == "height"): if (node.group == "height"):
for reference in pub.references: for reference in pub.references:
for node in nodes: for node in nodes:
...@@ -65,6 +74,8 @@ def complete_inner_edges(test_var): ...@@ -65,6 +74,8 @@ def complete_inner_edges(test_var):
# adds edges for citations between publications # adds edges for citations between publications
def create_graph_structure_citations(pub, search_height, search_height_max): def create_graph_structure_citations(pub, search_height, search_height_max):
for citation in pub.citations: for citation in pub.citations:
# checks if publication already exists in nodes
not_in_nodes = True not_in_nodes = True
for node in nodes: for node in nodes:
# checks every citation for duplication # checks every citation for duplication
...@@ -77,7 +88,7 @@ def create_graph_structure_citations(pub, search_height, search_height_max): ...@@ -77,7 +88,7 @@ def create_graph_structure_citations(pub, search_height, search_height_max):
nodes.append(citation) nodes.append(citation)
edges.append([citation.doi_url,pub.doi_url]) edges.append([citation.doi_url,pub.doi_url])
# adds only edge if citation already exists # adds only an edge (citation already exists)
elif [citation.doi_url,pub.doi_url] not in edges: elif [citation.doi_url,pub.doi_url] not in edges:
edges.append([citation.doi_url,pub.doi_url]) edges.append([citation.doi_url,pub.doi_url])
...@@ -87,6 +98,8 @@ def create_graph_structure_citations(pub, search_height, search_height_max): ...@@ -87,6 +98,8 @@ def create_graph_structure_citations(pub, search_height, search_height_max):
# adds edges for references between publications # adds edges for references between publications
def create_graph_structure_references(pub, search_depth, search_depth_max): def create_graph_structure_references(pub, search_depth, search_depth_max):
for reference in pub.references: for reference in pub.references:
# checks if publication already exists in nodes
not_in_nodes = True not_in_nodes = True
for node in nodes: for node in nodes:
# checks every reference for duplication # checks every reference for duplication
...@@ -99,7 +112,7 @@ def create_graph_structure_references(pub, search_depth, search_depth_max): ...@@ -99,7 +112,7 @@ def create_graph_structure_references(pub, search_depth, search_depth_max):
nodes.append(reference) nodes.append(reference)
edges.append([pub.doi_url,reference.doi_url]) edges.append([pub.doi_url,reference.doi_url])
# adds only edge if citation already exists # adds only an edge (citation already exists)
elif [pub.doi_url,reference.doi_url] not in edges: elif [pub.doi_url,reference.doi_url] not in edges:
edges.append([pub.doi_url,reference.doi_url]) edges.append([pub.doi_url,reference.doi_url])
...@@ -115,6 +128,8 @@ def process_citations_rec(doi_citations, search_height, search_height_max, test_ ...@@ -115,6 +128,8 @@ def process_citations_rec(doi_citations, search_height, search_height_max, test_
# 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:
# checks if its a test and chooses input function accordingly
if (test_var): if (test_var):
pub = input_test_func(pub_doi) pub = input_test_func(pub_doi)
else: else:
...@@ -129,7 +144,7 @@ def process_citations_rec(doi_citations, search_height, search_height_max, test_ ...@@ -129,7 +144,7 @@ def process_citations_rec(doi_citations, search_height, search_height_max, test_
# 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 citation.doi_url): if ("acs" in citation.doi_url or test_var == True):
citations_list.append(citation.doi_url) citations_list.append(citation.doi_url)
# recursive call of function. # recursive call of function.
...@@ -147,6 +162,8 @@ def process_references_rec(doi_references, search_depth, search_depth_max, test_ ...@@ -147,6 +162,8 @@ def process_references_rec(doi_references, search_depth, search_depth_max, test_
# 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:
#checks if its a test and chooses input function accordingly
if (test_var): if (test_var):
pub = input_test_func(pub_doi) pub = input_test_func(pub_doi)
else: else:
...@@ -164,7 +181,6 @@ def process_references_rec(doi_references, search_depth, search_depth_max, test_ ...@@ -164,7 +181,6 @@ def process_references_rec(doi_references, search_depth, search_depth_max, test_
if ("acs" in reference.doi_url or test_var == True): 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, test_var) process_references_rec(references_list, search_depth, search_depth_max, test_var)
...@@ -190,6 +206,7 @@ def process_main(doi_input_list, search_height, search_depth, test_var = False): ...@@ -190,6 +206,7 @@ def process_main(doi_input_list, search_height, search_depth, test_var = False):
nodes = [] nodes = []
edges = [] edges = []
initialize_nodes_list(doi_input_list,test_var) initialize_nodes_list(doi_input_list,test_var)
process_citations_rec(doi_input_list, 0, search_height, test_var) process_citations_rec(doi_input_list, 0, search_height, test_var)
process_references_rec(doi_input_list, 0, search_depth, test_var) process_references_rec(doi_input_list, 0, search_depth, test_var)
......
...@@ -2,7 +2,7 @@ import unittest ...@@ -2,7 +2,7 @@ import unittest
from Processing import process_main from Processing import process_main
class ProcessingTest(unittest.TestCase): class ProcessingTest(unittest.TestCase):
def testCycle(self): def testCycle(self):
nodes, edges = process_main(['doiz1'],1,1,True) nodes, edges = process_main(['doiz1'],1,1,True)
self.assertCountEqual(nodes, ['doiz1', 'doiz2']) self.assertCountEqual(nodes, ['doiz1', 'doiz2'])
self.assertCountEqual(edges, [['doiz1', 'doiz2'], ['doiz2', 'doiz1']]) self.assertCountEqual(edges, [['doiz1', 'doiz2'], ['doiz2', 'doiz1']])
...@@ -17,7 +17,7 @@ class ProcessingTest(unittest.TestCase): ...@@ -17,7 +17,7 @@ class ProcessingTest(unittest.TestCase):
#def testEmptyDepth(self): #def testEmptyDepth(self):
def testEmptyDepthHeight(self): def testEmptyDepthHeight(self):
nodes, edges = process_main(['doi1'],0,0,True) nodes, edges = process_main(['doi1'],0,0,True)
self.assertCountEqual(nodes,['doi1']) self.assertCountEqual(nodes,['doi1'])
self.assertCountEqual(edges, []) self.assertCountEqual(edges, [])
...@@ -31,10 +31,36 @@ class ProcessingTest(unittest.TestCase): ...@@ -31,10 +31,36 @@ class ProcessingTest(unittest.TestCase):
self.assertCountEqual(edges, [['doi3', 'doi1'], ['doi1', 'doi2']]) self.assertCountEqual(edges, [['doi3', 'doi1'], ['doi1', 'doi2']])
def testInnerEdges(self): def testInnerEdges(self):
nodes, edges = process_main(['doi_ie1'],1,1,True) nodes, edges = process_main(['doi_ie1'],1,1,True)
self.assertCountEqual(nodes,['doi_ie1','doi_ie2','doi_ie3']) self.assertCountEqual(nodes,['doi_ie1','doi_ie2','doi_ie3'])
self.assertCountEqual(edges,[['doi_ie1','doi_ie2'],['doi_ie3','doi_ie1'],['doi_ie3','doi_ie2']]) self.assertCountEqual(edges,[['doi_ie1','doi_ie2'],['doi_ie3','doi_ie1'],['doi_ie3','doi_ie2']])
def testRightHeight(self):
nodes, edges = process_main(['doi_h01'],1,0,True)
self.assertCountEqual(nodes,['doi_h01'])
self.assertCountEqual(edges, [])
nodes, edges = process_main(['doi_h02'],1,0,True)
self.assertCountEqual(nodes,['doi_h02','doi_h1'])
self.assertCountEqual(edges, [['doi_h1','doi_h02']])
nodes, edges = process_main(['doi_h02'],2,0,True)
self.assertCountEqual(nodes,['doi_h02','doi_h1','doi_h2'])
self.assertCountEqual(edges, [['doi_h1','doi_h02'], ['doi_h2','doi_h1']])
def testRightDepth(self):
nodes, edges = process_main(['doi_d01'],0,1,True)
self.assertCountEqual(nodes,['doi_d01'])
self.assertCountEqual(edges, [])
nodes, edges = process_main(['doi_d02'],0,1,True)
self.assertCountEqual(nodes,['doi_d02','doi_d1'])
self.assertCountEqual(edges, [['doi_d02','doi_d1']])
nodes, edges = process_main(['doi_d02'],0,2,True)
self.assertCountEqual(nodes,['doi_d02','doi_d1','doi_d2'])
self.assertCountEqual(edges, [['doi_d02','doi_d1'], ['doi_d1','doi_d2']])
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
\ No newline at end of file
File added
No preview for this file type
No preview for this file type
...@@ -67,4 +67,16 @@ inner_edge1 = ['doi_ie1', 'title_ie1', ['contributor_ie1.1', 'contributor_ie1.2' ...@@ -67,4 +67,16 @@ inner_edge1 = ['doi_ie1', 'title_ie1', ['contributor_ie1.1', 'contributor_ie1.2'
inner_edge2 = ['doi_ie2', 'title_ie2', ['contributor_ie2.1', 'contributor_ie2.2'], 'journal_ie2', 'date_ie2', [], ['doi_ie1','doi_ie3'], ''] inner_edge2 = ['doi_ie2', 'title_ie2', ['contributor_ie2.1', 'contributor_ie2.2'], 'journal_ie2', 'date_ie2', [], ['doi_ie1','doi_ie3'], '']
inner_edge3 = ['doi_ie3', 'titlez_ie3', ['contributor_ie3.1', 'contributor_ie3.2'], 'journal_ie3', 'date_ie3', ['doi_ie1','doi_ie2'], [], ''] inner_edge3 = ['doi_ie3', 'titlez_ie3', ['contributor_ie3.1', 'contributor_ie3.2'], 'journal_ie3', 'date_ie3', ['doi_ie1','doi_ie2'], [], '']
list_of_arrays = [beispiel1, beispiel2, beispiel3, zyklus1, zyklus2, inner_edge1, inner_edge2, inner_edge3] right_height01 = ['doi_h01', 'title_h01', ['contributor_h01'], 'journal_h01', 'date_h01', [], [], '']
right_height02 = ['doi_h02', 'title_h02', ['contributor_h02'], 'journal_h02', 'date_h02', [], ['doi_h1'], '']
right_height1 = ['doi_h1', 'title_h1', ['contributor_h1'], 'journal_h1', 'date_h1', [], ['doi_h2'], '']
right_height2 = ['doi_h2', 'title_h2', ['contributor_h2'], 'journal_h2', 'date_h2', [], ['doi_h3'], '']
right_height3 = ['doi_h3', 'title_h3', ['contributor_h3'], 'journal_h3', 'date_h3', [], [], '']
right_depth01 = ['doi_d01', 'title_d01', ['contributor_d01'], 'journal_d01', 'date_d01', [], [], '']
right_depth02 = ['doi_d02', 'title_d02', ['contributor_d02'], 'journal_d02', 'date_d02', ['doi_d1'], [], '']
right_depth1 = ['doi_d1', 'title_d1', ['contributor_d1'], 'journal_d1', 'date_d1', ['doi_d2'], [], '']
right_depth2 = ['doi_d2', 'title_d2', ['contributor_d2'], 'journal_d2', 'date_d2', ['doi_d3'], [], '']
right_depth3 = ['doi_d3', 'title_d3', ['contributor_d3'], 'journal_d3', 'date_d3', [], [], '']
list_of_arrays = [beispiel1, beispiel2, beispiel3, zyklus1, zyklus2, inner_edge1, inner_edge2, inner_edge3, right_height01, right_height02, right_height1, right_height2, right_height3, right_depth01, right_depth02, right_depth1, right_depth2, right_depth3]
{"nodes": [{"name": "title_ie1", "author": ["contributor_ie1.1", "contributor_ie1.2"], "year": "date_ie1", "journal": "journal_ie1", "doi": "doi_ie1", "group": "input"}, {"name": "titlez_ie3", "author": ["contributor_ie3.1", "contributor_ie3.2"], "year": "date_ie3", "journal": "journal_ie3", "doi": "doi_ie3", "group": "height"}, {"name": "title_ie2", "author": ["contributor_ie2.1", "contributor_ie2.2"], "year": "date_ie2", "journal": "journal_ie2", "doi": "doi_ie2", "group": "depth"}], "links": [{"source": "doi_ie3", "target": "doi_ie1"}, {"source": "doi_ie1", "target": "doi_ie2"}, {"source": "doi_ie3", "target": "doi_ie2"}]} {"nodes": [{"name": "title_h02", "author": ["contributor_h02"], "year": "date_h02", "journal": "journal_h02", "doi": "doi_h02", "group": "input"}, {"name": "title_h1", "author": ["contributor_h1"], "year": "date_h1", "journal": "journal_h1", "doi": "doi_h1", "group": "height"}, {"name": "title_h2", "author": ["contributor_h2"], "year": "date_h2", "journal": "journal_h2", "doi": "doi_h2", "group": "height"}], "links": [{"source": "doi_h1", "target": "doi_h02"}, {"source": "doi_h2", "target": "doi_h1"}]}
\ No newline at end of file \ 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