Skip to content

Commit

Permalink
Merge pull request #149 from ontoportal-lirmm/pr/sync-agroportal-biop…
Browse files Browse the repository at this point in the history
…ortal

Feature: make the api use submission naturalLanguage  to choose the default language to display
  • Loading branch information
alexskr authored May 21, 2024
2 parents 3dc9f9d + 9892e98 commit d9398ce
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 32 deletions.
14 changes: 8 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ gem 'unicorn-worker-killer'
gem 'haml', '~> 5.2.2' # pin see https://github.com/ncbo/ontologies_api/pull/107
gem 'redcarpet'

# NCBO

# NCBO gems (can be from a local dev path or from rubygems/git)
gem 'ncbo_annotator', git: 'https://github.com/ncbo/ncbo_annotator.git', branch: 'master'
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: 'ncbo/goo', branch: 'develop'
gem 'ncbo_annotator', github: 'ncbo/ncbo_annotator', branch: 'develop'
gem 'ncbo_cron', github: 'ncbo/ncbo_cron', branch: 'develop'
gem 'ncbo_ontology_recommender', github: 'ncbo/ncbo_ontology_recommender', branch: 'develop'
gem 'ontologies_linked_data', github: 'ncbo/ontologies_linked_data', branch: 'feature/multilingual-support-add-search-and-languages-serialization'
gem 'sparql-client', github: 'ncbo/sparql-client', branch: 'develop'
gem 'ontologies_linked_data', github: 'ontoportal-lirmm/ontologies_linked_data', branch: 'pr/sync-agroportal-ncbo'


group :development do
# bcrypt_pbkdf and ed35519 is required for capistrano deployments when using ed25519 keys; see https://github.com/miloserdow/capistrano-deploy/issues/42
Expand Down
54 changes: 29 additions & 25 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/ncbo/goo.git
revision: a55ef42e92bc02129992c77890278831f8ca5387
revision: 70007faf43d0d96292809f89f15a27a757ccaa25
branch: develop
specs:
goo (0.0.2)
Expand All @@ -16,8 +16,8 @@ GIT

GIT
remote: https://github.com/ncbo/ncbo_annotator.git
revision: 7531e10ad55ac66e925c099d7fc05a5a3ceae67e
branch: develop
revision: 63c986880aa88c9384043e6611a682434a14aba7
branch: master
specs:
ncbo_annotator (0.0.1)
goo
Expand All @@ -27,8 +27,8 @@ GIT

GIT
remote: https://github.com/ncbo/ncbo_cron.git
revision: 98dc1a9bb8aba4ef41a1687251ca1245edd5de57
branch: develop
revision: 67810ddd2e14876d789c63c427b08af6919f661e
branch: master
specs:
ncbo_cron (0.0.1)
dante
Expand All @@ -45,8 +45,8 @@ GIT

GIT
remote: https://github.com/ncbo/ncbo_ontology_recommender.git
revision: f92a42f660635522eb8709e618ff2e641aef0d17
branch: develop
revision: 013abea4af3b10910ec661dbb358a4b6cae198a4
branch: master
specs:
ncbo_ontology_recommender (0.0.1)
goo
Expand All @@ -55,9 +55,19 @@ GIT
redis

GIT
remote: https://github.com/ncbo/ontologies_linked_data.git
revision: 0227d37c6431f52a7fd85bdb597cc3d32e975098
branch: feature/multilingual-support-add-search-and-languages-serialization
remote: https://github.com/ncbo/sparql-client.git
revision: e89c26aa96f184dbe9b52d51e04fb3d9ba998dbc
branch: master
specs:
sparql-client (1.0.1)
json_pure (>= 1.4)
net-http-persistent (= 2.9.4)
rdf (>= 1.0)

GIT
remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git
revision: 67f9e10c03880431590b15ea5b27d2f1fe1354c4
branch: pr/sync-agroportal-ncbo
specs:
ontologies_linked_data (0.0.1)
activesupport
Expand All @@ -74,16 +84,6 @@ GIT
rsolr
rubyzip

GIT
remote: https://github.com/ncbo/sparql-client.git
revision: 1657f0dd69fd4b522d3549a6848670175f5e98cc
branch: develop
specs:
sparql-client (1.0.1)
json_pure (>= 1.4)
net-http-persistent (= 2.9.4)
rdf (>= 1.0)

GIT
remote: https://github.com/palexander/rack-post-body-to-params.git
revision: 0fd30e710386d0cb8a3a6833d9549d7b655d5398
Expand Down Expand Up @@ -114,7 +114,9 @@ GEM
backports (3.25.0)
base64 (0.2.0)
bcrypt (3.1.20)
bcrypt_pbkdf (1.1.0)
bcrypt_pbkdf (1.1.1)
bcrypt_pbkdf (1.1.1-arm64-darwin)
bcrypt_pbkdf (1.1.1-x86_64-darwin)
bigdecimal (1.4.2)
builder (3.2.4)
capistrano (3.18.1)
Expand Down Expand Up @@ -271,7 +273,7 @@ GEM
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.5)
racc (1.7.3)
racc (1.8.0)
rack (1.6.13)
rack-accept (0.4.5)
rack (>= 0.4)
Expand All @@ -287,7 +289,7 @@ GEM
rack
rack-test (2.1.0)
rack (>= 1.3)
rack-timeout (0.6.3)
rack-timeout (0.7.0)
rainbow (3.1.1)
raindrops (0.20.1)
rake (10.5.0)
Expand All @@ -303,15 +305,16 @@ 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)
Expand Down Expand Up @@ -367,6 +370,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
23 changes: 23 additions & 0 deletions test/controllers/test_classes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -531,4 +531,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 d9398ce

Please sign in to comment.