Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deprecate recommender_v1 endpoint
Browse files Browse the repository at this point in the history
syphax-bouazzouni committed Oct 25, 2024
1 parent bd3d004 commit e7c0cba
Showing 4 changed files with 123 additions and 133 deletions.
11 changes: 2 additions & 9 deletions controllers/recommender_v1_controller.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
class RecommenderController < ApplicationController
namespace "/recommender_v1" do

# execute an annotator query
# Mark this route as deprecated
get do
text = params["text"]
raise error 400, "A text to be analyzed by the recommender must be supplied using the argument text=<text>" if text.nil? || text.strip.empty?
acronyms = restricted_ontologies_to_acronyms(params)
display_classes = params['display_classes'].eql?('true') # default will be false
recommender = Recommender::Models::NcboRecommender.new
recommendations = recommender.recommend(text, acronyms, display_classes)
reply 200, recommendations
reply 410, { message: "This API endpoint has been deprecated and is no longer available. Please use /recommender or refer to the API documentation for updated routes." }
end

end
end

38 changes: 5 additions & 33 deletions test/controllers/test_recommender_v1_controller.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
require_relative '../test_case'

# recommender_v1 is deprecated as of 2024-10-27
# TODO: remove completely after 2025-10-27
class TestRecommenderV1Controller < TestCase

def before_suite
LinkedData::SampleData::Ontology.delete_ontologies_and_submissions
@@ontologies = LinkedData::SampleData::Ontology.sample_owl_ontologies(process_submission: true)
@@text = <<eos
Ginsenosides chemistry, biosynthesis, analysis, and potential health effects in software concept or data." "Ginsenosides are a special group of triterpenoid saponins that can be classified into two groups by the skeleton of their aglycones, namely dammarane- and oleanane-type. Ginsenosides are found nearly exclusively in Panax species (ginseng) and up to now more than 150 naturally occurring ginsenosides have been isolated from roots, leaves/stems, fruits, and/or flower heads of ginseng. The same concept indicates Ginsenosides have been the target of a lot of research as they are believed to be the main active principles behind the claims of ginsengs efficacy. The potential health effects of ginsenosides that are discussed in this chapter include anticarcinogenic, immunomodulatory, anti-inflammatory, antiallergic, antiatherosclerotic, antihypertensive, and antidiabetic effects as well as antistress activity and effects on the central nervous system. Ginsensoides can be metabolized in the stomach (acid hydrolysis) and in the gastrointestinal tract (bacterial hydrolysis) or transformed to other ginsenosides by drying and steaming of ginseng to more bioavailable and bioactive ginsenosides. The metabolization and transformation of intact ginsenosides, which seems to play an important role for their potential health effects, are discussed. Qualitative and quantitative analytical techniques for the analysis of ginsenosides are important in relation to quality control of ginseng products and plant material and for the determination of the effects of processing of plant material as well as for the determination of the metabolism and bioavailability of ginsenosides. Analytical techniques for the analysis of ginsenosides that are described in this chapter are thin-layer chromatography (TLC), high-performance liquid chromatography (HPLC) combined with various detectors, gas chromatography (GC), colorimetry, enzyme immunoassays (EIA), capillary electrophoresis (CE), nuclear magnetic resonance (NMR) spectroscopy, and spectrophotometric methods.
eos
end

def test_recommend_query_failure
params = {}
get "/recommender_v1", params
assert last_response.status == 400
end

def test_recommend_query
def test_recommender_v1_deprecation
params = {
:text => @@text
:text => 'recommender v1 is deprecated'
}
get "/recommender_v1", params
assert last_response.ok?
recommendations = MultiJson.load(last_response.body)
assert_instance_of(Array, recommendations)
assert_equal(3, recommendations.length, msg='Failed to return 3 recommendations')
rec = recommendations.first
assert_instance_of(Hash, rec)
ont_acronyms = @@ontologies.map {|o| o.bring(:acronym); o.acronym }
assert ont_acronyms.include? rec['ontology']['acronym']
assert rec['annotatedClasses'].length == 0 # no classes requested
assert rec['numTermsMatched'] > 0
assert rec['numTermsTotal'] > 0
assert rec['numTermsTotal'] >= rec['numTermsMatched']
assert recommendations[0]['score'].to_i >= recommendations[1]['score'].to_i
assert recommendations[1]['score'].to_i >= recommendations[2]['score'].to_i
assert_equal 410, last_response.status
end

