From 2ca8d152058458857944e1c5e9f116fdb744a9c3 Mon Sep 17 00:00:00 2001 From: Malte Schokolowski <baw8441@uni-hamburg.de> Date: Sat, 27 Nov 2021 15:30:26 +0100 Subject: [PATCH] added test functunality --- verarbeitung/Processing.py | 81 +++++++++++------- .../__pycache__/input_test.cpython-39.pyc | Bin 0 -> 2495 bytes .../__pycache__/json_demo.cpython-39.pyc | Bin 805 -> 891 bytes verarbeitung/input_test.py | 5 +- verarbeitung/json_text.json | 2 +- "verarbeitung/n\303\266tige Tests.txt" | 4 + 6 files changed, 61 insertions(+), 31 deletions(-) create mode 100644 verarbeitung/__pycache__/input_test.cpython-39.pyc create mode 100644 "verarbeitung/n\303\266tige Tests.txt" diff --git a/verarbeitung/Processing.py b/verarbeitung/Processing.py index 89f1ef2..ac85f52 100644 --- a/verarbeitung/Processing.py +++ b/verarbeitung/Processing.py @@ -25,9 +25,13 @@ from json_demo import output_to_json # doi_input_list: list of publication dois from user # 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: - pub = input_test_func(pub_doi) + if(test_var): + pub = input_test_func(pub_doi) + else: + pub = input(pub_doi) + not_in_nodes = True for node in nodes: # checks if a pub is already in nodes if (pub.doi_url == node.doi_url): @@ -35,6 +39,7 @@ def initialize_nodes_list(doi_input_list): break if (not_in_nodes): nodes.append(pub) + #print(pub.doi_url) pub.group = "input" else: doi_input_list.remove(pub_doi) @@ -55,11 +60,11 @@ def create_graph_structure_citations(pub, search_height, search_height_max): if (search_height <= search_height_max): citation.group = "height" 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 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): if (search_depth <= search_depth_max): reference.group = "depth" 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 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): # doi_citations: input list of citet dois # search_height: current search_height of height-first-search # 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 search_height += 1 # create class object for every citation from list 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) # 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. @@ -109,7 +118,7 @@ def process_citations_rec(doi_citations, search_height, search_height_max): citations_list.append(citation.doi_url) # 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): # doi_references: input list of referenced dois # search_depth: current search_depth of height-first-search # 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 search_depth += 1 # create class object for every citation from list 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) # 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. @@ -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 # 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) + # 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 if (len(doi_input_list) == 0): print("Error, no input data") @@ -161,16 +175,33 @@ def process_main(doi_input_list, search_height, search_depth): nodes = [] edges = [] - initialize_nodes_list(doi_input_list) - process_citations_rec(doi_input_list, 0, search_height) - process_references_rec(doi_input_list, 0, search_depth) + initialize_nodes_list(doi_input_list,test_var) + process_citations_rec(doi_input_list, 0, search_height, test_var) + process_references_rec(doi_input_list, 0, search_depth, test_var) output_to_json(nodes,edges) # only for internal testing 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. def test_print(): @@ -185,19 +216,11 @@ def test_print(): #url = sys.argv[1] #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") - for node in nodes: - print(node.title, "\n") - print("\n Kanten:\n") - for edge in edges: - print(edge,"\n") + print_graph(nodes, edges) -test_print() +#test_print() +test_cycle() \ No newline at end of file diff --git a/verarbeitung/__pycache__/input_test.cpython-39.pyc b/verarbeitung/__pycache__/input_test.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d5948ff804073098a6d097ad17e81503eb7ec86b GIT binary patch literal 2495 zcmYe~<>g{vU|^84UzE6ylY!weh=Ytd7#J8F7#J9euQ4z%xHF_Mq%gKHq%bx!MS*xs zDa<VlDa_4GQH<^kDJ&_hEet8F%}h~DDQqe1Eeui2DI6)BEeugCDO@SsEeuhtDLg5> zDSYXSDf}q{DT3*YDMIOtDZ=R-QEVxKDIzJN>5M62DdOo2DLhbd_7tHMi4@6n#uTX( zX^?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ezyt0UKO%?5r<LX<D}%fbDiRnNIT(2u z%@~VR85kH)0s-U(cpwBZFfgPufC9jUA=agq2^=6+wahh4HO$Ze5vXBYz*qw1*D!+v zg*gQjD9kCKKw(Z{m1JmUUC7ADP$*EyQNtL_u#(NMND>syQXm2pB}JgvEs_P5P|QV& z3=9mn*b)m0Qu9*4iBps176&*CQt~sSSdueKiXj;a<Qp^}7lE9v1@a}RxMN^s0hKt6 zJdApbU>SP*v`7u)Lv;oQ22GYCO$G*rD3+qsG(67dWME)0!s>jGOcYB>ex_j*8@Mtt zj6$wW45K)pwTWRAE2s)F1S>WIlg76gpqh+OG#SA)89_7|L6sS!C^LpDGlnQLzQvl7 zpIK!X#SV5!m0=Y>QpHwfsD~k76vYX3UX@`K8_0cCAa~|xRvEzzF+w%O2;C4PJtRYn zpoSRvY4U(G1UR7-fwD9>NrPj%2pnddNvWB|1(~TihEZ^)5rSzP#a>mJol{zD2xAz5 tQy@~pLgXh78%UjG2g<m`pz?}Oh>wGhgM*!egM(9wQG!u|Nrq8|2>?RG2(bVF literal 0 HcmV?d00001 diff --git a/verarbeitung/__pycache__/json_demo.cpython-39.pyc b/verarbeitung/__pycache__/json_demo.cpython-39.pyc index 29c2c14b5229d9768c2a273f8e1adba6cfcfc63f..a4f37b5097c0c5a82e7d36cd45671fb178e749ca 100644 GIT binary patch delta 379 zcmZ3=_M43_k(ZZ?fq{WxiSD9Ac9w~J*^EynR!K1iOq{B&$eP7k!<NEg!%)MT#a6?X z!U|@w*RZ9q*)Y^FE#R2AU$UNElA(qpg~NuShCPK7%;vITs9|2fQNyv2k&&S=r-rG9 zC50O#R>P9QW5ZCwnZldG*UZ!}Q_ESxwSc>ZrG|4M6C*=7Lka^60}DelGb2NufFVQi zH3J4lFpOkiWJqBMX3*sKyTy{1n422KmRMSnkzaI+rBWg_vFH|iR(@$wUSduZb4q^Z zE!Om+{L+HSk&HHsJd>v}Dyaw*lqTh5CMT9;=I6zyB$lKWu`)0)++t73&x|iE$|+)F zU|^VhfU%WPda@f+PP`T<JQ&%)kb{wpkqZg(FoHyQ7(tMOk%Nhcu}GGIfkBg{NEBow eM`m6@X-RxqRuK~e0|Qv9NE*aK5HgdwnWX^eSyOKS delta 293 zcmey(wv>%8k(ZZ?fq{Xc%4TBX7Uqe3*^I{~R!K1$O`NLE%(Q@Y;$6vl7D<L0juciK zh8p%1HZYsrhM|Ue0c#D%LPkc0LcbcO8kQ6ekXQ{%3a1T230n$R3U@P8zf3J>3Ht($ z8kQQ)g-nbL;S4DZEDS6R&CHApc>;zE#XAfb7{M@-fsrAFA(%mv$L|(PUSe))6kB3x zNk)EA6mtqwe&*y}MjJ-X$)^~VIM`G2GviB(awZEfwK9rNp2n0DsRD98BO4fUFtRan zF>*0+G4e2i*gT9N$ic|L#KTx5$-uy%$x<Z9z`$^eBQvj{v?M+)tB8q#fdMR4Bo1OB K2#Lvw%u)cNcsl$5 diff --git a/verarbeitung/input_test.py b/verarbeitung/input_test.py index 79b00b1..c55f852 100644 --- a/verarbeitung/input_test.py +++ b/verarbeitung/input_test.py @@ -60,4 +60,7 @@ beispiel1 = ['doi1', 'title1', ['contributor1'], 'journal1', 'date1', ['doi2'], beispiel2 = ['doi2', 'title2', ['contributor2'], 'journal2', 'date2', [], ['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] diff --git a/verarbeitung/json_text.json b/verarbeitung/json_text.json index 683e49f..8f648bf 100644 --- a/verarbeitung/json_text.json +++ b/verarbeitung/json_text.json @@ -1 +1 @@ -{"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"}]} \ No newline at end of file +{"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 diff --git "a/verarbeitung/n\303\266tige Tests.txt" "b/verarbeitung/n\303\266tige Tests.txt" new file mode 100644 index 0000000..9556328 --- /dev/null +++ "b/verarbeitung/n\303\266tige Tests.txt" @@ -0,0 +1,4 @@ +Zyklus +großer Zyklus +Innere Kanten vervollständigen + -- GitLab