Skip to content

Commit

Permalink
make the api use submission naturalLanguage to choose the default lan…
Browse files Browse the repository at this point in the history
…guage to display
  • Loading branch information
syphax-bouazzouni committed May 20, 2024
1 parent 2a675bb commit 9ca2500
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ gem 'ncbo_annotator', git: 'https://github.com/ncbo/ncbo_annotator.git', branch:
gem 'ncbo_cron', git: 'https://github.com/ncbo/ncbo_cron.git', branch: 'master'
gem 'ncbo_ontology_recommender', git: 'https://github.com/ncbo/ncbo_ontology_recommender.git', branch: 'master'
gem 'sparql-client', github: 'ncbo/sparql-client', branch: 'master'
gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'pr/sync-agroportal-bioportal'
gem 'goo', github: 'ncbo/goo', branch: 'develop'
gem 'ontologies_linked_data', github: 'ontoportal-lirmm/ontologies_linked_data', branch: 'pr/sync-agroportal-ncbo'

group :development do
Expand Down
52 changes: 29 additions & 23 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
GIT
remote: https://github.com/ncbo/goo.git
revision: 70007faf43d0d96292809f89f15a27a757ccaa25
branch: develop
specs:
goo (0.0.2)
addressable (~> 2.8)
pry
rdf (= 1.0.8)
redis
request_store
rest-client
rsolr
sparql-client
uuid

GIT
remote: https://github.com/ncbo/ncbo_annotator.git
revision: 63c986880aa88c9384043e6611a682434a14aba7
Expand All @@ -11,11 +27,13 @@ GIT

GIT
remote: https://github.com/ncbo/ncbo_cron.git
revision: f239b34230131cd7cfb9eec5b34068ba990b698b
revision: 67810ddd2e14876d789c63c427b08af6919f661e
branch: master
specs:
ncbo_cron (0.0.1)
dante
faraday (~> 2)
faraday-follow_redirects (~> 0)
goo
google-analytics-data
mlanett-redis-lock
Expand Down Expand Up @@ -46,25 +64,9 @@ GIT
net-http-persistent (= 2.9.4)
rdf (>= 1.0)

GIT
remote: https://github.com/ontoportal-lirmm/goo.git
revision: f2751fe9324e48a0a5c2a8b15580ab879fc53a2b
branch: pr/sync-agroportal-bioportal
specs:
goo (0.0.2)
addressable (~> 2.8)
pry
rdf (= 1.0.8)
redis
request_store
rest-client
rsolr
sparql-client
uuid

GIT
remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
revision: fc48343ad7a3f1867821c173be900cf16506b4b7
revision: 7c5184fc7d3b25b5c9dd54c25f5ea2b1c4951318
branch: pr/sync-agroportal-ncbo
specs:
ontologies_linked_data (0.0.1)
Expand Down Expand Up @@ -143,6 +145,8 @@ GEM
base64
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-follow_redirects (0.3.0)
faraday (>= 1, < 3)
faraday-net_http (3.0.2)
faraday-retry (2.2.1)
faraday (~> 2.0)
Expand Down Expand Up @@ -223,7 +227,7 @@ GEM
method_source (1.1.0)
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2024.0305)
mime-types-data (3.2024.0507)
mini_mime (1.1.5)
minitest (4.7.5)
minitest-stub_any_instance (1.0.3)
Expand All @@ -232,7 +236,7 @@ GEM
multi_json (1.15.0)
mutex_m (0.2.0)
net-http-persistent (2.9.4)
net-imap (0.4.10)
net-imap (0.4.11)
date
net-protocol
net-pop (0.1.2)
Expand Down Expand Up @@ -295,19 +299,20 @@ GEM
redis-store (>= 1.6, < 2)
redis-store (1.10.0)
redis (>= 4, < 6)
regexp_parser (2.9.0)
regexp_parser (2.9.2)
request_store (1.7.0)
rack (>= 1.4)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.2.6)
rexml (3.2.8)
strscan (>= 3.0.9)
rsolr (2.6.0)
builder (>= 2.1.2)
faraday (>= 0.9, < 3, != 2.0.0)
rubocop (1.63.4)
rubocop (1.63.5)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand Down Expand Up @@ -359,6 +364,7 @@ GEM
net-scp (>= 1.1.2)
net-sftp (>= 2.1.2)
net-ssh (>= 2.8.0)
strscan (3.1.0)
systemu (2.6.5)
temple (0.10.3)
tilt (2.3.0)
Expand Down
19 changes: 19 additions & 0 deletions helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ def get_ontology_and_submission
error 404, "Ontology #{@params["acronym"]} does not have any submissions"
end
end

save_submission_language(submission)

return ont, submission
end

Expand Down Expand Up @@ -438,6 +441,22 @@ def naive_expiring_cache_read(key)
return object[:object]
end


def save_submission_language(submission, language_property = :naturalLanguage)
request_lang = RequestStore.store[:requested_lang]

return if submission.nil? || !request_lang.blank?

submission.bring(language_property) if submission.bring?(language_property)
collection_natural_language = submission.send(language_property) rescue nil
return [] if collection_natural_language.blank?

collection_natural_language = collection_natural_language.values.flatten if collection_natural_language.is_a?(Hash)
submissions_language = collection_natural_language.map { |natural_language| natural_language.to_s.split('/').last[0..1] }.compact.first

RequestStore.store[:requested_lang] = submissions_language if submissions_language
end

end
end
end
Expand Down
26 changes: 25 additions & 1 deletion test/controllers/test_classes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def self.before_suite
submissions_to_process: [1, 2],
process_submission: true,
random_submission_count: false,
process_options: {process_rdf: true, extract_metadata: false}
process_options: {process_rdf: true, extract_metadata: false},
file_path: "./test/data/ontology_files/BRO_v3.2.owl",
}
return LinkedData::SampleData::Ontology.create_ontologies_and_submissions(options)
end
Expand Down Expand Up @@ -531,4 +532,27 @@ def test_class_page_with_metric_count
assert page_response["collection"].length == 0
end

def test_default_multilingual
ont = Ontology.find("TEST-ONT-0").include(:acronym).first
sub = ont.latest_submission
sub.bring_remaining

get "/ontologies/#{ont.acronym}/classes/#{CGI.escape('http://bioontology.org/ontologies/Activity.owl#Biospecimen_Management')}"
assert last_response.ok?
page_response = MultiJson.load(last_response.body)

# does not contain a value in english show the generated one
assert_equal 'Biospecimen_Management', page_response["prefLabel"]


sub.naturalLanguage = ['fr']
sub.save

get "/ontologies/#{ont.acronym}/classes/#{CGI.escape('http://bioontology.org/ontologies/Activity.owl#Biospecimen_Management')}"
assert last_response.ok?
page_response = MultiJson.load(last_response.body)

# show french value as specified in submission naturalLanguage
assert_equal 'Biospecimen Management', page_response["prefLabel"]
end
end
2 changes: 1 addition & 1 deletion test/data/ontology_files/BRO_v3.2.owl
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@
<owl:Class rdf:about="&activity;Biospecimen_Management">
<rdfs:subClassOf rdf:resource="&activity;Activity"/>
<desc:definition rdf:datatype="&xsd;string">Activity related to the creation, use, or maintenance of a biorepository (http://en.wikipedia.org/wiki/Biorepository)</desc:definition>
<core:prefLabel rdf:datatype="&xsd;string">Biospecimen Management</core:prefLabel>
<core:prefLabel xml:lang="fr">Biospecimen Management</core:prefLabel>
</owl:Class>


Expand Down

0 comments on commit 9ca2500

Please sign in to comment.