From 84f079ef8464b9c0e9916d344cbb30ad136b3f57 Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Mon, 6 May 2024 14:33:46 +0200 Subject: [PATCH] add multilingual search unit tests --- test/controllers/test_search_controller.rb | 100 ++++++++++++++++----- test/data/ontology_files/BRO_v3.2.owl | 3 + 2 files changed, 81 insertions(+), 22 deletions(-) diff --git a/test/controllers/test_search_controller.rb b/test/controllers/test_search_controller.rb index 70bf246e..851616f7 100644 --- a/test/controllers/test_search_controller.rb +++ b/test/controllers/test_search_controller.rb @@ -85,7 +85,7 @@ def test_search_ontology_filter assert last_response.ok? results = MultiJson.load(last_response.body) doc = results["collection"][0] - assert_equal "cell line", doc["prefLabel"] + assert_equal "cell line", doc["prefLabel"].first assert doc["links"]["ontology"].include? acronym results["collection"].each do |doc| acr = doc["links"]["ontology"].split('/')[-1] @@ -103,7 +103,8 @@ def test_search_other_filters get "search?q=data&require_definitions=true" assert last_response.ok? results = MultiJson.load(last_response.body) - assert_equal 26, results["collection"].length + assert results["collection"].all? {|doc| !doc["definition"].nil? && doc.values.flatten.join(" ").include?("data") } + #assert_equal 26, results["collection"].length get "search?q=data&require_definitions=false" assert last_response.ok? @@ -115,10 +116,14 @@ def test_search_other_filters get "search?q=Integration%20and%20Interoperability&ontologies=#{acronym}" results = MultiJson.load(last_response.body) - assert_equal 22, results["collection"].length + + assert results["collection"].all? { |x| !x["obsolete"] } + count = results["collection"].length + get "search?q=Integration%20and%20Interoperability&ontologies=#{acronym}&also_search_obsolete=false" results = MultiJson.load(last_response.body) - assert_equal 22, results["collection"].length + assert_equal count, results["collection"].length + get "search?q=Integration%20and%20Interoperability&ontologies=#{acronym}&also_search_obsolete=true" results = MultiJson.load(last_response.body) assert_equal 29, results["collection"].length @@ -134,8 +139,14 @@ def test_search_other_filters # testing cui and semantic_types flags get "search?q=Funding%20Resource&ontologies=#{acronym}&include=prefLabel,synonym,definition,notation,cui,semanticType" results = MultiJson.load(last_response.body) - assert_equal 35, results["collection"].length - assert_equal "Funding Resource", results["collection"][0]["prefLabel"] + #assert_equal 35, results["collection"].length + assert results["collection"].all? do |r| + ["prefLabel", "synonym", "definition", "notation", "cui", "semanticType"].map {|x| r[x]} + .flatten + .join(' ') + .include?("Funding Resource") + end + assert_equal "Funding Resource", results["collection"][0]["prefLabel"].first assert_equal "T028", results["collection"][0]["semanticType"][0] assert_equal "X123456", results["collection"][0]["cui"][0] @@ -190,7 +201,7 @@ def test_search_provisional_class assert_equal 10, results["collection"].length provisional = results["collection"].select {|res| assert_equal ontology_type, res["ontologyType"]; res["provisional"]} assert_equal 1, provisional.length - assert_equal @@test_pc_root.label, provisional[0]["prefLabel"] + assert_equal @@test_pc_root.label, provisional[0]["prefLabel"].first # subtree root with provisional class test get "search?ontology=#{acronym}&subtree_root_id=#{CGI::escape(@@cls_uri.to_s)}&also_search_provisional=true" @@ -199,7 +210,7 @@ def test_search_provisional_class provisional = results["collection"].select {|res| res["provisional"]} assert_equal 1, provisional.length - assert_equal @@test_pc_child.label, provisional[0]["prefLabel"] + assert_equal @@test_pc_child.label, provisional[0]["prefLabel"].first end def test_search_obo_id @@ -254,11 +265,11 @@ def test_search_obo_id assert_equal ogms_acronym, LinkedData::Utils::Triples.last_iri_fragment(docs[0]["links"]["ontology"]) assert_equal cno_acronym, LinkedData::Utils::Triples.last_iri_fragment(docs[1]["links"]["ontology"]) assert_equal ncit_acronym, LinkedData::Utils::Triples.last_iri_fragment(docs[2]["links"]["ontology"]) - assert_equal 'realization', docs[1]["prefLabel"] - assert_equal 'realization', docs[2]["prefLabel"] - assert docs[3]["prefLabel"].upcase.include?('OGMS ') - assert docs[4]["prefLabel"].upcase.include?('OGMS ') - assert docs[5]["prefLabel"].upcase.include?('OGMS ') + assert_equal 'realization', docs[1]["prefLabel"].first + assert_equal 'realization', docs[2]["prefLabel"].first + assert docs[3]["prefLabel"].first.upcase.include?('OGMS ') + assert docs[4]["prefLabel"].first.upcase.include?('OGMS ') + assert docs[5]["prefLabel"].first.upcase.include?('OGMS ') get "/search?q=CNO:0000002" assert last_response.ok? @@ -270,10 +281,10 @@ def test_search_obo_id assert acr_1 === ncit_acronym || acr_1 === ogms_acronym acr_2= LinkedData::Utils::Triples.last_iri_fragment(docs[2]["links"]["ontology"]) assert acr_2 === ncit_acronym || acr_2 === ogms_acronym - assert docs[3]["prefLabel"].upcase.include?('CNO ') - assert docs[4]["prefLabel"].upcase.include?('CNO ') - assert docs[5]["prefLabel"].upcase.include?('CNO ') - assert docs[6]["prefLabel"].upcase.include?('CNO ') + assert docs[3]["prefLabel"].first.upcase.include?('CNO ') + assert docs[4]["prefLabel"].first.upcase.include?('CNO ') + assert docs[5]["prefLabel"].first.upcase.include?('CNO ') + assert docs[6]["prefLabel"].first.upcase.include?('CNO ') # mdorf, 3/2/2024, when the : is followed by a LETTER, as in NCIT:C20480, # then Solr does not split the query on the tokens, @@ -284,22 +295,22 @@ def test_search_obo_id results = MultiJson.load(last_response.body) docs = results["collection"] assert_equal 1, docs.size - assert_equal 'Cellular Process', docs[0]["prefLabel"] + assert_equal 'Cellular Process', docs[0]["prefLabel"].first get "/search?q=NCIT:C20480" assert last_response.ok? results = MultiJson.load(last_response.body) docs = results["collection"] assert_equal 1, docs.size - assert_equal 'Cellular Process', docs[0]["prefLabel"] + assert_equal 'Cellular Process', docs[0]["prefLabel"].first get "/search?q=Leukocyte Apoptotic Process&ontologies=#{ncit_acronym}" assert last_response.ok? results = MultiJson.load(last_response.body) docs = results["collection"] - assert_equal 'Leukocyte Apoptotic Process', docs[0]["prefLabel"] - assert_equal 'Leukocyte Apoptotic Test Class', docs[1]["prefLabel"] - assert_equal 'Lymphocyte Apoptotic Process', docs[2]["prefLabel"] + assert_equal 'Leukocyte Apoptotic Process', docs[0]["prefLabel"].first + assert_equal 'Leukocyte Apoptotic Test Class', docs[1]["prefLabel"].first + assert_equal 'Lymphocyte Apoptotic Process', docs[2]["prefLabel"].first ensure ont = LinkedData::Models::Ontology.find(ncit_acronym).first ont.delete if ont @@ -357,4 +368,49 @@ def test_search_short_id end end + def test_multilingual_search + get "/search?q=Activity&ontologies=BROSEARCHTEST-0" + res = MultiJson.load(last_response.body) + refute_equal 0, res["totalCount"] + + doc = res["collection"].select{|doc| doc["@id"].to_s.eql?('http://bioontology.org/ontologies/Activity.owl#Activity')}.first + refute_nil doc + + res = LinkedData::Models::Class.search("prefLabel_none:Activity", {:fq => "submissionAcronym:BROSEARCHTEST-0", :start => 0, :rows => 80}) + refute_equal 0, res["response"]["numFound"] + refute_nil res["response"]["docs"].select{|doc| doc["resource_id"].eql?('http://bioontology.org/ontologies/Activity.owl#Activity')}.first + + get "/search?q=Activit%C3%A9&ontologies=BROSEARCHTEST-0&lang=fr" + res = MultiJson.load(last_response.body) + refute_equal 0, res["totalCount"] + refute_nil res["collection"].select{|doc| doc["@id"].eql?('http://bioontology.org/ontologies/Activity.owl#Activity')}.first + + + + get "/search?q=ActivityEnglish&ontologies=BROSEARCHTEST-0&lang=en" + res = MultiJson.load(last_response.body) + refute_equal 0, res["totalCount"] + refute_nil res["collection"].select{|doc| doc["@id"].eql?('http://bioontology.org/ontologies/Activity.owl#Activity')}.first + + + get "/search?q=ActivityEnglish&ontologies=BROSEARCHTEST-0&lang=fr&require_exact_match=true" + res = MultiJson.load(last_response.body) + assert_nil res["collection"].select{|doc| doc["@id"].eql?('http://bioontology.org/ontologies/Activity.owl#Activity')}.first + + get "/search?q=ActivityEnglish&ontologies=BROSEARCHTEST-0&lang=en&require_exact_match=true" + res = MultiJson.load(last_response.body) + refute_nil res["collection"].select{|doc| doc["@id"].eql?('http://bioontology.org/ontologies/Activity.owl#Activity')}.first + + get "/search?q=Activity&ontologies=BROSEARCHTEST-0&lang=en&require_exact_match=true" + res = MultiJson.load(last_response.body) + assert_nil res["collection"].select{|doc| doc["@id"].eql?('http://bioontology.org/ontologies/Activity.owl#Activity')}.first + + get "/search?q=Activit%C3%A9&ontologies=BROSEARCHTEST-0&lang=fr&require_exact_match=true" + res = MultiJson.load(last_response.body) + refute_nil res["collection"].select{|doc| doc["@id"].eql?('http://bioontology.org/ontologies/Activity.owl#Activity')}.first + + + end + + end diff --git a/test/data/ontology_files/BRO_v3.2.owl b/test/data/ontology_files/BRO_v3.2.owl index d64075cc..b2aeccf5 100644 --- a/test/data/ontology_files/BRO_v3.2.owl +++ b/test/data/ontology_files/BRO_v3.2.owl @@ -631,6 +631,9 @@ Activity + Activity + ActivityEnglish + Activité Activity of interest that may be related to a BRO:Resource. activities