Skip to content

Commit

Permalink
fix annotator prefLabel language selection
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jun 27, 2024
1 parent 923629e commit 6abcaaa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6abcaaa

Please sign in to comment.