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 preflabels #221

Merged
merged 3 commits into from
Oct 21, 2024
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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ group :development do
gem 'rubocop', require: false
end
# NCBO gems (can be from a local dev path or from rubygems/git)
gem 'goo', github: 'ncbo/goo', branch: 'develop'
gem 'goo', github: 'ncbo/goo', branch: 'multilingual_preflabels'
gem 'sparql-client', github: 'ncbo/sparql-client', branch: 'develop'
27 changes: 10 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GIT
remote: https://github.com/ncbo/goo.git
revision: d4da86d07a449e91dbbd6b72763f42d3ba3f20f3
branch: develop
revision: d6b84e12d61317dbddc1b86cb1451acb37915369
branch: multilingual_preflabels
specs:
goo (0.0.2)
addressable (~> 2.8)
Expand Down Expand Up @@ -37,6 +37,7 @@ GEM
public_suffix (>= 2.0.2, < 7.0)
ansi (1.5.0)
ast (2.4.2)
base64 (0.2.0)
bcrypt (3.1.20)
bigdecimal (3.1.8)
builder (3.3.0)
Expand All @@ -55,15 +56,12 @@ GEM
launchy (>= 2.1, < 4.0)
mail (~> 2.7)
eventmachine (1.2.7)
faraday (2.12.0)
faraday-net_http (>= 2.0, < 3.4)
json
logger
faraday-net_http (3.3.0)
net-http
ffi (1.17.0-aarch64-linux-gnu)
faraday (2.8.1)
base64
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
ffi (1.17.0-arm64-darwin)
ffi (1.17.0-x86_64-linux-gnu)
hashie (5.0.0)
htmlentities (4.3.4)
http-accept (1.7.0)
Expand Down Expand Up @@ -99,8 +97,6 @@ GEM
minitest (>= 2.12, < 5.0)
powerbar
multi_json (1.15.0)
net-http (0.4.1)
uri
net-http-persistent (2.9.4)
net-imap (0.4.17)
date
Expand Down Expand Up @@ -129,7 +125,7 @@ GEM
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (6.0.1)
public_suffix (5.1.1)
racc (1.8.1)
rack (2.2.10)
rack-test (0.8.3)
Expand Down Expand Up @@ -167,6 +163,7 @@ GEM
rubocop-ast (1.32.3)
parser (>= 3.3.1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (1.3.0)
simplecov (0.22.0)
docile (~> 1.1)
Expand All @@ -186,15 +183,11 @@ GEM
timeout (0.4.1)
tzinfo (0.3.62)
unicode-display_width (2.6.0)
uri (0.13.1)
uuid (2.3.9)
macaddr (~> 1.0)

PLATFORMS
aarch64-linux
arm64-darwin-22
arm64-darwin-23
x86_64-linux

DEPENDENCIES
activesupport (~> 4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,24 @@

def generate_missing_labels_each(artifacts = {}, logger, paging, page_classes, page, c)
prefLabel = nil
portal_lang = Goo.portal_language
prefLabel_lang = c.prefLabel(include_languages: true)
no_default_prefLabel = prefLabel_lang.nil? || (prefLabel_lang.keys & [portal_lang, :none]).empty?

if c.prefLabel.nil?
if prefLabel_lang.nil? || no_default_prefLabel
lang_rdfs_labels = c.label(include_languages: true)
lang_rdfs_labels = {none: []} if lang_rdfs_labels.empty?
lang_rdfs_labels = {none: []} if lang_rdfs_labels.to_a.empty? ||
(no_default_prefLabel && (lang_rdfs_labels.keys & [portal_lang, :none]).empty?)

lang_rdfs_labels&.each do |lang, rdfs_labels|
lang_rdfs_labels.each do |lang, rdfs_labels|
if rdfs_labels && rdfs_labels.length > 1 && c.synonym.length > 0
rdfs_labels = (Set.new(c.label) - Set.new(c.synonym)).to_a.first

rdfs_labels = c.label if rdfs_labels.nil? || rdfs_labels.length == 0
end

rdfs_labels = [rdfs_labels] if rdfs_labels and not (rdfs_labels.instance_of? Array)
label = nil

label = nil
if rdfs_labels && rdfs_labels.length > 0
# this sort is needed for a predictable label selection
label = rdfs_labels.sort[0]
Expand All @@ -215,13 +218,15 @@
lang = nil
prefLabel = label
end
prefLabel = label if !prefLabel && lang === Goo.portal_language
prefLabel = label if !prefLabel && lang === portal_lang
prefLabel = label unless prefLabel
artifacts[:label_triples] << LinkedData::Utils::Triples.label_for_class_triple(
c.id, Goo.vocabulary(:metadata_def)[:prefLabel], label, lang)
c.id, Goo.vocabulary(:metadata_def)[:prefLabel], prefLabel, lang)
end
else
elsif prefLabel_lang
prefLabel = c.prefLabel
else
prefLabel = LinkedData::Utils::Triples.last_iri_fragment c.id.to_s

Check warning on line 229 in lib/ontologies_linked_data/services/submission_process/operations/submission_rdf_generator.rb

View check run for this annotation

Codecov / codecov/patch

lib/ontologies_linked_data/services/submission_process/operations/submission_rdf_generator.rb#L229

Added line #L229 was not covered by tests
end

if @submission.ontology.viewOf.nil?
Expand Down
5 changes: 3 additions & 2 deletions test/data/ontology_files/BRO_v3.2.owl
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,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>
<rdfs:label xml:lang="fr">Gestion des échantillons biologiques</rdfs:label>
<core:prefLabel xml:lang="fr">Biospecimen Management</core:prefLabel>
</owl:Class>

Expand All @@ -652,7 +653,7 @@
<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>
<core:prefLabel xml:lang="fr">Engagement communautaire</core:prefLabel>
</owl:Class>


Expand All @@ -672,7 +673,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>
<rdfs:label xml:lang="fr">Thérapie génique</rdfs:label>
</owl:Class>


Expand Down
2 changes: 0 additions & 2 deletions test/models/test_ontology_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ def test_generate_language_preflabels
submission_parse("D3OTEST", "DSMZ Digital Diversity Ontology Test",
"./test/data/ontology_files/d3o.owl", 1,
process_rdf: true, index_search: true, extract_metadata: false)

res = LinkedData::Models::Class.search("prefLabel_en:Anatomic Structure", {:fq => "submissionAcronym:D3OTEST", :start => 0, :rows => 100})
refute_equal 0, res["response"]["numFound"]
refute_nil res["response"]["docs"].select{|doc| doc["resource_id"].eql?('https://purl.dsmz.de/schema/AnatomicStructure')}.first
Expand Down Expand Up @@ -1190,7 +1189,6 @@ def test_submission_extract_metadata
end
end


def test_submission_delete_remove_files
#This one has resources wih accents.
submission_parse("ONTOMATEST",
Expand Down