end
206 changes: 115 additions & 91 deletions test/controllers/test_search_controller.rb
Original file line number Diff line number Diff line change
@@ -3,11 +3,11 @@
class TestSearchController < TestCase

def before_suite
self.backend_4s_delete
LinkedData::Models::Ontology.indexClear
LinkedData::Models::Agent.indexClear
LinkedData::Models::Class.indexClear
LinkedData::Models::OntologyProperty.indexClear

count, acronyms, bro = LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
acronym: "BROSEARCHTEST",
@@ -92,10 +92,7 @@ def test_search_ontology_filter
assert last_response.ok?
results = MultiJson.load(last_response.body)
doc = results["collection"][0]

pref_label = doc["prefLabel"].kind_of?(Array) ? doc["prefLabel"].first : doc["prefLabel"]
assert_equal "cell line", pref_label

assert_equal "cell line", doc["prefLabel"]
assert doc["links"]["ontology"].include? acronym
results["collection"].each do |doc|
acr = doc["links"]["ontology"].split('/')[-1]
@@ -156,9 +153,7 @@ def test_search_other_filters
.join(' ')
.include?("Funding Resource")
end

label0 = results["collection"][0]["prefLabel"].kind_of?(Array) ? results["collection"][0]["prefLabel"].first : results["collection"][0]["prefLabel"]
assert_equal "Funding Resource", label0
assert_equal "Funding Resource", results["collection"][0]["prefLabel"]
assert_equal "T028", results["collection"][0]["semanticType"][0]
assert_equal "X123456", results["collection"][0]["cui"][0]

@@ -213,8 +208,7 @@ def test_search_provisional_class
assert_includes [10, 6], results["collection"].length # depending if owlapi import SKOS concepts
provisional = results["collection"].select {|res| assert_equal ontology_type, res["ontologyType"]; res["provisional"]}
assert_equal 1, provisional.length
prov_label = provisional[0]["prefLabel"].kind_of?(Array) ? provisional[0]["prefLabel"].first : provisional[0]["prefLabel"]
assert_equal @@test_pc_root.label, prov_label
assert_equal @@test_pc_root.label, provisional[0]["prefLabel"]

# subtree root with provisional class test
get "search?ontology=#{acronym}&subtree_root_id=#{CGI::escape(@@cls_uri.to_s)}&also_search_provisional=true"
@@ -223,9 +217,79 @@ 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"]
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
assert_equal "ActivityEnglish", doc["prefLabel"]

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"]
doc = res["collection"].select{|doc| doc["@id"].eql?('http://bioontology.org/ontologies/Activity.owl#Activity')}.first
refute_nil doc
assert_equal "Activité", doc["prefLabel"]


get "/search?q=ActivityEnglish&ontologies=BROSEARCHTEST-0&lang=en"
res = MultiJson.load(last_response.body)
refute_equal 0, res["totalCount"]
doc = res["collection"].select{|doc| doc["@id"].eql?('http://bioontology.org/ontologies/Activity.owl#Activity')}.first
refute_nil doc
assert_equal "ActivityEnglish", doc["prefLabel"]


get "/search?q=ActivityEnglish&ontologies=BROSEARCHTEST-0&lang=fr,es"
res = MultiJson.load(last_response.body)
assert_equal 0, res["totalCount"]

get "/search?q=ActivityEnglish&ontologies=BROSEARCHTEST-0&lang=en,es"
res = MultiJson.load(last_response.body)
refute_equal 0, res["totalCount"]
doc = res["collection"].select{|doc| doc["@id"].eql?('http://bioontology.org/ontologies/Activity.owl#Activity')}.first
refute_nil doc
expected_pref_label = {"none"=>["Activity"], "en"=>["ActivityEnglish"]}
assert_equal expected_pref_label, doc["prefLabel"]

