Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: multilingual generated missing labels issue #101

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 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: 6018b33373467b778744432ec78a6d814159d129
revision: f8ac7b00e8d8b46d1eea04de014175525c1cdd83
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: 0a456557bc0ae2a7d016000de9b57d3f9eca99a5
revision: 793c4fde592e6db91d8d103c15afe993c3472aae
branch: development
specs:
ontologies_linked_data (0.0.1)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
71 changes: 53 additions & 18 deletions 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 @@ -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

Expand All @@ -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"]
Expand Down Expand Up @@ -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"
Expand 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"
Expand All @@ -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" ]

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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',
Expand All @@ -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" ]
Expand All @@ -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'] =[
Expand Down Expand Up @@ -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" ]

Expand Down Expand Up @@ -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"]
Expand All @@ -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
6 changes: 2 additions & 4 deletions 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 All @@ -655,7 +655,6 @@
<owl:Class rdf:about="&activity;Community_Engagement">
<rdfs:subClassOf rdf:resource="&activity;Activity"/>
<desc:definition rdf:datatype="&xsd;string">As defined in http://en.wikipedia.org/wiki/Community_engagement</desc:definition>
<core:prefLabel rdf:datatype="&xsd;string">Community Engagement</core:prefLabel>
</owl:Class>


Expand All @@ -675,7 +674,7 @@
<owl:Class rdf:about="&activity;Gene_Therapy">
<rdfs:subClassOf rdf:resource="&activity;Therapeutics"/>
<desc:definition rdf:datatype="&xsd;string">As defined in http://en.wikipedia.org/wiki/Gene_therapy</desc:definition>
<core:prefLabel rdf:datatype="&xsd;string">Gene Therapy</core:prefLabel>
<core:prefLabel xml:lang="fr">Gene Therapy</core:prefLabel>
</owl:Class>


Expand Down Expand Up @@ -6328,4 +6327,3 @@ radionuclide (tracer), which is introduced into the body on a biologically activ


<!-- Generated by the OWL API (version 3.4.2) http://owlapi.sourceforge.net -->

Loading