From 0e469abe6c34a61fd2f69c4efd3a8e1e65f5f2f9 Mon Sep 17 00:00:00 2001 From: Alex Skrenchuk Date: Mon, 25 Nov 2024 23:26:10 -0800 Subject: [PATCH 1/3] tidy up unit tests - comply with minitest style guide - fix the use of assigment operator (=) instead of equality operator (==) - add unit test failure message for debugging https://github.com/ncbo/ncbo_annotator/issues/40 --- Gemfile | 3 +- Gemfile.lock | 4 +- test/test_annotator.rb | 139 +++++++++++++++++++++-------------------- 3 files changed, 75 insertions(+), 71 deletions(-) diff --git a/Gemfile b/Gemfile index f45945cb..a33fac70 100644 --- a/Gemfile +++ b/Gemfile @@ -16,5 +16,6 @@ end # NCBO gems (can be from a local dev path or from rubygems/git) gem 'goo', github: 'ncbo/goo', branch: 'develop' -gem 'ontologies_linked_data', github: 'ncbo/ontologies_linked_data', branch: 'develop' +# gem 'ontologies_linked_data', github: 'ncbo/ontologies_linked_data', branch: 'develop' +gem 'ontologies_linked_data', github: 'ncbo/ontologies_linked_data', tag: 'v5.33.0' gem 'sparql-client', github: 'ncbo/sparql-client', branch: 'develop' diff --git a/Gemfile.lock b/Gemfile.lock index 91f702db..9c7463a8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,8 +16,8 @@ GIT GIT remote: https://github.com/ncbo/ontologies_linked_data.git - revision: db05a3b22c4187fb73dd83312a038fb7f7741271 - branch: develop + revision: 9ab4be437ed84f5a480e7f0d8799824fcea310ae + tag: v5.33.0 specs: ontologies_linked_data (0.0.1) activesupport diff --git a/test/test_annotator.rb b/test/test_annotator.rb index f63e0235..58ca9718 100644 --- a/test/test_annotator.rb +++ b/test/test_annotator.rb @@ -251,16 +251,17 @@ def test_annotate with_synonyms: true }) direct = annotations - assert direct.length >= size && direct.length > 0 + assert_operator 0, :<, direct.length + assert_operator size, :<, direct.length found = 0 class_page.each do |cls| if cls.prefLabel.length > 2 #TODO: This assertion may fail if the dictionary file on mgrep server does not contain the terms from the test ontologies - assert (direct.select { |x| x.annotatedClass.id.to_s == cls.id.to_s }).length > 0 + assert_operator 0, :<, (direct.select { |x| x.annotatedClass.id.to_s == cls.id.to_s }).length, "expected to find #{cls.id}" found += 1 end end - assert found >= size + assert_operator size, :<=, found end # test for a specific class annotation @@ -279,12 +280,12 @@ def test_annotate with_synonyms: true }) - assert annotations.length == 1 - assert annotations.first.annotatedClass.id.to_s == "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Data_Storage" - assert annotations.first.annotations.length == 1 - assert annotations.first.annotations.first[:from] == 1 - assert annotations.first.annotations.first[:to] == term_text.length - assert text[annotations.first.annotations.first[:from] - 1, annotations.first.annotations.first[:to]] == term_text + assert_equal 1, annotations.length + assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Data_Storage", annotations.first.annotatedClass.id.to_s + assert_equal 1, annotations.first.annotations.length + assert_equal 1, annotations.first.annotations.first[:from] + assert_equal term_text.length, annotations.first.annotations.first[:to] + assert_equal term_text, text[annotations.first.annotations.first[:from] - 1, annotations.first.annotations.first[:to]] # check for a non-existent ontology non_existent_ont = ["DOESNOTEXIST"] @@ -370,14 +371,15 @@ def test_annotate_minsize_term }) direct = annotations - assert direct.length >= size && direct.length > 0 + assert_operator 0, :<, direct.length + assert_operator size, :<, direct.length found = 0 filter_out_next = [] must_be_next = [] class_page.each do |cls| if cls.prefLabel.length > 2 #TODO: This assertion may fail if the dictionary file on mgrep server does not contain the terms from the test ontologies - assert (direct.select { |x| x.annotatedClass.id.to_s == cls.id.to_s }).length > 0 + assert_operator 0, :<, (direct.select { |x| x.annotatedClass.id.to_s == cls.id.to_s }).length found += 1 if cls.prefLabel.length < 10 filter_out_next << cls @@ -403,12 +405,13 @@ def test_annotate_minsize_term direct = annotations filter_out_next.each do |cls| - assert (direct.select { |x| x.annotatedClass.id.to_s == cls.id.to_s }).length == 0 + assert_equal 0, (direct.select { |x| x.annotatedClass.id.to_s == cls.id.to_s }).length end must_be_next.each do |cls| - assert (direct.select { |x| x.annotatedClass.id.to_s == cls.id.to_s }).length > 0 + assert_operator 0, :<, (direct.select { |x| x.annotatedClass.id.to_s == cls.id.to_s }).length end - assert must_be_next.length > 0 && filter_out_next.length > 0 + assert_operator 0, :<, must_be_next.length + assert_operator 0, :<, filter_out_next.length end def test_annotate_stop_words @@ -430,7 +433,7 @@ def test_annotate_stop_words "http://purl.obolibrary.org/obo/MCBCC_0000296#Deletion"] not_show.each do |cls| - assert (annotations.select { |x| x.annotatedClass.id.to_s == cls }).length > 0 + assert_operator 0, :<, (annotations.select { |x| x.annotatedClass.id.to_s == cls }).length end #annotation should not show up @@ -449,7 +452,7 @@ def test_annotate_stop_words }) not_show.each do |cls| - assert (annotations.select { |x| x.annotatedClass.id.to_s == cls }).length == 0 + assert_equal 0, (annotations.select { |x| x.annotatedClass.id.to_s == cls }).length end #empty array must annotate all @@ -468,7 +471,7 @@ def test_annotate_stop_words }) not_show.each do |cls| - assert (annotations.select { |x| x.annotatedClass.id.to_s == cls }).length > 0 + assert_operator 0, :<, (annotations.select { |x| x.annotatedClass.id.to_s == cls }).length end end @@ -477,16 +480,16 @@ def test_annotate_hierarchy text = "Aggregate Human Data Aggregate Human Data" annotator = Annotator::Models::NcboAnnotator.new annotations = annotator.annotate(text) - assert annotations.length == 1 - assert annotations.first.annotatedClass.id.to_s == "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Aggregate_Human_Data" - assert annotations.first.annotatedClass.submission.ontology.acronym == "BROTEST-0" - assert annotations.first.annotations.length == 2 - assert annotations.first.annotations.first[:from] = 1 - assert annotations.first.annotations.first[:to] = 1+("Aggregate Human Data".length) - assert annotations.first.annotations[1][:from] = 2 + ("Aggregate Human Data".length) - assert text[annotations.first.annotations.first[:from]-1,annotations.first.annotations.first[:to]-1] == "Aggregate Human Data" - assert annotations.first.annotations[1][:to] == (1 + ("Aggregate Human Data".length)) + ("Aggregate Human Data".length) - assert text[annotations.first.annotations[1][:from]-1,annotations.first.annotations[1][:to]-1] == "Aggregate Human Data" + assert_equal 1, annotations.length + assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Aggregate_Human_Data", annotations.first.annotatedClass.id.to_s + assert_equal "BROTEST-0", annotations.first.annotatedClass.submission.ontology.acronym + assert_equal 2, annotations.first.annotations.length + assert_equal 1, annotations.first.annotations.first[:from] + assert_equal "Aggregate Human Data".length, annotations.first.annotations.first[:to] + assert_equal 2 + ("Aggregate Human Data".length), annotations.first.annotations[1][:from] + assert_equal "Aggregate Human Data", text[annotations.first.annotations.first[:from]-1,annotations.first.annotations.first[:to]] + assert_equal (1 + ("Aggregate Human Data".length)) + ("Aggregate Human Data".length), annotations.first.annotations[1][:to] + assert_equal "Aggregate Human Data", text[annotations.first.annotations[1][:from]-1,annotations.first.annotations[1][:to]-1] annotations = annotator.annotate(text, { ontologies: [], semantic_types: [], @@ -499,16 +502,16 @@ def test_annotate_hierarchy with_synonyms: true }) - assert annotations.length == 1 - assert annotations.first.annotatedClass.id.to_s == "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Aggregate_Human_Data" - assert annotations.first.annotatedClass.submission.ontology.acronym == "BROTEST-0" - assert annotations.first.annotations.length == 2 - assert annotations.first.annotations.first[:from] = 1 - assert annotations.first.annotations.first[:to] = 1+("Aggregate Human Data".length) + assert_equal 1, annotations.length + assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Aggregate_Human_Data", annotations.first.annotatedClass.id.to_s + assert_equal "BROTEST-0", annotations.first.annotatedClass.submission.ontology.acronym + assert_equal 2, annotations.first.annotations.length + assert_equal 1, annotations.first.annotations.first[:from] + assert_equal "Aggregate Human Data".length, annotations.first.annotations.first[:to] - assert annotations.first.hierarchy.length == 1 - assert annotations.first.hierarchy.first.annotatedClass.id.to_s == "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Clinical_Care_Data" - assert annotations.first.hierarchy.first.distance == 1 + assert_equal 1, annotations.first.hierarchy.length + assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Clinical_Care_Data", annotations.first.hierarchy.first.annotatedClass.id.to_s + assert_equal 1, annotations.first.hierarchy.first.distance annotations = annotator.annotate(text, { ontologies: [], semantic_types: [], @@ -521,13 +524,13 @@ def test_annotate_hierarchy with_synonyms: true }) - assert annotations.first.hierarchy.length == 3 - assert annotations.first.hierarchy.first.annotatedClass.id.to_s == "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Clinical_Care_Data" - assert annotations.first.hierarchy.first.distance == 1 - assert annotations.first.hierarchy[1].annotatedClass.id.to_s == "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Data_Resource" - assert annotations.first.hierarchy[1].distance == 2 - assert annotations.first.hierarchy[2].annotatedClass.id.to_s == "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Information_Resource" - assert annotations.first.hierarchy[2].distance == 3 + assert_equal 3, annotations.first.hierarchy.length + assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Clinical_Care_Data", annotations.first.hierarchy.first.annotatedClass.id.to_s + assert_equal 1, annotations.first.hierarchy.first.distance + assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Data_Resource", annotations.first.hierarchy[1].annotatedClass.id.to_s + assert_equal 2, annotations.first.hierarchy[1].distance + assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Information_Resource", annotations.first.hierarchy[2].annotatedClass.id.to_s + assert_equal 3, annotations.first.hierarchy[2].distance end def test_annotate_hierachy_terms_multiple @@ -546,56 +549,56 @@ def test_annotate_hierachy_terms_multiple with_synonyms: true }) - assert annotations[0].annotatedClass.id.to_s == "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Aggregate_Human_Data" - assert annotations[0].annotations.length == 3 - assert annotations[0].hierarchy.length == 4 + assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Aggregate_Human_Data", annotations[0].annotatedClass.id.to_s + assert_equal 3, annotations[0].annotations.length + assert_equal 4, annotations[0].hierarchy.length hhh = annotations[0].hierarchy.sort {|x| x.distance }.map { |x| x.annotatedClass.id.to_s } hhh.sort! - assert hhh == [ + assert_equal [ "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Resource", "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Information_Resource", "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Clinical_Care_Data", "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Data_Resource" - ].sort + ].sort, hhh - assert annotations[1].annotatedClass.id.to_s == "http://purl.obolibrary.org/obo/MCBCC_0000288#ChromosomalMutation" - assert annotations[1].annotations.length == 2 + assert_equal "http://purl.obolibrary.org/obo/MCBCC_0000288#ChromosomalMutation", annotations[1].annotatedClass.id.to_s + assert_equal 2, annotations[1].annotations.length hhh = annotations[1].hierarchy.sort {|x| x.distance }.map { |x| x.annotatedClass.id.to_s } - hhh == ["http://purl.obolibrary.org/obo/MCBCC_0000287#GeneticVariation"] + assert_equal ["http://purl.obolibrary.org/obo/MCBCC_0000287#GeneticVariation"], hhh - assert annotations[2].annotatedClass.id.to_s == "http://purl.obolibrary.org/obo/MCBCC_0000289#ChromosomalDeletion" - assert annotations[2].annotations.length == 1 + assert_equal "http://purl.obolibrary.org/obo/MCBCC_0000289#ChromosomalDeletion", annotations[2].annotatedClass.id.to_s + assert_equal 1, annotations[2].annotations.length hhh = annotations[2].hierarchy.sort {|x| x.distance }.map { |x| x.annotatedClass.id.to_s } assert hhh == ["http://purl.obolibrary.org/obo/MCBCC_0000287#GeneticVariation", "http://purl.obolibrary.org/obo/MCBCC_0000288#ChromosomalMutation"] - assert annotations[3].annotatedClass.id.to_s == "http://purl.obolibrary.org/obo/MCBCC_0000296#Deletion" + assert_equal "http://purl.obolibrary.org/obo/MCBCC_0000296#Deletion", annotations[3].annotatedClass.id.to_s hhh = annotations[3].hierarchy.sort {|x| x.distance }.map { |x| x.annotatedClass.id.to_s } - assert hhh = ["http://purl.obolibrary.org/obo/MCBCC_0000287#GeneticVariation", - "http://purl.obolibrary.org/obo/MCBCC_0000295#GeneMutation"] + assert_equal ["http://purl.obolibrary.org/obo/MCBCC_0000287#GeneticVariation", + "http://purl.obolibrary.org/obo/MCBCC_0000295#GeneMutation"], hhh - assert annotations[4].annotatedClass.id.to_s == "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Data_Resource" + assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Data_Resource", annotations[4].annotatedClass.id.to_s hhh = annotations[4].hierarchy.sort {|x| x.distance }.map { |x| x.annotatedClass.id.to_s } - assert hhh == ["http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Resource", - "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Information_Resource"] + assert_equal ["http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Resource", + "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Information_Resource"], hhh - assert annotations[5].annotatedClass.id.to_s == "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Resource" + assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Resource", annotations[5].annotatedClass.id.to_s hhh = annotations[5].hierarchy.sort {|x| x.distance }.map { |x| x.annotatedClass.id.to_s } - assert hhh == [] #root + assert_empty hhh - assert annotations[6].annotatedClass.id.to_s == "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Federal_Funding_Resource" + assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Federal_Funding_Resource", annotations[6].annotatedClass.id.to_s hhh = annotations[6].hierarchy.sort {|x| x.distance }.map { |x| x.annotatedClass.id.to_s } - assert hhh == ["http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Resource", - "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Funding_Resource"] + assert_equal ["http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Resource", + "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Funding_Resource"], hhh - assert annotations[7].annotatedClass.id.to_s == "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Funding_Resource" + assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Funding_Resource", annotations[7].annotatedClass.id.to_s hhh = annotations[7].hierarchy.sort {|x| x.distance }.map { |x| x.annotatedClass.id.to_s } - assert hhh == ["http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Resource" ] + assert_equal ["http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Resource" ], hhh - assert annotations[8].annotatedClass.id.to_s == "http://purl.obolibrary.org/obo/MCBCC_0000275#ReceptorAntagonists" + assert_equal "http://purl.obolibrary.org/obo/MCBCC_0000275#ReceptorAntagonists", annotations[8].annotatedClass.id.to_s hhh = annotations[8].hierarchy.sort {|x| x.distance }.map { |x| x.annotatedClass.id.to_s } - assert hhh == ["http://purl.obolibrary.org/obo/MCBCC_0000256#ChemicalsAndDrugs"] + assert_equal ["http://purl.obolibrary.org/obo/MCBCC_0000256#ChemicalsAndDrugs"], hhh end From c0222c9c94a814b577c98e93a141dba4d7ecc59c Mon Sep 17 00:00:00 2001 From: Alex Skrenchuk Date: Mon, 25 Nov 2024 23:37:28 -0800 Subject: [PATCH 2/3] use ontologies_linked_data v5.33.4 --- Gemfile | 4 ++-- Gemfile.lock | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index a33fac70..76da6f6f 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,6 @@ end # NCBO gems (can be from a local dev path or from rubygems/git) gem 'goo', github: 'ncbo/goo', branch: 'develop' -# gem 'ontologies_linked_data', github: 'ncbo/ontologies_linked_data', branch: 'develop' -gem 'ontologies_linked_data', github: 'ncbo/ontologies_linked_data', tag: 'v5.33.0' +gem 'ontologies_linked_data', github: 'ncbo/ontologies_linked_data', branch: 'develop' +# gem 'ontologies_linked_data', github: 'ncbo/ontologies_linked_data', tag: 'v5.33.0' gem 'sparql-client', github: 'ncbo/sparql-client', branch: 'develop' diff --git a/Gemfile.lock b/Gemfile.lock index 9c7463a8..693255c7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,8 +16,8 @@ GIT GIT remote: https://github.com/ncbo/ontologies_linked_data.git - revision: 9ab4be437ed84f5a480e7f0d8799824fcea310ae - tag: v5.33.0 + revision: 6389fa2052e06ff8e21c64fd1be0030beca4c828 + branch: develop specs: ontologies_linked_data (0.0.1) activesupport From 2856de7db0067b5ddd3fc6972bad66ceadd88463 Mon Sep 17 00:00:00 2001 From: Alex Skrenchuk Date: Tue, 26 Nov 2024 16:53:18 -0800 Subject: [PATCH 3/3] use mgrep with updated dictionary.txt --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 6c55b6bd..2215312d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -80,7 +80,7 @@ services: retries: 10 mgrep-ut: - image: ontoportal/mgrep:0.0.2 + image: ontoportal/mgrep:0.0.3 platform: linux/amd64 healthcheck: test: ["CMD", "nc", "-z", "-v", "127.0.0.1", "55556"]