get "/search?q=ActivityEnglish&ontologies=BROSEARCHTEST-0&lang=all"
res = MultiJson.load(last_response.body)
refute_equal 0, res["totalCount"]
doc = res["collection"].select{|doc| doc["@id"].eql?('http://bioontology.org/ontologies/Activity.owl#Activity')}.first
refute_nil doc
expected_pref_label = {"none"=>["Activity"], "en"=>["ActivityEnglish"], "fr"=>["Activité"]}
assert_equal expected_pref_label, doc["prefLabel"]



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


prov_label = provisional[0]["prefLabel"].kind_of?(Array) ? provisional[0]["prefLabel"].first : provisional[0]["prefLabel"]
assert_equal @@test_pc_child.label, prov_label
end

def test_search_obo_id
@@ -237,38 +301,38 @@ def test_search_obo_id

begin
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
acronym: ncit_acronym,
acronym_suffix: '',
name: "NCIT Search Test",
pref_label_property: "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#P108",
synonym_property: "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#P90",
definition_property: "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#P97",
file_path: "./test/data/ontology_files/ncit_test.owl",
ontology_format: 'OWL',
ont_count: 1,
submission_count: 1
})
process_submission: true,
acronym: ncit_acronym,
acronym_suffix: '',
name: "NCIT Search Test",
pref_label_property: "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#P108",
synonym_property: "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#P90",
definition_property: "http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#P97",
file_path: "./test/data/ontology_files/ncit_test.owl",
ontology_format: 'OWL',
ont_count: 1,
submission_count: 1
})
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
acronym: ogms_acronym,
acronym_suffix: '',
name: "OGMS Search Test",
file_path: "./test/data/ontology_files/ogms_test.owl",
ontology_format: 'OWL',
ont_count: 1,
submission_count: 1
})
process_submission: true,
acronym: ogms_acronym,
acronym_suffix: '',
name: "OGMS Search Test",
file_path: "./test/data/ontology_files/ogms_test.owl",
ontology_format: 'OWL',
ont_count: 1,
submission_count: 1
})
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
acronym: cno_acronym,
acronym_suffix: '',
name: "CNO Search Test",
file_path: "./test/data/ontology_files/CNO_05.owl",
ontology_format: 'OWL',
ont_count: 1,
submission_count: 1
})
process_submission: true,
acronym: cno_acronym,
acronym_suffix: '',
name: "CNO Search Test",
file_path: "./test/data/ontology_files/CNO_05.owl",
ontology_format: 'OWL',
ont_count: 1,
submission_count: 1
})

# 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,
@@ -375,15 +439,15 @@ def test_search_short_id

begin
LinkedData::SampleData::Ontology.create_ontologies_and_submissions({
process_submission: true,
acronym: vario_acronym,
acronym_suffix: "",
name: "VARIO OBO Search Test",
file_path: "./test/data/ontology_files/vario_test.obo",
ontology_format: 'OBO',
ont_count: 1,
submission_count: 1
})
process_submission: true,
acronym: vario_acronym,
acronym_suffix: "",
name: "VARIO OBO Search Test",
file_path: "./test/data/ontology_files/vario_test.obo",
ontology_format: 'OBO',
ont_count: 1,
submission_count: 1
})
get "/search?q=VariO:0012&ontologies=#{vario_acronym}"
assert last_response.ok?
results = MultiJson.load(last_response.body)
@@ -453,44 +517,4 @@ def test_language_attribute_filter
assert_equal 2, doc["definition"].size
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
1 change: 1 addition & 0 deletions test/helpers/test_slices_helper.rb
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ class TestSlicesHelper < TestCaseHelpers

def before_suite
self.backend_4s_delete
LinkedData::Models::Class.indexClear

@@orig_slices_setting = LinkedData.settings.enable_slices
LinkedData.settings.enable_slices = true

0 comments on commit e7c0cba

Please sign in to comment.