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 zcmcgt&2HO95Z>kQQkG@eaT42c+Qw;;s(=NE0(uCFHh=@9mkL3Q00p6fpgFX_n33cq zS-=8)avr4ZO)t^M=z-Us^a?$7X7yvqL4qPEN@2d;+1VY<%+AgP>+2PU-`@AX2Y)z> z{YA|3Cy;rDl>UkEf&l~m4(Uqsh|@qvPDhR-XMl;EiJS%&*zcI9g8&Cd11hkFqX|`5 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(;2BuVKVm-hC>QB{^GSmJdJwlfOEr_0 zx7<xyo|tu$7It%NAuYApRoE`s?2x;1$Xy(Ar-$6xw)V=l_F`Lmx~*NBXvnDL*~*ep zYqYV{*ha19dke1T%*?}67TJfRQsT~)xT{Lsn@Zf~k`gpjDRDcEs(KJAQ6xQSmD1|A zrHYw@tt%bIQPT1jQ`9tHZF~0U;w;Hi^kzD7RR%64ma0Znh)VJ8v?qP1+6>jJ+Ez`} Sgs_DW&K}?4JK8?q*Zu)Q#0aqf 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 zcmYk2zfQw25XOCp<2Y$rx**X%3?L*_BqZ27Ga@7g)Gm?11rkD1OfnQ1F;vVbiePRL zJO?}lLuTHBg-aH=Px|h6pKtNKvme$H&8ADR-gaMwP4m_jeCKyvILe>5H>}XoOwu9I zR>+X7nrtM7WGs08(Rr{tM03e8u%%P8i)=2q=1Tx_6KO+J*{Cw?-jJk@Y|7T$c<SFf zsk>-ss-2|)<b+5<QF9YW+}<a*UwZ^<jnE}ICWDp3lE&hCGG-!6FB4VL+1f;?(hieM z#UdJ;G6_oSLM7R>7{L&{;srLh+SBYb3eH3tB(X0=I#Cw>xU_NE&s3xsPQ@oYLa#V5 zB7dj42e4Wk-TfyIs>G|sfg2vEb=)3MwTi9eK|IY;|2$L%j`fr3RrF{5qG5J_0q9v% AZvX%Q delta 293 zcmYL@y-ve06ov1#9mg?gRi=`P2_d0wz?^63!hqVPiewOhl7LB;%7~$2M97NDoDRGJ z15d!fBUIu^Sa7^>k95v=e}?<Z-+4dl^(44jrZ)Sawts_Pb~(aRyFQ|%4eU?y#1b$< z1u2+NanGS++6G2!5aE7eh+#@}GnY{c6<1R2tjO#BV^oE$Fw8_7f^ZHBnA3_P6oV6Z z_&f&mnmSi-2IF|LWkq&-G2>ZXU6p!96)E%P1yhWgZ#)p8D)V`*7tMe?<FI)ni|Jwa wKXNbOT%sfrW9&Hg5-3QFI&pVnrgvRzMPA(1)%@~W6W98c9(MF^drd}1f1-Fg`~Uy| 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