Skip to content

Commit

Permalink
Merge branch 'fix/search-multilingual-filter' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jun 28, 2024
2 parents 3ed10b9 + 6abcaaa commit 28624e6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
13 changes: 9 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/goo.git
revision: b2a635fb1e8206e6e3010be4dbe033b47eb58481
revision: a95245b8c964431505ca6315907440996c59a00d
branch: development
specs:
goo (0.0.2)
Expand Down Expand Up @@ -57,7 +57,7 @@ GIT

GIT
remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
revision: a5b56a68e6dc8ecfc9db708d44350342dac38ce6
revision: 4cd56da111c2037bf0b606574e6b325bfa74a2f1
branch: development
specs:
ontologies_linked_data (0.0.1)
Expand Down Expand Up @@ -164,7 +164,7 @@ GEM
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
ffi (1.17.0)
ffi (1.16.3)
gapic-common (0.21.1)
faraday (>= 1.9, < 3.a)
faraday-retry (>= 1.0, < 3.a)
Expand Down Expand Up @@ -197,6 +197,7 @@ GEM
google-cloud-env (2.1.1)
faraday (>= 1.0, < 3.a)
google-cloud-errors (1.4.0)
google-protobuf (3.25.3)
google-protobuf (3.25.3-x86_64-linux)
googleapis-common-protos (1.6.0)
google-protobuf (>= 3.18, < 5.a)
Expand All @@ -211,6 +212,9 @@ GEM
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
grpc (1.64.0)
google-protobuf (~> 3.25)
googleapis-common-protos-types (~> 1.0)
grpc (1.64.0-x86_64-linux)
google-protobuf (~> 3.25)
googleapis-common-protos-types (~> 1.0)
Expand Down Expand Up @@ -385,7 +389,7 @@ GEM
strscan (3.1.0)
systemu (2.6.5)
temple (0.10.3)
tilt (2.3.0)
tilt (2.4.0)
timeout (0.4.1)
trailblazer-option (0.1.2)
tzinfo (2.0.6)
Expand All @@ -405,6 +409,7 @@ GEM
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
Expand Down
10 changes: 7 additions & 3 deletions helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def request_multiple_languages?
end

def request_languages?
!(params['lang'] || params['languages']).blank?
!(params['lang'] || params['language']).blank?
end

def request_all_languages?
Expand All @@ -274,6 +274,10 @@ def add_lang_suffix(attr, rank = "")
end
end

def pref_label_by_language(doc)
Array(doc["prefLabel_#{request_languages.first}".to_sym]).first || Array(doc["prefLabel_none".to_sym]).first || Array(doc[:prefLabel]).first
end

def filter_attrs_by_language(doc)
lang_values = {}
doc.each do |k, v|
Expand All @@ -297,7 +301,7 @@ def filter_attrs_by_language(doc)
doc[k] = lang_vals.map { |l, v| l.eql?('none') ? nil : v }.compact.flatten + Array(lang_vals['none'])
end

doc[:prefLabel] = Array(doc["prefLabel_#{request_languages.first}".to_sym]).first || Array(doc[:prefLabel]).first
doc[:prefLabel] = pref_label_by_language(doc)
end

doc
Expand Down Expand Up @@ -431,7 +435,7 @@ def populate_classes_from_search(classes, ontology_acronyms=nil)
doc[:submission] = old_class.submission
doc[:properties] = MultiJson.load(doc.delete(:propertyRaw)) if include_param_contains?(:properties)
instance = LinkedData::Models::Class.read_only(doc)
instance.prefLabel = instance.prefLabel.first if instance.prefLabel.is_a?(Array)
instance.prefLabel = pref_label_by_language(doc)
classes_hash[ont_uri_class_uri] = instance
end

Expand Down
8 changes: 4 additions & 4 deletions test/controllers/test_annotator_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,16 +265,16 @@ def test_default_properties_output
assert last_response.ok?
annotations = MultiJson.load(last_response.body)
assert_equal 9, annotations.length
annotations.sort! { |a,b| a["annotatedClass"]["prefLabel"].first.downcase <=> b["annotatedClass"]["prefLabel"].first.downcase }
annotations.sort! { |a,b| a["annotatedClass"]["prefLabel"].downcase <=> b["annotatedClass"]["prefLabel"].downcase }
assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Aggregate_Human_Data", annotations.first["annotatedClass"]["@id"]
assert_equal "Aggregate Human Data", Array(annotations.first["annotatedClass"]["prefLabel"]).first
assert_equal "Aggregate Human Data", annotations.first["annotatedClass"]["prefLabel"]

params = {text: text, include: "prefLabel,definition"}
get "/annotator", params
assert last_response.ok?
annotations = MultiJson.load(last_response.body)
assert_equal 9, annotations.length
annotations.sort! { |a,b| Array(a["annotatedClass"]["prefLabel"]).first.downcase <=> Array(b["annotatedClass"]["prefLabel"]).first.downcase }
annotations.sort! { |a,b| a["annotatedClass"]["prefLabel"].downcase <=> b["annotatedClass"]["prefLabel"].downcase }
assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Aggregate_Human_Data", annotations.first["annotatedClass"]["@id"]
assert_equal ["A resource that provides data from clinical care that comprises combined data from multiple individual human subjects."], annotations.first["annotatedClass"]["definition"]
end
Expand Down Expand Up @@ -354,7 +354,7 @@ def self.mapping_test_set
class_id = terms_a[i]
ont_acr = onts_a[i]
sub = LinkedData::Models::Ontology.find(ont_acr).first.latest_submission(status: :any)
binding.pry if sub.nil?

sub.bring(ontology: [:acronym])
c = LinkedData::Models::Class.find(RDF::URI.new(class_id))
.in(sub)
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/test_search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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"].first
assert_equal "cell line", doc["prefLabel"]
assert doc["links"]["ontology"].include? acronym
results["collection"].each do |doc|
acr = doc["links"]["ontology"].split('/')[-1]
Expand Down

0 comments on commit 28624e6

Please sign in to comment.