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

Feature: Support multilingual - Add read one language from request parameter tests #71

1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ gem 'rest-client'
gem 'rsolr', '~> 1.0'
gem 'rubyzip', '~> 1.0'
gem 'thin'
gem 'request_store'

# Testing
group :test do
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/ontoportal-lirmm/goo.git
revision: 3d5bbe1db4a6aca2ff621ccfcdb85a32dbe9704e
revision: b769c165906163e30a026dba511ae1069c4eed3d
branch: development
specs:
goo (0.0.2)
Expand Down Expand Up @@ -39,11 +39,11 @@ GEM
bcrypt (3.1.18)
builder (3.2.4)
coderay (1.1.3)
concurrent-ruby (1.1.10)
concurrent-ruby (1.2.2)
connection_pool (2.3.0)
cube-ruby (0.0.3)
daemons (1.4.1)
date (3.3.2)
date (3.3.3)
docile (1.4.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
Expand All @@ -52,7 +52,7 @@ GEM
launchy (~> 2.1)
mail (~> 2.7)
eventmachine (1.2.7)
faraday (1.10.2)
faraday (1.10.3)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
Expand Down Expand Up @@ -85,21 +85,21 @@ GEM
concurrent-ruby (~> 1.0)
json (2.6.3)
json_pure (2.6.3)
launchy (2.5.0)
addressable (~> 2.7)
launchy (2.5.2)
addressable (~> 2.8)
libxml-ruby (2.9.0)
logger (1.5.3)
macaddr (1.7.2)
systemu (~> 2.6.5)
mail (2.8.0)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
method_source (1.0.0)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2022.0105)
mime-types-data (3.2023.0218.1)
mini_mime (1.1.2)
minitest (4.7.5)
minitest-reporters (0.14.24)
Expand All @@ -108,9 +108,9 @@ GEM
minitest (>= 2.12, < 5.0)
powerbar
multi_json (1.15.0)
multipart-post (2.2.3)
multipart-post (2.3.0)
net-http-persistent (2.9.4)
net-imap (0.3.2)
net-imap (0.3.4)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -124,13 +124,13 @@ GEM
omni_logger (0.1.4)
logger
parallel (1.22.1)
parser (3.1.3.0)
parser (3.2.1.0)
ast (~> 2.4.1)
pony (1.13.1)
mail (>= 2.0)
powerbar (2.0.1)
hashie (>= 1.1.0)
pry (0.14.1)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (5.0.1)
Expand All @@ -141,11 +141,13 @@ GEM
rake (10.5.0)
rdf (1.0.8)
addressable (>= 2.2)
redis (5.0.5)
redis (5.0.6)
redis-client (>= 0.9.0)
redis-client (0.11.2)
redis-client (0.13.0)
connection_pool
regexp_parser (2.6.1)
regexp_parser (2.7.0)
request_store (1.5.1)
rack (>= 1.4)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
Expand All @@ -154,22 +156,22 @@ GEM
rexml (3.2.5)
rsolr (1.1.2)
builder (>= 2.1.2)
rubocop (1.40.0)
rubocop (1.48.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.2.1)
parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.23.0, < 2.0)
rubocop-ast (>= 1.26.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.24.0)
parser (>= 3.1.1.0)
ruby-progressbar (1.11.0)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.27.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (1.3.0)
simplecov (0.21.2)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
Expand All @@ -186,17 +188,18 @@ GEM
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
thread_safe (0.3.6)
timeout (0.3.1)
timeout (0.3.2)
tzinfo (0.3.61)
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
unicode-display_width (2.3.0)
unicode-display_width (2.4.2)
uuid (2.3.9)
macaddr (~> 1.0)

PLATFORMS
x86_64-darwin-21
x86_64-linux

DEPENDENCIES
activesupport (~> 4)
Expand All @@ -218,6 +221,7 @@ DEPENDENCIES
rack (~> 1.0)
rack-test (~> 0.6)
rake (~> 10.0)
request_store
rest-client
rsolr (~> 1.0)
rubocop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def create_mapping_process(mapping_process_hash, source_uri, object_uri, user)
process.relation = relations_array
process.creator = user

