diff --git a/Gemfile.lock b/Gemfile.lock index 2470fac9..98c8ada6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,7 +11,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/goo.git - revision: 6018b33373467b778744432ec78a6d814159d129 + revision: f8ac7b00e8d8b46d1eea04de014175525c1cdd83 branch: development specs: goo (0.0.2) @@ -57,7 +57,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git - revision: 0a456557bc0ae2a7d016000de9b57d3f9eca99a5 + revision: 793c4fde592e6db91d8d103c15afe993c3472aae branch: development specs: ontologies_linked_data (0.0.1) @@ -204,7 +204,7 @@ GEM grpc (~> 1.41) googleapis-common-protos-types (1.16.0) google-protobuf (>= 3.18, < 5.a) - googleauth (1.11.1) + googleauth (1.11.2) faraday (>= 1.0, < 3.a) google-cloud-env (~> 2.1) jwt (>= 1.4, < 3.0) @@ -225,7 +225,7 @@ GEM httpclient (2.8.3) i18n (0.9.5) concurrent-ruby (~> 1.0) - json (2.7.2) + json (2.7.3) json-ld (3.0.2) multi_json (~> 1.12) rdf (>= 2.2.8, < 4.0) @@ -343,7 +343,7 @@ GEM mime-types (>= 1.16, < 4.0) netrc (~> 0.8) retriable (3.1.2) - rexml (3.3.8) + rexml (3.3.9) rsolr (2.6.0) builder (>= 2.1.2) faraday (>= 0.9, < 3, != 2.0.0) diff --git a/helpers/application_helper.rb b/helpers/application_helper.rb index 24893eef..f03c3c36 100644 --- a/helpers/application_helper.rb +++ b/helpers/application_helper.rb @@ -408,6 +408,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 @@ -454,6 +457,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 diff --git a/test/controllers/test_classes_controller.rb b/test/controllers/test_classes_controller.rb index fc5adb96..4056f006 100644 --- a/test/controllers/test_classes_controller.rb +++ b/test/controllers/test_classes_controller.rb @@ -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 @@ -82,7 +83,6 @@ def test_notation_lookup assert response["@id"] == "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Ontology_Development_and_Management" end - def test_all_class_pages ont = Ontology.find("TEST-ONT-0").include(:acronym).first @@ -99,7 +99,7 @@ def test_all_class_pages assert last_response.ok? page_response = MultiJson.load(last_response.body) page_response["collection"].each do |item| - assert_instance_of String, item["prefLabel"] + assert_instance_of String, item["prefLabel"], item["@id"] assert_instance_of String, item["@id"] assert_instance_of Hash, item["@context"] assert_instance_of Hash, item["links"] @@ -131,6 +131,7 @@ def test_single_cls_all ont = Ontology.find("TEST-ONT-0").include(:acronym).first clss_ids = [ 'http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Molecular_Interaction', "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Electron_Microscope" ] + clss_ids.each do |cls_id| escaped_cls= CGI.escape(cls_id) call = "/ontologies/#{ont.acronym}/classes/#{escaped_cls}?include=all" @@ -149,6 +150,7 @@ def test_single_cls_properties ont = Ontology.find("TEST-ONT-0").include(:acronym).first clss_ids = [ 'http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Molecular_Interaction', "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Electron_Microscope" ] + clss_ids.each do |cls_id| escaped_cls= CGI.escape(cls_id) call = "/ontologies/#{ont.acronym}/classes/#{escaped_cls}?include=properties" @@ -163,7 +165,6 @@ def test_single_cls_properties def test_single_cls ont = Ontology.find("TEST-ONT-0").include(:acronym).first - clss_ids = [ 'http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Molecular_Interaction', "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Electron_Microscope" ] @@ -182,13 +183,8 @@ def test_single_cls assert_instance_of(Array, cls["synonym"]) assert(cls["@id"] == cls_id) - if submission_id.nil? || submission_id == 2 - assert(cls["prefLabel"]["In version 3.2"]) - assert(cls["definition"][0]["In version 3.2"]) - else - assert(!cls["prefLabel"]["In version 3.2"]) - assert(!cls["definition"][0]["In version 3.2"]) - end + assert(cls["prefLabel"]["In version 3.2"]) + assert(cls["definition"][0]["In version 3.2"]) if cls["prefLabel"].include? "Electron" assert_equal(1, cls["synonym"].length) @@ -208,7 +204,7 @@ def test_roots_for_cls roots = MultiJson.load(last_response.body) assert_includes [9, 6, 5], roots.length roots.each do |r| - assert_instance_of String, r["prefLabel"] + assert_instance_of String, r["prefLabel"], r["@id"] assert_instance_of String, r["@id"] assert r.include?"hasChildren" #By definition roots have no parents @@ -221,7 +217,6 @@ def test_roots_for_cls end def test_classes_for_not_parsed_ontology - ont = Ontology.find("TEST-ONT-0").include(:acronym).first #first submission was not parsed @@ -232,7 +227,6 @@ def test_classes_for_not_parsed_ontology end def test_tree - ont = Ontology.find("TEST-ONT-0").include(:acronym).first clss_ids = [ 'http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Molecular_Interaction', @@ -251,7 +245,6 @@ def test_tree end def test_path_to_root_for_cls - ont = Ontology.find("TEST-ONT-0").include(:acronym).first clss_ids = [ 'http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Molecular_Interaction', "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Electron_Microscope" ] @@ -264,7 +257,6 @@ def test_path_to_root_for_cls end def test_ancestors_for_cls - ont = Ontology.find("TEST-ONT-0").include(:acronym).first ancestors_data = {} ancestors_data['http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Molecular_Interaction'] =[ @@ -456,7 +448,6 @@ def test_calls_not_found end def test_children_for_cls_round_trip - clss_ids = [ 'http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Molecular_and_Cellular_Data', "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Microscope" ] @@ -513,7 +504,7 @@ def test_class_page_with_metric_count assert last_response.ok? page_response = MultiJson.load(last_response.body) page_response["collection"].each do |item| - assert_instance_of String, item["prefLabel"] + assert_instance_of String, item["prefLabel"], item["@id"] assert_instance_of String, item["@id"] assert_instance_of Hash, item["@context"] assert_instance_of Hash, item["links"] @@ -533,4 +524,48 @@ 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 + + # rdfs:label is NOT present and the prefLabel is NOT defined for the ontology or portal language + sub.naturalLanguage = [RDF::URI.new('http://lexvo.org/id/iso639-3/es')] + sub.save + + get "/ontologies/#{ont.acronym}/classes/#{CGI.escape('http://bioontology.org/ontologies/Activity.owl#Community_Engagement')}" + assert last_response.ok? + page_response = MultiJson.load(last_response.body) + # does not contain a value in english show the generated one + assert_equal 'Community_Engagement', page_response["prefLabel"] + + # rdfs:label is present but NOT for either the ontology or portal language + 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"] + + # prefLabel NOT present, rdfs:label is present but NOT for either the ontology or portal language + get "/ontologies/#{ont.acronym}/classes/#{CGI.escape('http://bioontology.org/ontologies/Activity.owl#Gene_Therapy')}" + assert last_response.ok? + page_response = MultiJson.load(last_response.body) + # does not contain a value in english show the generated one + assert_equal 'Gene_Therapy', page_response["prefLabel"] + + # prefLabel is present in the ontology language + sub.naturalLanguage = [RDF::URI.new('http://lexvo.org/id/iso639-3/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"] + + sub.naturalLanguage = [] + sub.save + end + end diff --git a/test/data/ontology_files/BRO_v3.2.owl b/test/data/ontology_files/BRO_v3.2.owl index b2aeccf5..c55d2f38 100644 --- a/test/data/ontology_files/BRO_v3.2.owl +++ b/test/data/ontology_files/BRO_v3.2.owl @@ -645,7 +645,7 @@ Activity related to the creation, use, or maintenance of a biorepository (http://en.wikipedia.org/wiki/Biorepository) - Biospecimen Management + Biospecimen Management @@ -655,7 +655,6 @@ As defined in http://en.wikipedia.org/wiki/Community_engagement - Community Engagement @@ -675,7 +674,7 @@ As defined in http://en.wikipedia.org/wiki/Gene_therapy - Gene Therapy + Gene Therapy @@ -6328,4 +6327,3 @@ radionuclide (tracer), which is introduced into the body on a biologically activ -