process.subject_source_id = RDF::URI.new(source_uri || mapping_process_hash[:subject_source_id])
process.object_source_id = RDF::URI.new(object_uri || mapping_process_hash[:object_source_id])
process.subject_source_id = create_uri(source_uri || mapping_process_hash[:subject_source_id])
process.object_source_id = create_uri(object_uri || mapping_process_hash[:object_source_id])
process.date = mapping_process_hash[:date] ? DateTime.parse(mapping_process_hash[:date]) : DateTime.now
process_fields = %i[source source_name comment name source_contact_info]
process_fields.each do |att|
Expand All @@ -92,6 +92,9 @@ def create_mapping_process(mapping_process_hash, source_uri, object_uri, user)
end

private
def create_uri(value)
RDF::URI.new(value) unless value.nil?
end

def save_rest_mapping(classes, process)
LinkedData::Mappings.create_rest_mapping(classes, process)
Expand Down
6 changes: 5 additions & 1 deletion lib/ontologies_linked_data/models/users/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ def custom_ontology_id_set
end

def to_s
self.username.to_s
if bring?(:username)
self.id.to_s
else
self.username.to_s
end
end

private
Expand Down
6 changes: 3 additions & 3 deletions test/models/notes/test_note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ def test_note_lifecycle
relatedOntology: [@@ontology],
})

assert_equal false, n.exist?(reload=true)
assert_equal false, n.exist?
n.save
assert_equal true, n.exist?(reload=true)
assert_equal true, n.exist?
n.delete
assert_equal false, n.exist?(reload=true)
assert_equal false, n.exist?
ensure
n.delete if !n.nil? && n.persistent?
end
Expand Down
4 changes: 2 additions & 2 deletions test/models/skos/test_collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.before_suite

def test_collections_all
submission_parse('INRAETHES', 'Testing skos',
'test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf',
'test/data/ontology_files/thesaurusINRAE_nouv_structure.skos',
1,
process_rdf: true, index_search: false,
run_metrics: false, reasoning: false)
Expand All @@ -31,7 +31,7 @@ def test_collections_all

def test_collection_members
submission_parse('INRAETHES', 'Testing skos',
'test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf',
'test/data/ontology_files/thesaurusINRAE_nouv_structure.skos',
1,
process_rdf: true, index_search: false,
run_metrics: false, reasoning: false)
Expand Down
2 changes: 1 addition & 1 deletion test/models/skos/test_schemes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.before_suite

def test_schemes_all
submission_parse('INRAETHES', 'Testing skos',
'test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf',
'test/data/ontology_files/thesaurusINRAE_nouv_structure.skos',
1,
process_rdf: true, index_search: false,
run_metrics: false, reasoning: false)
Expand Down
8 changes: 2 additions & 6 deletions test/models/skos/test_skos_xl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.before_suite

def test_skos_xl_label_all
submission_parse('INRAETHES', 'Testing skos',
'test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf',
'test/data/ontology_files/thesaurusINRAE_nouv_structure.skos',
1,
process_rdf: true, index_search: false,
run_metrics: false, reasoning: false)
Expand All @@ -27,18 +27,14 @@ def test_skos_xl_label_all

def test_class_skos_xl_label
submission_parse('INRAETHES', 'Testing skos',
'test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf',
'test/data/ontology_files/thesaurusINRAE_nouv_structure.skos',
1,
process_rdf: true, index_search: false,
run_metrics: false, reasoning: false)
ont = 'INRAETHES'
ont = LinkedData::Models::Ontology.find(ont).first
sub = ont.latest_submission

sub.bring_remaining
sub.hasOntologyLanguage = LinkedData::Models::OntologyFormat.find('SKOS').first
sub.save

class_test = LinkedData::Models::Class.find('http://opendata.inrae.fr/thesaurusINRAE/c_16193')
.in(sub).include(:prefLabel,
altLabelXl: [:literalForm],
Expand Down
32 changes: 18 additions & 14 deletions test/models/test_class_main_lang.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,34 @@ class TestClassMainLang < LinkedData::TestOntologyCommon

def self.before_suite
@@old_main_languages = Goo.main_languages
RequestStore.store[:requested_lang] = nil
end

def self.after_suite
Goo.main_languages = @@old_main_languages
RequestStore.store[:requested_lang] = nil
end

def test_map_attribute_found
cls = parse_and_get_class lang: ['fr']
cls = parse_and_get_class lang: [:FR]
cls.bring :unmapped
LinkedData::Models::Class.map_attributes(cls)
assert_equal 'entité matérielle detaillée', cls.label.first
assert_equal 'skos prefLabel fr', cls.prefLabel
assert_equal ['entité matérielle detaillée'], cls.label
assert_includes ['skos prefLabel fr', 'skos prefLabel rien'], cls.prefLabel
assert_equal ['entité fra', 'entite rien'], cls.synonym
end

def test_map_attribute_not_found
cls = parse_and_get_class lang: ['es']
cls = parse_and_get_class lang: [:ES]
cls.bring :unmapped
LinkedData::Models::Class.map_attributes(cls)
assert_equal ['material detailed entity', 'entité matérielle detaillée'], cls.label
assert_equal 'skos prefLabel rien', cls.prefLabel
assert_equal ['entita esp' , 'entite rien' ], cls.synonym
assert_equal ['entita esp', 'entite rien'], cls.synonym
end

def test_map_attribute_secondary_lang
cls = parse_and_get_class lang: %w[es fr]
cls = parse_and_get_class lang: %i[ES FR]
cls.bring :unmapped
LinkedData::Models::Class.map_attributes(cls)
assert_equal ['entité matérielle detaillée'], cls.label
Expand All @@ -38,14 +40,14 @@ def test_map_attribute_secondary_lang


def test_label_main_lang_fr_found
cls = parse_and_get_class lang: ['fr']
assert_equal 'entité matérielle detaillée', cls.label.first
cls = parse_and_get_class lang: [:FR]
assert_equal ['entité matérielle detaillée'], cls.label
assert_equal 'skos prefLabel fr', cls.prefLabel
assert_equal ['entité fra', 'entite rien'], cls.synonym
end

def test_label_main_lang_not_found
cls = parse_and_get_class lang: ['es']
cls = parse_and_get_class lang: [:ES]

assert_equal ['material detailed entity', 'entité matérielle detaillée'], cls.label
assert_equal 'skos prefLabel rien', cls.prefLabel
Expand All @@ -54,15 +56,15 @@ def test_label_main_lang_not_found

def test_label_secondary_lang
# 'es' will not be found so will take 'fr' if fond or anything else
cls = parse_and_get_class lang: %w[es fr]
cls = parse_and_get_class lang: %i[ES FR]

assert_equal ['entité matérielle detaillée'], cls.label
assert_equal 'skos prefLabel rien', cls.prefLabel
assert_equal ['entita esp', 'entite rien'], cls.synonym
end

def test_label_main_lang_en_found
cls = parse_and_get_class lang: ['en']
cls = parse_and_get_class lang: [:EN]
assert_equal 'material detailed entity', cls.label.first
assert_equal 'skos prefLabel en', cls.prefLabel
assert_equal ['entity eng', 'entite rien'], cls.synonym
Expand All @@ -72,7 +74,7 @@ def test_label_main_lang_en_found
private

def parse_and_get_class(lang:, klass: 'http://lirmm.fr/2015/resource/AGROOE_c_03')
lang_set lang
portal_lang_set portal_languages: lang
submission_parse('AGROOE', 'AGROOE Test extract metadata ontology',
'./test/data/ontology_files/agrooeMappings-05-05-2016.owl', 1,
process_rdf: true, index_search: false,
Expand All @@ -85,8 +87,10 @@ def parse_and_get_class(lang:, klass: 'http://lirmm.fr/2015/resource/AGROOE_c_03
cls
end

def lang_set(lang)
Goo.main_languages = lang

def portal_lang_set(portal_languages: nil)
Goo.main_languages = portal_languages if portal_languages
RequestStore.store[:requested_lang] = nil
end

def get_ontology_last_submission(ont)
Expand Down
Loading