From 9d696543850ca6773719898fb02f911050e4ccec Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Fri, 26 Jan 2024 14:21:49 +0100 Subject: [PATCH 01/12] remove useless line preventing sending the reset password email (#65) --- helpers/users_helper.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/helpers/users_helper.rb b/helpers/users_helper.rb index e2c69e60..a9a14d30 100644 --- a/helpers/users_helper.rb +++ b/helpers/users_helper.rb @@ -23,9 +23,7 @@ def send_reset_token(email, username) error 404, "User not found" unless user reset_token = token(36) user.resetToken = reset_token - - return user if user.valid? - + user.save(override_security: true) LinkedData::Utils::Notifications.reset_password(user, reset_token) user From 59bfba67d25afd8f55572f6639058f1033405a23 Mon Sep 17 00:00:00 2001 From: OntoPortal Bot Date: Wed, 7 Feb 2024 02:05:17 +0100 Subject: [PATCH 02/12] [ontoportal-bot] Gemfile.lock update --- Gemfile.lock | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5849b1c8..1fcb2048 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,7 +11,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/goo.git - revision: f8aeea33e270960afb530064d616eaf8343b5473 + revision: 27a38376d7372d46cd39790dbae3eeed0fec15bb branch: development specs: goo (0.0.2) @@ -193,7 +193,6 @@ GEM google-cloud-env (2.1.1) faraday (>= 1.0, < 3.a) google-cloud-errors (1.3.1) - google-protobuf (3.25.2-x86_64-darwin) google-protobuf (3.25.2-x86_64-linux) googleapis-common-protos (1.4.0) google-protobuf (~> 3.14) @@ -208,7 +207,7 @@ GEM multi_json (~> 1.11) os (>= 0.9, < 2.0) signet (>= 0.16, < 2.a) - grpc (1.61.0-x86_64-darwin) + grpc (1.61.0-x86_64-linux) google-protobuf (~> 3.25) googleapis-common-protos-types (~> 1.0) grpc (1.61.0-x86_64-linux) @@ -242,7 +241,7 @@ GEM method_source (1.0.0) mime-types (3.5.2) mime-types-data (~> 3.2015) - mime-types-data (3.2023.1205) + mime-types-data (3.2024.0206) mini_mime (1.1.5) minitest (4.7.5) minitest-stub_any_instance (1.0.3) @@ -252,7 +251,7 @@ GEM multipart-post (2.3.0) mutex_m (0.2.0) net-http-persistent (2.9.4) - net-imap (0.4.9.1) + net-imap (0.4.10) date net-protocol net-pop (0.1.2) @@ -378,7 +377,7 @@ GEM unicorn (>= 4, < 7) uuid (2.3.9) macaddr (~> 1.0) - webmock (3.19.1) + webmock (3.20.0) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) From fe2563e36ba66d0f01a5fa127a0ec20ab848f2d4 Mon Sep 17 00:00:00 2001 From: imadbourouche Date: Wed, 7 Feb 2024 23:34:33 +0100 Subject: [PATCH 03/12] Feature: api endpoint returns json-ld for the element with that URI --- Dockerfile | 1 + Gemfile | 4 +- Gemfile.lock | 14 ++- bin/ontoportal | 4 +- .../dereference_resource_controller.rb | 89 ++++++++++++++ models/simple_wrappers.rb | 2 + .../test_dereference_resource_controller.rb | 115 ++++++++++++++++++ 7 files changed, 222 insertions(+), 7 deletions(-) create mode 100644 controllers/dereference_resource_controller.rb create mode 100644 test/controllers/test_dereference_resource_controller.rb diff --git a/Dockerfile b/Dockerfile index 6feebd11..94e0e656 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,6 +7,7 @@ RUN apt-get update -yqq && apt-get install -yqq --no-install-recommends \ openjdk-11-jre-headless \ raptor2-utils \ wait-for-it \ + libraptor2-dev \ && rm -rf /var/lib/apt/lists/* RUN mkdir -p /srv/ontoportal/ontologies_api diff --git a/Gemfile b/Gemfile index 82554462..78b59262 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,8 @@ gem 'sinatra', '~> 1.0' gem 'sinatra-advanced-routes' gem 'sinatra-contrib', '~> 1.0' gem 'request_store' +gem 'rdf-raptor' + # Rack middleware gem 'ffi' @@ -49,7 +51,7 @@ gem 'ncbo_annotator', git: 'https://github.com/ontoportal-lirmm/ncbo_annotator.g gem 'ncbo_cron', git: 'https://github.com/ontoportal-lirmm/ncbo_cron.git', branch: 'master' gem 'ncbo_ontology_recommender', git: 'https://github.com/ncbo/ncbo_ontology_recommender.git', branch: 'master' gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'master' -gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'development' +gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'feature/sparql-fetch-related-triples' 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 diff --git a/Gemfile.lock b/Gemfile.lock index 1fcb2048..b3d6da90 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,7 +11,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/goo.git - revision: 27a38376d7372d46cd39790dbae3eeed0fec15bb + revision: 6187c205a1310c2f8a72fe8e07fcf99477060fa9 branch: development specs: goo (0.0.2) @@ -54,8 +54,8 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git - revision: 0de5f3b2db02a5d2c008ace73a34d586c24e67a7 - branch: development + revision: 3745f308776d82bff5b346cfa6eebc143daf14bf + branch: feature/sparql-fetch-related-triples specs: ontologies_linked_data (0.0.1) activesupport @@ -248,7 +248,7 @@ GEM mlanett-redis-lock (0.2.7) redis multi_json (1.15.0) - multipart-post (2.3.0) + multipart-post (2.4.0) mutex_m (0.2.0) net-http-persistent (2.9.4) net-imap (0.4.10) @@ -298,6 +298,9 @@ GEM rake (10.5.0) rdf (1.0.8) addressable (>= 2.2) + rdf-raptor (1.0.1) + ffi (>= 1.0) + rdf (>= 1.0.0) redcarpet (3.6.0) redis (4.8.1) redis-activesupport (5.3.0) @@ -422,6 +425,7 @@ DEPENDENCIES rack-test rack-timeout rake (~> 10.0) + rdf-raptor redcarpet redis (~> 4.8.1) redis-activesupport @@ -440,4 +444,4 @@ DEPENDENCIES webmock BUNDLED WITH - 2.4.21 + 2.4.22 diff --git a/bin/ontoportal b/bin/ontoportal index 4840dad3..d488d0a4 100755 --- a/bin/ontoportal +++ b/bin/ontoportal @@ -207,7 +207,9 @@ test() { local custom_command="bundle exec rake test TEST='$test_path' TESTOPTS='$test_options'" echo "run : $custom_command" - run_command "$custom_command" "${all_arguments[@]}" + #run_command "$custom_command" "${all_arguments[@]}" + run_command "$custom_command" --old-path /home/bourouche/PFE/backend/ontologies_linked_data --goo-path /home/bourouche/PFE/backend/goo + } # Function to handle the "run" option diff --git a/controllers/dereference_resource_controller.rb b/controllers/dereference_resource_controller.rb new file mode 100644 index 00000000..e2fcedb3 --- /dev/null +++ b/controllers/dereference_resource_controller.rb @@ -0,0 +1,89 @@ +require_relative '../test/test_case' + + +class ImadController < ApplicationController + + namespace '/dereference_resource' do + + get do + raise error 405, "Method Not Allowd: This route must be provided via POST request with acronym, uri, output_format parameters" + end + + def set_vars + @@acronym = "TST" + @@name = "Test Ontology" + @@test_file = File.expand_path("../../test/data/ontology_files/BRO_v3.1.owl", __FILE__) + @@file_params = { + name: @@name, + hasOntologyLanguage: "OWL", + administeredBy: "tim", + "file" => Rack::Test::UploadedFile.new(@@test_file, ""), + released: DateTime.now.to_s, + contact: [{name: "test_name", email: "test3@example.org"}], + URI: 'https://test.com/test', + status: 'production', + description: 'ontology description' + } + @@status_uploaded = "UPLOADED" + @@status_rdf = "RDF" + end + + def create_user + username = "tim" + test_user = User.new(username: username, email: "#{username}@example.org", password: "password") + test_user.save if test_user.valid? + @@user = test_user.valid? ? test_user : User.find(username).first + end + + def create_onts + ont = Ontology.new(acronym: @@acronym, name: @@name, administeredBy: [@@user]) + end + + post do + set_vars() + create_user() + create_onts() + + acronym = params[:acronym] + uri = params[:uri] + output_format = params[:output_format].presence || 'jsonld' + acronym = URI.decode_www_form_component(acronym) + uri = URI.decode_www_form_component(uri) + unless valid_url?(acronym) && valid_url?(uri) + raise error 500, "INVALID URLs" + return + end + + r = Resource.new(acronym, uri) + case output_format + when 'jsonld' + content_type 'application/json' + reply JSON.parse(r.to_json) + when 'json' + content_type 'application/json' + reply JSON.parse(r.to_json) + when 'xml' + content_type 'application/xml' + reply r.to_xml + when 'turtle' + content_type 'text/turtle' + reply r.to_turtle + when 'ntriples' + content_type 'application/n-triples' + reply r.to_ntriples + else + raise error 500, "Invalid output format" + end + + end + + private + + def valid_url?(url) + uri = URI.parse(url) + uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) + rescue URI::InvalidURIError + false + end + end +end \ No newline at end of file diff --git a/models/simple_wrappers.rb b/models/simple_wrappers.rb index e4097aff..f6aeb027 100644 --- a/models/simple_wrappers.rb +++ b/models/simple_wrappers.rb @@ -29,3 +29,5 @@ ProvisionalRelation = LinkedData::Models::ProvisionalRelation SearchHelper = Sinatra::Helpers::SearchHelper + +Resource = LinkedData::Models::Resource \ No newline at end of file diff --git a/test/controllers/test_dereference_resource_controller.rb b/test/controllers/test_dereference_resource_controller.rb new file mode 100644 index 00000000..77e8b7b9 --- /dev/null +++ b/test/controllers/test_dereference_resource_controller.rb @@ -0,0 +1,115 @@ +require_relative '../test_case' + +class TestImadController < TestCase + + def self.before_suite + #LinkedData::TestCase.backend_4s_delete +=begin + data = %( + @prefix ex: . + @prefix rdf: <#{Goo.vocabulary(:rdf)}> . + @prefix owl: <#{Goo.vocabulary(:owl)}> . + @prefix xsd: . + + ex:TestSubject1 rdf:type owl:Ontology . + ex:TestSubject1 ex:TestPredicate11 "TestObject11" . + ex:TestSubject1 ex:TestPredicate12 ex:test . + ex:TestSubject1 ex:TestPredicate13 1 . + ex:TestSubject1 ex:TestPredicate14 true . + ex:TestSubject1 ex:TestPredicate15 "1.9"^^xsd:float . + ex:TestSubject2 ex:TestPredicate2 1.9 . + ) + graph = "http://example.org/test_graph" + Goo.sparql_data_client.execute_append_request(graph, data, "application/x-turtle") +=end + _set_vars + _create_user + _create_onts + end + + + def self._set_vars + @@acronym = "TST" + @@name = "Test Ontology" + @@test_file = File.expand_path("../../data/ontology_files/BRO_v3.1.owl", __FILE__) + @@file_params = { + name: @@name, + hasOntologyLanguage: "OWL", + administeredBy: "tim", + "file" => Rack::Test::UploadedFile.new(@@test_file, ""), + released: DateTime.now.to_s, + contact: [{name: "test_name", email: "test3@example.org"}], + URI: 'https://test.com/test', + status: 'production', + description: 'ontology description' + } + @@status_uploaded = "UPLOADED" + @@status_rdf = "RDF" + end + + def self._create_user + username = "tim" + test_user = User.new(username: username, email: "#{username}@example.org", password: "password") + test_user.save if test_user.valid? + @@user = test_user.valid? ? test_user : User.find(username).first + end + + def self._create_onts + ont = Ontology.new(acronym: @@acronym, name: @@name, administeredBy: [@@user]) + ont.save + end + + def submit_ontology + post "/ontologies/#{@@acronym}/submissions", @@file_params + assert_equal(201, last_response.status, msg=get_errors(last_response)) + sub = MultiJson.load(last_response.body) + get "/ontologies/#{@@acronym}" + ont = MultiJson.load(last_response.body) + assert ont["acronym"].eql?(@@acronym) + end + + + def test_imad_controller + submit_ontology() + + post "/dereference_resource", { acronym: "http://data.bioontology.org/ontologies/TST/submissions/1", uri: "http://data.bioontology.org/users/tim" } + puts + puts last_response.body + puts + assert last_response.ok? + + + post "/dereference_resource", { acronym: "http://data.bioontology.org/ontologies/TST/submissions/1", uri: "http://data.bioontology.org/users/tim", output_format: "json"} + puts + puts last_response.body + puts + assert last_response.ok? + + + post "/dereference_resource", { acronym: "http://data.bioontology.org/ontologies/TST/submissions/1", uri: "http://data.bioontology.org/users/tim", output_format: "xml"} + puts + puts last_response.body + puts + assert last_response.ok? + + + post "/dereference_resource", { acronym: "http://data.bioontology.org/ontologies/TST/submissions/1", uri: "http://data.bioontology.org/users/tim", output_format: "ntriples"} + puts + puts last_response.body + puts + assert last_response.ok? + + + post "/dereference_resource", { acronym: "http://data.bioontology.org/ontologies/TST/submissions/1", uri: "http://data.bioontology.org/users/tim", output_format: "turtle"} + puts + puts last_response.body + puts + assert last_response.ok? + + # Cleanup + #delete "/ontologies/#{@@acronym}/submissions/#{sub['submissionId']}" + #assert_equal(204, last_response.status, msg=get_errors(last_response)) + + end + +end \ No newline at end of file From bbf3aff666705a548122ae792065dfd1b3aae326 Mon Sep 17 00:00:00 2001 From: imadbourouche Date: Thu, 22 Feb 2024 12:41:08 +0100 Subject: [PATCH 04/12] implement GET, POST requests, and GET /parse to submit INRATHES ontology --- .../dereference_resource_controller.rb | 69 +++++++++---------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/controllers/dereference_resource_controller.rb b/controllers/dereference_resource_controller.rb index e2fcedb3..df539705 100644 --- a/controllers/dereference_resource_controller.rb +++ b/controllers/dereference_resource_controller.rb @@ -4,51 +4,48 @@ class ImadController < ApplicationController namespace '/dereference_resource' do - - get do - raise error 405, "Method Not Allowd: This route must be provided via POST request with acronym, uri, output_format parameters" - end - def set_vars - @@acronym = "TST" - @@name = "Test Ontology" - @@test_file = File.expand_path("../../test/data/ontology_files/BRO_v3.1.owl", __FILE__) - @@file_params = { - name: @@name, - hasOntologyLanguage: "OWL", - administeredBy: "tim", - "file" => Rack::Test::UploadedFile.new(@@test_file, ""), - released: DateTime.now.to_s, - contact: [{name: "test_name", email: "test3@example.org"}], - URI: 'https://test.com/test', - status: 'production', - description: 'ontology description' - } - @@status_uploaded = "UPLOADED" - @@status_rdf = "RDF" + get do + reply "GET: /:acronym/:uri?output_format= OR POST: acronym, uri, output_format parameters" end - - def create_user - username = "tim" - test_user = User.new(username: username, email: "#{username}@example.org", password: "password") - test_user.save if test_user.valid? - @@user = test_user.valid? ? test_user : User.find(username).first + + get "/:acronym/:uri" do + acronym = params[:acronym] + uri = params[:uri] + output_format = params[:output_format].presence || 'jsonld' + process_request(acronym, uri, output_format) end - - def create_onts - ont = Ontology.new(acronym: @@acronym, name: @@name, administeredBy: [@@user]) + + get "/parse" do + LinkedData::SampleData::Ontology.create_ontologies_and_submissions({ + process_submission: true, + acronym: 'INRAETHES', + name: 'INRAETHES', + file_path: './test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf', + ont_count: 1, + submission_count: 1 + }) + ont = Ontology.find('INRAETHES-0').include(:acronym).first + sub = ont.latest_submission + sub.bring_remaining + sub.hasOntologyLanguage = LinkedData::Models::OntologyFormat.find('SKOS').first + sub.save + reply "OK: ONTOLOGY PARSED" end post do - set_vars() - create_user() - create_onts() acronym = params[:acronym] uri = params[:uri] output_format = params[:output_format].presence || 'jsonld' - acronym = URI.decode_www_form_component(acronym) - uri = URI.decode_www_form_component(uri) + process_request(acronym, uri, output_format) + end + + private + + def process_request(acronym_param, uri_param, output_format) + acronym = URI.decode_www_form_component(acronym_param) + uri = URI.decode_www_form_component(uri_param) unless valid_url?(acronym) && valid_url?(uri) raise error 500, "INVALID URLs" return @@ -77,8 +74,6 @@ def create_onts end - private - def valid_url?(url) uri = URI.parse(url) uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) From 0949021f539558437faaf2a4fd3e88cec28be393 Mon Sep 17 00:00:00 2001 From: imadbourouche Date: Thu, 22 Feb 2024 12:41:54 +0100 Subject: [PATCH 05/12] Enhance tests using real data submission --- .../test_dereference_resource_controller.rb | 205 ++++++++++-------- 1 file changed, 114 insertions(+), 91 deletions(-) diff --git a/test/controllers/test_dereference_resource_controller.rb b/test/controllers/test_dereference_resource_controller.rb index 77e8b7b9..83fdeadb 100644 --- a/test/controllers/test_dereference_resource_controller.rb +++ b/test/controllers/test_dereference_resource_controller.rb @@ -1,115 +1,138 @@ require_relative '../test_case' +require 'rexml/document' + class TestImadController < TestCase def self.before_suite - #LinkedData::TestCase.backend_4s_delete -=begin - data = %( - @prefix ex: . - @prefix rdf: <#{Goo.vocabulary(:rdf)}> . - @prefix owl: <#{Goo.vocabulary(:owl)}> . - @prefix xsd: . - - ex:TestSubject1 rdf:type owl:Ontology . - ex:TestSubject1 ex:TestPredicate11 "TestObject11" . - ex:TestSubject1 ex:TestPredicate12 ex:test . - ex:TestSubject1 ex:TestPredicate13 1 . - ex:TestSubject1 ex:TestPredicate14 true . - ex:TestSubject1 ex:TestPredicate15 "1.9"^^xsd:float . - ex:TestSubject2 ex:TestPredicate2 1.9 . - ) - graph = "http://example.org/test_graph" - Goo.sparql_data_client.execute_append_request(graph, data, "application/x-turtle") -=end - _set_vars - _create_user - _create_onts + LinkedData::SampleData::Ontology.create_ontologies_and_submissions({ + process_submission: true, + acronym: 'INRAETHES', + name: 'INRAETHES', + file_path: './test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf', + ont_count: 1, + submission_count: 1 + }) + ont = Ontology.find('INRAETHES-0').include(:acronym).first + sub = ont.latest_submission + sub.bring_remaining + sub.hasOntologyLanguage = LinkedData::Models::OntologyFormat.find('SKOS').first + sub.save + @@graph = "http://data.bioontology.org/ontologies/INRAETHES-0/submissions/1" + @@uri = "http://opendata.inrae.fr/thesaurusINRAE/c_6496" end - def self._set_vars - @@acronym = "TST" - @@name = "Test Ontology" - @@test_file = File.expand_path("../../data/ontology_files/BRO_v3.1.owl", __FILE__) - @@file_params = { - name: @@name, - hasOntologyLanguage: "OWL", - administeredBy: "tim", - "file" => Rack::Test::UploadedFile.new(@@test_file, ""), - released: DateTime.now.to_s, - contact: [{name: "test_name", email: "test3@example.org"}], - URI: 'https://test.com/test', - status: 'production', - description: 'ontology description' - } - @@status_uploaded = "UPLOADED" - @@status_rdf = "RDF" - end - - def self._create_user - username = "tim" - test_user = User.new(username: username, email: "#{username}@example.org", password: "password") - test_user.save if test_user.valid? - @@user = test_user.valid? ? test_user : User.find(username).first - end + def test_dereference_resource_controller_json + skip + post "/dereference_resource", { acronym: @@graph, uri: @@uri , output_format: "json"} + assert last_response.ok? - def self._create_onts - ont = Ontology.new(acronym: @@acronym, name: @@name, administeredBy: [@@user]) - ont.save - end + result = last_response.body + expected_result = %( + { + "@context": { + "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", + "skos": "http://www.w3.org/2004/02/skos/core#", + "owl": "http://www.w3.org/2002/07/owl#" + }, + "@id": "http://opendata.inrae.fr/thesaurusINRAE/c_6496", + "@type": [ + "skos:Concept", + "owl:NamedIndividual" + ], + "skos:broader": { + "@id": "http://opendata.inrae.fr/thesaurusINRAE/c_a9d99f3a" + }, + "skos:inScheme": [ + { + "@id": "http://opendata.inrae.fr/thesaurusINRAE/mt_65" + }, + { + "@id": "http://opendata.inrae.fr/thesaurusINRAE/thesaurusINRAE" + } + ], + "skos:prefLabel": { + "@language": "fr", + "@value": "altération de l'ADN" + }, + "skos:topConceptOf": { + "@id": "http://opendata.inrae.fr/thesaurusINRAE/mt_65" + } + } + ) - def submit_ontology - post "/ontologies/#{@@acronym}/submissions", @@file_params - assert_equal(201, last_response.status, msg=get_errors(last_response)) - sub = MultiJson.load(last_response.body) - get "/ontologies/#{@@acronym}" - ont = MultiJson.load(last_response.body) - assert ont["acronym"].eql?(@@acronym) + a = result.gsub(' ', '').gsub("\n", '') + b = expected_result.gsub(' ', '').gsub("\n", '') + + assert_equal b, a end - - def test_imad_controller - submit_ontology() - - post "/dereference_resource", { acronym: "http://data.bioontology.org/ontologies/TST/submissions/1", uri: "http://data.bioontology.org/users/tim" } - puts - puts last_response.body - puts + def test_dereference_resource_controller_xml + post "/dereference_resource", { acronym: @@graph, uri: @@uri , output_format: "xml"} assert last_response.ok? + result = last_response.body + expected_result = %( + + + + + + + + + altération de l'ADN + + + ) + a = result.gsub('\\"', '"').gsub('\\n', "").gsub(" ", "")[1..-2] + b = expected_result.gsub(' ', '').gsub("\n", '') - post "/dereference_resource", { acronym: "http://data.bioontology.org/ontologies/TST/submissions/1", uri: "http://data.bioontology.org/users/tim", output_format: "json"} - puts - puts last_response.body - puts - assert last_response.ok? - + assert_equal b, a + end - post "/dereference_resource", { acronym: "http://data.bioontology.org/ontologies/TST/submissions/1", uri: "http://data.bioontology.org/users/tim", output_format: "xml"} - puts - puts last_response.body - puts + def test_dereference_resource_controller_ntriples + post "/dereference_resource", { acronym: @@graph, uri: @@uri , output_format: "ntriples"} assert last_response.ok? + result = last_response.body + expected_result = %( + . + . + . + . + . + . + "alt\\\\u00E9rationdel'ADN"@fr . + ) + a = result.gsub('\\"', '"').gsub(' ', '').gsub("\\n", '')[1..-2] + b = expected_result.gsub(' ', '').gsub("\n", '') - post "/dereference_resource", { acronym: "http://data.bioontology.org/ontologies/TST/submissions/1", uri: "http://data.bioontology.org/users/tim", output_format: "ntriples"} - puts - puts last_response.body - puts - assert last_response.ok? - + assert_equal b, a + end - post "/dereference_resource", { acronym: "http://data.bioontology.org/ontologies/TST/submissions/1", uri: "http://data.bioontology.org/users/tim", output_format: "turtle"} - puts - puts last_response.body - puts + def test_dereference_resource_controller_turtle + post "/dereference_resource", { acronym: @@graph, uri: @@uri , output_format: "turtle"} assert last_response.ok? - # Cleanup - #delete "/ontologies/#{@@acronym}/submissions/#{sub['submissionId']}" - #assert_equal(204, last_response.status, msg=get_errors(last_response)) - - end + result = last_response.body + expected_result = %( + @prefix rdf: . + @prefix skos: . + @prefix owl: . + + + a owl:NamedIndividual, skos:Concept ; + skos:broader ; + skos:inScheme , ; + skos:prefLabel "altération de l'ADN" ; + skos:topConceptOf . + ) + a = result.gsub('\\"','"').gsub(' ', '').gsub("\\n", '')[1..-2] + b = expected_result.gsub(' ', '').gsub("\n", '') + + assert_equal b, a + end end \ No newline at end of file From 471df3379445c30335a00a67a50acbc18e9970b2 Mon Sep 17 00:00:00 2001 From: imadbourouche Date: Thu, 22 Feb 2024 12:42:53 +0100 Subject: [PATCH 06/12] Enhance bin/ontoportal to make it able to run localy with UI --- Gemfile.lock | 58 ++++++++++++++++++++++++++++++-------------------- bin/ontoportal | 8 +++---- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index b3d6da90..da54f90a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,13 +11,15 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/goo.git - revision: 6187c205a1310c2f8a72fe8e07fcf99477060fa9 + revision: 0a30e18a5d0ed52e47382df7a2483581a68bcec8 branch: development specs: goo (0.0.2) - addressable (~> 2.8) pry - rdf (= 1.0.8) + rdf (= 3.2.11) + rdf-raptor + rdf-rdfxml + rdf-vocab redis rest-client rsolr @@ -37,7 +39,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ncbo_cron.git - revision: f33a917aae2000270d5b560cadf7044bff822779 + revision: 9ec0147203007cc368a5119ffe1a019fa8701c14 branch: master specs: ncbo_cron (0.0.1) @@ -54,7 +56,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git - revision: 3745f308776d82bff5b346cfa6eebc143daf14bf + revision: 3c18750e06052bef7d7d3a6efd67389b05d8d419 branch: feature/sparql-fetch-related-triples specs: ontologies_linked_data (0.0.1) @@ -109,6 +111,7 @@ GEM airbrussh (1.5.1) sshkit (>= 1.6.1, != 1.7.0) backports (3.24.1) + base64 (0.2.0) bcrypt (3.1.20) bcrypt_pbkdf (1.1.0) bigdecimal (1.4.2) @@ -127,7 +130,7 @@ GEM sshkit (~> 1.3) coderay (1.1.3) concurrent-ruby (1.2.3) - crack (0.4.6) + crack (1.0.0) bigdecimal rexml cube-ruby (0.0.3) @@ -193,14 +196,14 @@ GEM google-cloud-env (2.1.1) faraday (>= 1.0, < 3.a) google-cloud-errors (1.3.1) - google-protobuf (3.25.2-x86_64-linux) + google-protobuf (3.25.3-x86_64-linux) googleapis-common-protos (1.4.0) google-protobuf (~> 3.14) googleapis-common-protos-types (~> 1.2) grpc (~> 1.27) - googleapis-common-protos-types (1.11.0) + googleapis-common-protos-types (1.12.0) google-protobuf (~> 3.18) - googleauth (1.9.2) + googleauth (1.11.0) faraday (>= 1.0, < 3.a) google-cloud-env (~> 2.1) jwt (>= 1.4, < 3.0) @@ -210,13 +213,11 @@ GEM grpc (1.61.0-x86_64-linux) google-protobuf (~> 3.25) googleapis-common-protos-types (~> 1.0) - grpc (1.61.0-x86_64-linux) - google-protobuf (~> 3.25) - googleapis-common-protos-types (~> 1.0) haml (5.2.2) temple (>= 0.8.0) tilt hashdiff (1.1.0) + htmlentities (4.3.4) http-accept (1.7.0) http-cookie (1.0.5) domain_name (~> 0.5) @@ -227,9 +228,11 @@ GEM json-schema (2.8.1) addressable (>= 2.4) json_pure (2.7.1) - jwt (2.7.1) + jwt (2.8.0) + base64 kgio (2.11.4) libxml-ruby (5.0.2) + link_header (0.0.8) logger (1.6.0) macaddr (1.7.2) systemu (~> 2.6.5) @@ -287,7 +290,7 @@ GEM rack (>= 0.4) rack-cors (1.0.6) rack (>= 1.6.0) - rack-mini-profiler (3.3.0) + rack-mini-profiler (3.3.1) rack (>= 1.2.0) rack-protection (1.5.5) rack @@ -296,11 +299,21 @@ GEM rack-timeout (0.6.3) raindrops (0.20.1) rake (10.5.0) - rdf (1.0.8) - addressable (>= 2.2) - rdf-raptor (1.0.1) - ffi (>= 1.0) - rdf (>= 1.0.0) + rdf (3.2.11) + link_header (~> 0.0, >= 0.0.8) + rdf-raptor (3.2.0) + ffi (~> 1.15) + rdf (~> 3.2) + rdf-rdfxml (3.2.2) + builder (~> 3.2) + htmlentities (~> 4.3) + rdf (~> 3.2) + rdf-xsd (~> 3.2) + rdf-vocab (3.2.7) + rdf (~> 3.2, >= 3.2.4) + rdf-xsd (3.2.1) + rdf (~> 3.2) + rexml (~> 3.2) redcarpet (3.6.0) redis (4.8.1) redis-activesupport (5.3.0) @@ -315,7 +328,7 @@ GEM declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) uber (< 0.2.0) - request_store (1.5.1) + request_store (1.6.0) rack (>= 1.4) rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) @@ -332,7 +345,7 @@ GEM rubyzip (2.3.2) rufus-scheduler (2.0.24) tzinfo (>= 0.3.22) - signet (0.18.0) + signet (0.19.0) addressable (~> 2.8) faraday (>= 0.17.5, < 3.a) jwt (>= 1.5, < 3.0) @@ -380,13 +393,12 @@ GEM unicorn (>= 4, < 7) uuid (2.3.9) macaddr (~> 1.0) - webmock (3.20.0) + webmock (3.22.0) addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) PLATFORMS - x86_64-darwin-23 x86_64-linux DEPENDENCIES diff --git a/bin/ontoportal b/bin/ontoportal index d488d0a4..84df906e 100755 --- a/bin/ontoportal +++ b/bin/ontoportal @@ -76,7 +76,7 @@ build_docker_run_cmd() { local goo_path="$3" local sparql_client_path="$4" - local docker_run_cmd="docker compose run --rm -it" + local docker_run_cmd="docker compose -p ontoportal_docker run --rm -it --name api-service" local bash_cmd="" # Conditionally add bind mounts only if the paths are not empty @@ -177,7 +177,7 @@ run_command() { dev() { echo "Starting OntoPortal API development server..." - local custom_command="bundle exec shotgun --host 0.0.0.0 --env=development" + local custom_command="bundle exec rackup --host 0.0.0.0 --env=development --port 9393" run_command "$custom_command" "$@" } @@ -207,9 +207,7 @@ test() { local custom_command="bundle exec rake test TEST='$test_path' TESTOPTS='$test_options'" echo "run : $custom_command" - #run_command "$custom_command" "${all_arguments[@]}" - run_command "$custom_command" --old-path /home/bourouche/PFE/backend/ontologies_linked_data --goo-path /home/bourouche/PFE/backend/goo - + run_command "$custom_command" "${all_arguments[@]}" } # Function to handle the "run" option From c1460199db32e8cdc8b3790b5656c54458ef1bc4 Mon Sep 17 00:00:00 2001 From: imadbourouche Date: Thu, 22 Feb 2024 15:10:28 +0100 Subject: [PATCH 07/12] Small fixes - change controller name and test controller name - remove /parse endpoint - rackup to shotgun in bin/ontoportal --- bin/ontoportal | 2 +- controllers/dereference_resource_controller.rb | 18 +----------------- .../test_dereference_resource_controller.rb | 2 +- 3 files changed, 3 insertions(+), 19 deletions(-) diff --git a/bin/ontoportal b/bin/ontoportal index 84df906e..ea93cebd 100755 --- a/bin/ontoportal +++ b/bin/ontoportal @@ -177,7 +177,7 @@ run_command() { dev() { echo "Starting OntoPortal API development server..." - local custom_command="bundle exec rackup --host 0.0.0.0 --env=development --port 9393" + local custom_command="bundle exec shotgun --host 0.0.0.0 --env=development --port 9393" run_command "$custom_command" "$@" } diff --git a/controllers/dereference_resource_controller.rb b/controllers/dereference_resource_controller.rb index df539705..3b62b1bc 100644 --- a/controllers/dereference_resource_controller.rb +++ b/controllers/dereference_resource_controller.rb @@ -1,7 +1,7 @@ require_relative '../test/test_case' -class ImadController < ApplicationController +class DereferenceResourceController < ApplicationController namespace '/dereference_resource' do @@ -16,22 +16,6 @@ class ImadController < ApplicationController process_request(acronym, uri, output_format) end - get "/parse" do - LinkedData::SampleData::Ontology.create_ontologies_and_submissions({ - process_submission: true, - acronym: 'INRAETHES', - name: 'INRAETHES', - file_path: './test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf', - ont_count: 1, - submission_count: 1 - }) - ont = Ontology.find('INRAETHES-0').include(:acronym).first - sub = ont.latest_submission - sub.bring_remaining - sub.hasOntologyLanguage = LinkedData::Models::OntologyFormat.find('SKOS').first - sub.save - reply "OK: ONTOLOGY PARSED" - end post do diff --git a/test/controllers/test_dereference_resource_controller.rb b/test/controllers/test_dereference_resource_controller.rb index 83fdeadb..3952945e 100644 --- a/test/controllers/test_dereference_resource_controller.rb +++ b/test/controllers/test_dereference_resource_controller.rb @@ -2,7 +2,7 @@ require 'rexml/document' -class TestImadController < TestCase +class TestDereferenceResourceController < TestCase def self.before_suite LinkedData::SampleData::Ontology.create_ontologies_and_submissions({ From db9c9f49e0f557f601d1e027240cbfba8633c5e3 Mon Sep 17 00:00:00 2001 From: imadbourouche Date: Mon, 11 Mar 2024 10:14:03 +0100 Subject: [PATCH 08/12] Fix test dereference resource controller - in json test, before we test the result we sort the hashes with the function (sort_nested_hash) - in xml, ntriples and turtle, we split the result and the expected result, sort them and compare them --- .../test_dereference_resource_controller.rb | 179 ++++++++++-------- 1 file changed, 97 insertions(+), 82 deletions(-) diff --git a/test/controllers/test_dereference_resource_controller.rb b/test/controllers/test_dereference_resource_controller.rb index 3952945e..a5a9651d 100644 --- a/test/controllers/test_dereference_resource_controller.rb +++ b/test/controllers/test_dereference_resource_controller.rb @@ -24,47 +24,36 @@ def self.before_suite def test_dereference_resource_controller_json - skip post "/dereference_resource", { acronym: @@graph, uri: @@uri , output_format: "json"} assert last_response.ok? result = last_response.body - expected_result = %( - { - "@context": { - "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", - "skos": "http://www.w3.org/2004/02/skos/core#", - "owl": "http://www.w3.org/2002/07/owl#" - }, - "@id": "http://opendata.inrae.fr/thesaurusINRAE/c_6496", - "@type": [ - "skos:Concept", - "owl:NamedIndividual" - ], - "skos:broader": { - "@id": "http://opendata.inrae.fr/thesaurusINRAE/c_a9d99f3a" - }, - "skos:inScheme": [ - { - "@id": "http://opendata.inrae.fr/thesaurusINRAE/mt_65" - }, - { - "@id": "http://opendata.inrae.fr/thesaurusINRAE/thesaurusINRAE" - } - ], - "skos:prefLabel": { - "@language": "fr", - "@value": "altération de l'ADN" - }, - "skos:topConceptOf": { - "@id": "http://opendata.inrae.fr/thesaurusINRAE/mt_65" - } - } - ) - - a = result.gsub(' ', '').gsub("\n", '') - b = expected_result.gsub(' ', '').gsub("\n", '') - + expected_result = <<-JSON + { + "@context": { + "ns0": "http://opendata.inrae.fr/thesaurusINRAE/", + "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", + "owl": "http://www.w3.org/2002/07/owl#", + "skos": "http://www.w3.org/2004/02/skos/core#" + }, + "@graph": [ + { + "@id": "ns0:c_6496", + "@type": ["owl:NamedIndividual", "skos:Concept"], + "skos:broader": {"@id": "ns0:c_a9d99f3a"}, + "skos:topConceptOf": {"@id": "ns0:mt_65"}, + "skos:inScheme": [{"@id": "ns0:thesaurusINRAE"}, {"@id": "ns0:mt_65"}], + "skos:prefLabel": {"@value": "altération de l'ADN", "@language": "fr"} + }, + { + "@id": "ns0:mt_65", + "skos:hasTopConcept": {"@id": "ns0:c_6496"} + } + ] + } + JSON + a = sort_nested_hash(JSON.parse(result)) + b = sort_nested_hash(JSON.parse(expected_result)) assert_equal b, a end @@ -73,23 +62,26 @@ def test_dereference_resource_controller_xml assert last_response.ok? result = last_response.body - expected_result = %( - - - - - - - - - altération de l'ADN - - - ) - a = result.gsub('\\"', '"').gsub('\\n', "").gsub(" ", "")[1..-2] - b = expected_result.gsub(' ', '').gsub("\n", '') - - assert_equal b, a + expected_result = <<-XML + + + + + + + + + altération de l'ADN + + + + + + XML + a = result.gsub('\\"', '"').gsub(" ", "")[1..-2].split("\\n").reject(&:empty?) + b = expected_result.gsub(' ', '').split("\n").reject(&:empty?) + + assert_equal b.sort , a.sort end def test_dereference_resource_controller_ntriples @@ -97,19 +89,20 @@ def test_dereference_resource_controller_ntriples assert last_response.ok? result = last_response.body - expected_result = %( - . - . - . - . - . - . - "alt\\\\u00E9rationdel'ADN"@fr . - ) - a = result.gsub('\\"', '"').gsub(' ', '').gsub("\\n", '')[1..-2] - b = expected_result.gsub(' ', '').gsub("\n", '') - - assert_equal b, a + expected_result = <<-NTRIPLES + . + . + . + . + . + . + "alt\\\\u00E9rationdel'ADN"@fr . + . + NTRIPLES + a = result.gsub('\\"', '"').gsub(' ', '')[1..-2].split("\\n").reject(&:empty?) + b = expected_result.gsub(' ', '').split("\n").reject(&:empty?) + + assert_equal b.sort, a.sort end def test_dereference_resource_controller_turtle @@ -117,22 +110,44 @@ def test_dereference_resource_controller_turtle assert last_response.ok? result = last_response.body - expected_result = %( - @prefix rdf: . - @prefix skos: . - @prefix owl: . - - - a owl:NamedIndividual, skos:Concept ; - skos:broader ; - skos:inScheme , ; - skos:prefLabel "altération de l'ADN" ; - skos:topConceptOf . - ) - a = result.gsub('\\"','"').gsub(' ', '').gsub("\\n", '')[1..-2] - b = expected_result.gsub(' ', '').gsub("\n", '') + expected_result = <<-TURTLE + @prefix rdf: . + @prefix ns0: . + @prefix owl: . + @prefix skos: . + + ns0:c_6496 + a owl:NamedIndividual, skos:Concept ; + skos:broader ns0:c_a9d99f3a ; + skos:inScheme ns0:mt_65, ns0:thesaurusINRAE ; + skos:prefLabel "altération de l'ADN"@fr ; + skos:topConceptOf ns0:mt_65 . + + ns0:mt_65 + skos:hasTopConcept ns0:c_6496 . + TURTLE + a = result.gsub('\\"', '"').gsub(' ', '')[1..-2].split("\\n").reject(&:empty?) + b = expected_result.gsub(' ', '').split("\n").reject(&:empty?) + + assert_equal b.sort, a.sort + end - assert_equal b, a + private + + def sort_nested_hash(hash) + sorted_hash = {} + + hash.each do |key, value| + if value.is_a?(Hash) + sorted_hash[key] = sort_nested_hash(value) + elsif value.is_a?(Array) + sorted_hash[key] = value.map { |item| item.is_a?(Hash) ? sort_nested_hash(item) : item }.sort_by { |item| item.to_s } + else + sorted_hash[key] = value + end + end + + sorted_hash.sort.to_h end end \ No newline at end of file From 403e98a272f8670c19601c26776f5c24b0623ec4 Mon Sep 17 00:00:00 2001 From: imadbourouche Date: Mon, 11 Mar 2024 10:14:28 +0100 Subject: [PATCH 09/12] update gemfile: add json-ld (3.0.2) --- Gemfile | 3 +- Gemfile.lock | 465 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 467 insertions(+), 1 deletion(-) create mode 100644 Gemfile.lock diff --git a/Gemfile b/Gemfile index 830003c0..2a9c4264 100644 --- a/Gemfile +++ b/Gemfile @@ -15,6 +15,7 @@ gem 'sinatra-advanced-routes' gem 'sinatra-contrib', '~> 1.0' gem 'request_store' gem 'parallel' +gem 'json-ld', '~> 3.0.2' # Rack middleware gem 'ffi' @@ -50,7 +51,7 @@ gem 'ncbo_annotator', git: 'https://github.com/ontoportal-lirmm/ncbo_annotator.g gem 'ncbo_cron', git: 'https://github.com/ontoportal-lirmm/ncbo_cron.git', branch: 'master' gem 'ncbo_ontology_recommender', git: 'https://github.com/ncbo/ncbo_ontology_recommender.git', branch: 'master' gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'master' -gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'feature/sparql-fetch-related-triples' +gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'development' 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 diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 00000000..2e5e0b4a --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,465 @@ +GIT + remote: https://github.com/ncbo/ncbo_ontology_recommender.git + revision: 013abea4af3b10910ec661dbb358a4b6cae198a4 + branch: master + specs: + ncbo_ontology_recommender (0.0.1) + goo + ncbo_annotator + ontologies_linked_data + redis + +GIT + remote: https://github.com/ontoportal-lirmm/goo.git + revision: 6c51346b6f150a69391794b7909b30592acbbe0e + branch: development + specs: + goo (0.0.2) + addressable (~> 2.8) + pry + rdf (= 3.2.11) + rdf-raptor + rdf-rdfxml + rdf-vocab + redis + rest-client + rsolr + sparql-client + uuid + +GIT + remote: https://github.com/ontoportal-lirmm/ncbo_annotator.git + revision: 1eb751b65d10ae23d45c74e0516c78754a8419f0 + branch: development + specs: + ncbo_annotator (0.0.1) + goo + ontologies_linked_data + redis + ruby-xxHash + +GIT + remote: https://github.com/ontoportal-lirmm/ncbo_cron.git + revision: 9ec0147203007cc368a5119ffe1a019fa8701c14 + branch: master + specs: + ncbo_cron (0.0.1) + dante + goo + google-analytics-data + google-apis-analytics_v3 + mlanett-redis-lock + multi_json + ncbo_annotator + ontologies_linked_data + redis + rufus-scheduler (~> 2.0.24) + +GIT + remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git + revision: c9738faf4079fbbd36dcf9c45cc4f9525a9812b6 + branch: development + specs: + ontologies_linked_data (0.0.1) + activesupport + bcrypt + goo + json + libxml-ruby + multi_json + oj + omni_logger + pony + rack + rack-test + rsolr + rubyzip + +GIT + remote: https://github.com/ontoportal-lirmm/sparql-client.git + revision: 180c818f7715baac64b2699bb452ef5c756f62c5 + 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/palexander/rack-post-body-to-params.git + revision: 0fd30e710386d0cb8a3a6833d9549d7b655d5398 + branch: multipart_support + specs: + rack-post-body-to-params (0.1.8) + activesupport (>= 2.3) + +GIT + remote: https://github.com/palexander/shotgun.git + revision: db198224aaab2e4cb9b049adccb30e387d88bc3b + branch: ncbo + specs: + shotgun (0.9) + rack (>= 1.0) + +GEM + remote: https://rubygems.org/ + specs: + activesupport (3.2.22.5) + i18n (~> 0.6, >= 0.6.4) + multi_json (~> 1.0) + addressable (2.8.6) + public_suffix (>= 2.0.2, < 6.0) + airbrussh (1.5.1) + sshkit (>= 1.6.1, != 1.7.0) + backports (3.25.0) + base64 (0.2.0) + bcrypt (3.1.20) + bcrypt_pbkdf (1.1.0) + bigdecimal (1.4.2) + builder (3.2.4) + capistrano (3.18.0) + airbrussh (>= 1.0.0) + i18n + rake (>= 10.0.0) + sshkit (>= 1.9.0) + capistrano-bundler (2.1.0) + capistrano (~> 3.1) + capistrano-locally (0.3.0) + capistrano (~> 3.0) + capistrano-rbenv (2.2.0) + capistrano (~> 3.1) + sshkit (~> 1.3) + coderay (1.1.3) + concurrent-ruby (1.2.3) + crack (1.0.0) + bigdecimal + rexml + cube-ruby (0.0.3) + dante (0.2.0) + date (3.3.4) + declarative (0.0.20) + docile (1.4.0) + domain_name (0.6.20240107) + ed25519 (1.3.0) + faraday (1.10.3) + faraday-em_http (~> 1.0) + faraday-em_synchrony (~> 1.0) + faraday-excon (~> 1.1) + faraday-httpclient (~> 1.0) + faraday-multipart (~> 1.0) + faraday-net_http (~> 1.0) + faraday-net_http_persistent (~> 1.0) + faraday-patron (~> 1.0) + faraday-rack (~> 1.0) + faraday-retry (~> 1.0) + ruby2_keywords (>= 0.0.4) + faraday-em_http (1.0.0) + faraday-em_synchrony (1.0.0) + faraday-excon (1.1.0) + faraday-httpclient (1.0.1) + faraday-multipart (1.0.4) + multipart-post (~> 2) + faraday-net_http (1.0.1) + faraday-net_http_persistent (1.2.0) + faraday-patron (1.0.0) + faraday-rack (1.0.0) + faraday-retry (1.0.3) + ffi (1.16.3) + gapic-common (0.21.1) + faraday (>= 1.9, < 3.a) + faraday-retry (>= 1.0, < 3.a) + google-protobuf (~> 3.18) + googleapis-common-protos (>= 1.4.0, < 2.a) + googleapis-common-protos-types (>= 1.11.0, < 2.a) + googleauth (~> 1.9) + grpc (~> 1.59) + get_process_mem (0.2.7) + ffi (~> 1.0) + google-analytics-data (0.6.0) + google-analytics-data-v1beta (>= 0.11, < 2.a) + google-cloud-core (~> 1.6) + google-analytics-data-v1beta (0.12.0) + gapic-common (>= 0.21.1, < 2.a) + google-cloud-errors (~> 1.0) + google-apis-analytics_v3 (0.15.0) + google-apis-core (>= 0.14.0, < 2.a) + google-apis-core (0.14.0) + addressable (~> 2.5, >= 2.5.1) + googleauth (~> 1.9) + httpclient (>= 2.8.1, < 3.a) + mini_mime (~> 1.0) + representable (~> 3.0) + retriable (>= 2.0, < 4.a) + rexml + google-cloud-core (1.7.0) + google-cloud-env (>= 1.0, < 3.a) + google-cloud-errors (~> 1.0) + google-cloud-env (2.1.1) + faraday (>= 1.0, < 3.a) + google-cloud-errors (1.4.0) + google-protobuf (3.25.3-x86_64-linux) + googleapis-common-protos (1.5.0) + google-protobuf (~> 3.18) + googleapis-common-protos-types (~> 1.7) + grpc (~> 1.41) + googleapis-common-protos-types (1.13.0) + google-protobuf (~> 3.18) + googleauth (1.11.0) + faraday (>= 1.0, < 3.a) + google-cloud-env (~> 2.1) + jwt (>= 1.4, < 3.0) + multi_json (~> 1.11) + os (>= 0.9, < 2.0) + signet (>= 0.16, < 2.a) + grpc (1.62.0-x86_64-linux) + google-protobuf (~> 3.25) + googleapis-common-protos-types (~> 1.0) + haml (5.2.2) + temple (>= 0.8.0) + tilt + hashdiff (1.1.0) + htmlentities (4.3.4) + http-accept (1.7.0) + http-cookie (1.0.5) + domain_name (~> 0.5) + httpclient (2.8.3) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + json (2.7.1) + json-ld (3.0.2) + multi_json (~> 1.12) + rdf (>= 2.2.8, < 4.0) + json-schema (2.8.1) + addressable (>= 2.4) + json_pure (2.7.1) + jwt (2.8.1) + base64 + kgio (2.11.4) + libxml-ruby (5.0.2) + link_header (0.0.8) + logger (1.6.0) + macaddr (1.7.2) + systemu (~> 2.6.5) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + method_source (1.0.0) + mime-types (3.5.2) + mime-types-data (~> 3.2015) + mime-types-data (3.2024.0305) + mini_mime (1.1.5) + minitest (4.7.5) + minitest-stub_any_instance (1.0.3) + mlanett-redis-lock (0.2.7) + redis + multi_json (1.15.0) + multipart-post (2.4.0) + mutex_m (0.2.0) + net-http-persistent (2.9.4) + net-imap (0.4.10) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-scp (4.0.0) + net-ssh (>= 2.6.5, < 8.0.0) + net-sftp (4.0.0) + net-ssh (>= 5.0.0, < 8.0.0) + net-smtp (0.4.0.1) + net-protocol + net-ssh (7.2.1) + netrc (0.11.0) + newrelic_rpm (9.7.1) + oj (2.18.5) + omni_logger (0.1.4) + logger + os (1.1.4) + parallel (1.24.0) + parseconfig (1.1.2) + pony (1.13.1) + mail (>= 2.0) + pry (0.14.2) + coderay (~> 1.1) + method_source (~> 1.0) + public_suffix (5.0.4) + rack (1.6.13) + rack-accept (0.4.5) + rack (>= 0.4) + rack-attack (6.6.1) + rack (>= 1.0, < 3) + rack-cache (1.13.0) + rack (>= 0.4) + rack-cors (1.0.6) + rack (>= 1.6.0) + rack-mini-profiler (3.3.1) + rack (>= 1.2.0) + rack-protection (1.5.5) + rack + rack-test (2.1.0) + rack (>= 1.3) + rack-timeout (0.6.3) + raindrops (0.20.1) + rake (10.5.0) + rdf (3.2.11) + link_header (~> 0.0, >= 0.0.8) + rdf-raptor (3.2.0) + ffi (~> 1.15) + rdf (~> 3.2) + rdf-rdfxml (3.2.2) + builder (~> 3.2) + htmlentities (~> 4.3) + rdf (~> 3.2) + rdf-xsd (~> 3.2) + rdf-vocab (3.2.7) + rdf (~> 3.2, >= 3.2.4) + rdf-xsd (3.2.1) + rdf (~> 3.2) + rexml (~> 3.2) + redcarpet (3.6.0) + redis (4.8.1) + redis-activesupport (5.3.0) + activesupport (>= 3, < 8) + redis-store (>= 1.3, < 2) + redis-rack-cache (2.2.1) + rack-cache (>= 1.10, < 2) + redis-store (>= 1.6, < 2) + redis-store (1.9.1) + redis (>= 4, < 5) + representable (3.2.0) + declarative (< 0.1.0) + trailblazer-option (>= 0.1.1, < 0.2.0) + uber (< 0.2.0) + request_store (1.6.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) + retriable (3.1.2) + rexml (3.2.6) + rsolr (2.5.0) + builder (>= 2.1.2) + faraday (>= 0.9, < 3, != 2.0.0) + ruby-xxHash (0.4.0.2) + ruby2_keywords (0.0.5) + rubyzip (2.3.2) + rufus-scheduler (2.0.24) + tzinfo (>= 0.3.22) + signet (0.19.0) + addressable (~> 2.8) + faraday (>= 0.17.5, < 3.a) + jwt (>= 1.5, < 3.0) + multi_json (~> 1.10) + simplecov (0.22.0) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-cobertura (2.1.0) + rexml + simplecov (~> 0.19) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) + sinatra (1.4.8) + rack (~> 1.5) + rack-protection (~> 1.4) + tilt (>= 1.3, < 3) + sinatra-advanced-routes (0.5.3) + sinatra (~> 1.0) + sinatra-contrib (1.4.7) + backports (>= 2.0) + multi_json + rack-protection + rack-test + sinatra (~> 1.4.0) + tilt (>= 1.3, < 3) + sshkit (1.22.0) + mutex_m + net-scp (>= 1.1.2) + net-sftp (>= 2.1.2) + net-ssh (>= 2.8.0) + systemu (2.6.5) + temple (0.10.3) + tilt (2.3.0) + timeout (0.4.1) + trailblazer-option (0.1.2) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + uber (0.1.0) + unicorn (6.1.0) + kgio (~> 2.6) + raindrops (~> 0.7) + unicorn-worker-killer (0.4.5) + get_process_mem (~> 0) + unicorn (>= 4, < 7) + uuid (2.3.9) + macaddr (~> 1.0) + webmock (3.23.0) + addressable (>= 2.8.0) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) + +PLATFORMS + x86_64-linux + +DEPENDENCIES + activesupport (~> 3.2) + bcrypt_pbkdf (>= 1.0, < 2.0) + bigdecimal (= 1.4.2) + capistrano (~> 3) + capistrano-bundler + capistrano-locally + capistrano-rbenv + cube-ruby + ed25519 (>= 1.2, < 2.0) + faraday (~> 1.9) + ffi + goo! + haml (~> 5.2.2) + json-ld (~> 3.0.2) + json-schema (~> 2.0) + minitest (~> 4.0) + minitest-stub_any_instance + multi_json (~> 1.0) + ncbo_annotator! + ncbo_cron! + ncbo_ontology_recommender! + newrelic_rpm + oj (~> 2.0) + ontologies_linked_data! + parallel + parseconfig + pry + rack + rack-accept (~> 0.4) + rack-attack (~> 6.6.1) + rack-cache (~> 1.13.0) + rack-cors + rack-mini-profiler + rack-post-body-to-params! + rack-test + rack-timeout + rake (~> 10.0) + redcarpet + redis (~> 4.8.1) + redis-activesupport + redis-rack-cache (~> 2.0) + redis-store (= 1.9.1) + request_store + shotgun! + simplecov + simplecov-cobertura + sinatra (~> 1.0) + sinatra-advanced-routes + sinatra-contrib (~> 1.0) + sparql-client! + unicorn + unicorn-worker-killer + webmock + +BUNDLED WITH + 2.4.22 From e78628bfc8104302f15f82878542b241f49e9549 Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Mon, 11 Mar 2024 12:40:18 +0100 Subject: [PATCH 10/12] change derefrencement namespacing and clean code --- Gemfile.lock | 1 + .../dereference_resource_controller.rb | 105 ++++++++---------- .../test_dereference_resource_controller.rb | 20 ++-- 3 files changed, 58 insertions(+), 68 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2e5e0b4a..f7f9fe20 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -404,6 +404,7 @@ GEM hashdiff (>= 0.4.0, < 2.0.0) PLATFORMS + x86_64-darwin-23 x86_64-linux DEPENDENCIES diff --git a/controllers/dereference_resource_controller.rb b/controllers/dereference_resource_controller.rb index 3b62b1bc..e566c38c 100644 --- a/controllers/dereference_resource_controller.rb +++ b/controllers/dereference_resource_controller.rb @@ -2,67 +2,58 @@ class DereferenceResourceController < ApplicationController + namespace "/ontologies" do + get "/:acronym/resolve/:uri" do + acronym = params[:acronym] + uri = params[:uri] - namespace '/dereference_resource' do - - get do - reply "GET: /:acronym/:uri?output_format= OR POST: acronym, uri, output_format parameters" - end + if acronym.blank? || uri.blank? + error 500, "Usage: ontologies/:acronym/resolve/:uri?output_format= OR POST: acronym, uri, output_format parameters" + end - get "/:acronym/:uri" do - acronym = params[:acronym] - uri = params[:uri] - output_format = params[:output_format].presence || 'jsonld' - process_request(acronym, uri, output_format) - end - - - post do - - acronym = params[:acronym] - uri = params[:uri] - output_format = params[:output_format].presence || 'jsonld' - process_request(acronym, uri, output_format) - end - - private - - def process_request(acronym_param, uri_param, output_format) - acronym = URI.decode_www_form_component(acronym_param) - uri = URI.decode_www_form_component(uri_param) - unless valid_url?(acronym) && valid_url?(uri) - raise error 500, "INVALID URLs" - return - end + output_format = params[:output_format].presence || 'jsonld' + process_request(acronym, uri, output_format) + end - r = Resource.new(acronym, uri) - case output_format - when 'jsonld' - content_type 'application/json' - reply JSON.parse(r.to_json) - when 'json' - content_type 'application/json' - reply JSON.parse(r.to_json) - when 'xml' - content_type 'application/xml' - reply r.to_xml - when 'turtle' - content_type 'text/turtle' - reply r.to_turtle - when 'ntriples' - content_type 'application/n-triples' - reply r.to_ntriples - else - raise error 500, "Invalid output format" - end + private + + def process_request(acronym_param, uri_param, output_format) + acronym = acronym_param + uri = URI.decode_www_form_component(uri_param) + + error 500, "INVALID URI" unless valid_url?(uri) + sub = LinkedData::Models::Ontology.find(acronym).first&.latest_submission + + error 500, "Ontology not found" unless sub + + r = Resource.new(sub.id, uri) + case output_format + when 'jsonld' + content_type 'application/json' + reply JSON.parse(r.to_json) + when 'json' + content_type 'application/json' + reply JSON.parse(r.to_json) + when 'xml' + content_type 'application/xml' + reply r.to_xml + when 'turtle' + content_type 'text/turtle' + reply r.to_turtle + when 'ntriples' + content_type 'application/n-triples' + reply r.to_ntriples + else + error 500, "Invalid output format" + end - end + end - def valid_url?(url) - uri = URI.parse(url) - uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) - rescue URI::InvalidURIError - false - end + def valid_url?(url) + uri = URI.parse(url) + uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS) + rescue URI::InvalidURIError + false end + end end \ No newline at end of file diff --git a/test/controllers/test_dereference_resource_controller.rb b/test/controllers/test_dereference_resource_controller.rb index a5a9651d..45f741d3 100644 --- a/test/controllers/test_dereference_resource_controller.rb +++ b/test/controllers/test_dereference_resource_controller.rb @@ -7,24 +7,22 @@ class TestDereferenceResourceController < TestCase def self.before_suite LinkedData::SampleData::Ontology.create_ontologies_and_submissions({ process_submission: true, + process_options: {process_rdf: true, extract_metadata: false}, acronym: 'INRAETHES', name: 'INRAETHES', file_path: './test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf', ont_count: 1, + ontology_format: 'SKOS', submission_count: 1 }) - ont = Ontology.find('INRAETHES-0').include(:acronym).first - sub = ont.latest_submission - sub.bring_remaining - sub.hasOntologyLanguage = LinkedData::Models::OntologyFormat.find('SKOS').first - sub.save - @@graph = "http://data.bioontology.org/ontologies/INRAETHES-0/submissions/1" - @@uri = "http://opendata.inrae.fr/thesaurusINRAE/c_6496" + + @@graph = "INRAETHES-0" + @@uri = CGI.escape("http://opendata.inrae.fr/thesaurusINRAE/c_6496") end def test_dereference_resource_controller_json - post "/dereference_resource", { acronym: @@graph, uri: @@uri , output_format: "json"} + get "/ontologies/#{@@graph}/resolve/#{@@uri}?output_format=json" assert last_response.ok? result = last_response.body @@ -58,7 +56,7 @@ def test_dereference_resource_controller_json end def test_dereference_resource_controller_xml - post "/dereference_resource", { acronym: @@graph, uri: @@uri , output_format: "xml"} + get "/ontologies/#{@@graph}/resolve/#{@@uri}?output_format=xml" assert last_response.ok? result = last_response.body @@ -85,7 +83,7 @@ def test_dereference_resource_controller_xml end def test_dereference_resource_controller_ntriples - post "/dereference_resource", { acronym: @@graph, uri: @@uri , output_format: "ntriples"} + get "/ontologies/#{@@graph}/resolve/#{@@uri}?output_format=ntriples" assert last_response.ok? result = last_response.body @@ -106,7 +104,7 @@ def test_dereference_resource_controller_ntriples end def test_dereference_resource_controller_turtle - post "/dereference_resource", { acronym: @@graph, uri: @@uri , output_format: "turtle"} + get "/ontologies/#{@@graph}/resolve/#{@@uri}?output_format=turtle" assert last_response.ok? result = last_response.body From d979ac837d4780a0de99dc89cc95b6ef1a228876 Mon Sep 17 00:00:00 2001 From: imadbourouche Date: Mon, 11 Mar 2024 13:44:06 +0100 Subject: [PATCH 11/12] Fix dereference resource tests expected resultsto handle parse triples --- Gemfile | 2 +- Gemfile.lock | 11 +- .../test_dereference_resource_controller.rb | 110 ++++++++++++++---- 3 files changed, 94 insertions(+), 29 deletions(-) diff --git a/Gemfile b/Gemfile index 823a2dbe..0ccc627d 100644 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,7 @@ gem 'sinatra-advanced-routes' gem 'sinatra-contrib', '~> 1.0' gem 'request_store' gem 'parallel' -gem 'json-ld', '~> 3.0.2' +gem 'json-ld' # Rack middleware diff --git a/Gemfile.lock b/Gemfile.lock index f7f9fe20..2a63f563 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,7 +11,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/goo.git - revision: 6c51346b6f150a69391794b7909b30592acbbe0e + revision: 3f8b1f0b62c4334306f9ed5cb7b17a1b645e7db3 branch: development specs: goo (0.0.2) @@ -57,7 +57,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git - revision: c9738faf4079fbbd36dcf9c45cc4f9525a9812b6 + revision: 337dce98ec27627d14a440ff2a6ed09483cdac12 branch: development specs: ontologies_linked_data (0.0.1) @@ -117,7 +117,7 @@ GEM bcrypt_pbkdf (1.1.0) bigdecimal (1.4.2) builder (3.2.4) - capistrano (3.18.0) + capistrano (3.18.1) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -404,7 +404,6 @@ GEM hashdiff (>= 0.4.0, < 2.0.0) PLATFORMS - x86_64-darwin-23 x86_64-linux DEPENDENCIES @@ -421,7 +420,7 @@ DEPENDENCIES ffi goo! haml (~> 5.2.2) - json-ld (~> 3.0.2) + json-ld json-schema (~> 2.0) minitest (~> 4.0) minitest-stub_any_instance @@ -463,4 +462,4 @@ DEPENDENCIES webmock BUNDLED WITH - 2.4.22 + 2.4.21 diff --git a/test/controllers/test_dereference_resource_controller.rb b/test/controllers/test_dereference_resource_controller.rb index 45f741d3..1671f49f 100644 --- a/test/controllers/test_dereference_resource_controller.rb +++ b/test/controllers/test_dereference_resource_controller.rb @@ -32,20 +32,45 @@ def test_dereference_resource_controller_json "ns0": "http://opendata.inrae.fr/thesaurusINRAE/", "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "owl": "http://www.w3.org/2002/07/owl#", - "skos": "http://www.w3.org/2004/02/skos/core#" + "skos": "http://www.w3.org/2004/02/skos/core#", + "metadata_def": "http://data.bioontology.org/metadata/def/" }, "@graph": [ { "@id": "ns0:c_6496", - "@type": ["owl:NamedIndividual", "skos:Concept"], - "skos:broader": {"@id": "ns0:c_a9d99f3a"}, - "skos:topConceptOf": {"@id": "ns0:mt_65"}, - "skos:inScheme": [{"@id": "ns0:thesaurusINRAE"}, {"@id": "ns0:mt_65"}], - "skos:prefLabel": {"@value": "altération de l'ADN", "@language": "fr"} + "@type": [ + "owl:NamedIndividual", + "skos:Concept" + ], + "skos:broader": { + "@id": "ns0:c_a9d99f3a" + }, + "skos:topConceptOf": { + "@id": "ns0:mt_65" + }, + "skos:inScheme": [ + { + "@id": "ns0:thesaurusINRAE" + }, + { + "@id": "ns0:mt_65" + } + ], + "skos:prefLabel": { + "@value": "altération de l'ADN", + "@language": "fr" + }, + "metadata_def:prefLabel": "c_6496", + "metadata_def:mappingSameURI": { + "@id": "ns0:c_6496" + }, + "metadata_def:mappingLoom": "c6496" }, { "@id": "ns0:mt_65", - "skos:hasTopConcept": {"@id": "ns0:c_6496"} + "skos:hasTopConcept": { + "@id": "ns0:c_6496" + } } ] } @@ -60,9 +85,10 @@ def test_dereference_resource_controller_xml assert last_response.ok? result = last_response.body - expected_result = <<-XML + + expected_result_1 = <<-XML - + @@ -70,16 +96,49 @@ def test_dereference_resource_controller_xml altération de l'ADN + c_6496 + + c6496 - + + + + + XML - a = result.gsub('\\"', '"').gsub(" ", "")[1..-2].split("\\n").reject(&:empty?) - b = expected_result.gsub(' ', '').split("\n").reject(&:empty?) - assert_equal b.sort , a.sort + expected_result_2 = <<-XML + + + + + + + + + altération de l'ADN + c_6496 + + c6496 + + + + + + + + + + XML + + a = result.gsub('\\"', '"').gsub(" ", "")[1..-2].split("\\n").reject(&:empty?) + b_1 = expected_result_1.gsub(' ', '').split("\n").reject(&:empty?) + b_2 = expected_result_2.gsub(' ', '').split("\n").reject(&:empty?) + + assert(b_1.sort == a.sort || b_2.sort == a.sort) end def test_dereference_resource_controller_ntriples @@ -95,11 +154,14 @@ def test_dereference_resource_controller_ntriples . . "alt\\\\u00E9rationdel'ADN"@fr . + "c_6496" . + . + "c6496" . . + . NTRIPLES a = result.gsub('\\"', '"').gsub(' ', '')[1..-2].split("\\n").reject(&:empty?) b = expected_result.gsub(' ', '').split("\n").reject(&:empty?) - assert_equal b.sort, a.sort end @@ -113,16 +175,20 @@ def test_dereference_resource_controller_turtle @prefix ns0: . @prefix owl: . @prefix skos: . - + @prefix metadata_def: . + ns0:c_6496 - a owl:NamedIndividual, skos:Concept ; - skos:broader ns0:c_a9d99f3a ; - skos:inScheme ns0:mt_65, ns0:thesaurusINRAE ; - skos:prefLabel "altération de l'ADN"@fr ; - skos:topConceptOf ns0:mt_65 . - + metadata_def:mappingLoom "c6496" ; + metadata_def:mappingSameURI ns0:c_6496 ; + metadata_def:prefLabel "c_6496" ; + a owl:NamedIndividual, skos:Concept ; + skos:broader ns0:c_a9d99f3a ; + skos:inScheme ns0:mt_65, ns0:thesaurusINRAE ; + skos:prefLabel "altération de l'ADN"@fr ; + skos:topConceptOf ns0:mt_65 . + ns0:mt_65 - skos:hasTopConcept ns0:c_6496 . + skos:hasTopConcept ns0:c_6496 . TURTLE a = result.gsub('\\"', '"').gsub(' ', '')[1..-2].split("\\n").reject(&:empty?) b = expected_result.gsub(' ', '').split("\n").reject(&:empty?) From 544cea6f1a79e1af69bce51b293b67eee4d64bb9 Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Tue, 12 Mar 2024 12:21:41 +0100 Subject: [PATCH 12/12] fix xml serialization test for AG and Gb by cleaning the xml string --- Gemfile.lock | 7 +- .../test_dereference_resource_controller.rb | 200 ++++++++---------- 2 files changed, 93 insertions(+), 114 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2a63f563..d210ac10 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -197,6 +197,7 @@ GEM google-cloud-env (2.1.1) faraday (>= 1.0, < 3.a) google-cloud-errors (1.4.0) + google-protobuf (3.25.3-x86_64-darwin) google-protobuf (3.25.3-x86_64-linux) googleapis-common-protos (1.5.0) google-protobuf (~> 3.18) @@ -211,6 +212,9 @@ GEM multi_json (~> 1.11) os (>= 0.9, < 2.0) signet (>= 0.16, < 2.a) + grpc (1.62.0-x86_64-darwin) + google-protobuf (~> 3.25) + googleapis-common-protos-types (~> 1.0) grpc (1.62.0-x86_64-linux) google-protobuf (~> 3.25) googleapis-common-protos-types (~> 1.0) @@ -235,7 +239,7 @@ GEM jwt (2.8.1) base64 kgio (2.11.4) - libxml-ruby (5.0.2) + libxml-ruby (5.0.3) link_header (0.0.8) logger (1.6.0) macaddr (1.7.2) @@ -404,6 +408,7 @@ GEM hashdiff (>= 0.4.0, < 2.0.0) PLATFORMS + x86_64-darwin-23 x86_64-linux DEPENDENCIES diff --git a/test/controllers/test_dereference_resource_controller.rb b/test/controllers/test_dereference_resource_controller.rb index 1671f49f..4fb615ff 100644 --- a/test/controllers/test_dereference_resource_controller.rb +++ b/test/controllers/test_dereference_resource_controller.rb @@ -1,39 +1,36 @@ require_relative '../test_case' require 'rexml/document' - class TestDereferenceResourceController < TestCase - def self.before_suite - LinkedData::SampleData::Ontology.create_ontologies_and_submissions({ - process_submission: true, - process_options: {process_rdf: true, extract_metadata: false}, - acronym: 'INRAETHES', - name: 'INRAETHES', - file_path: './test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf', - ont_count: 1, - ontology_format: 'SKOS', - submission_count: 1 - }) - - @@graph = "INRAETHES-0" - @@uri = CGI.escape("http://opendata.inrae.fr/thesaurusINRAE/c_6496") - end - - - def test_dereference_resource_controller_json - get "/ontologies/#{@@graph}/resolve/#{@@uri}?output_format=json" - assert last_response.ok? - - result = last_response.body - expected_result = <<-JSON + def self.before_suite + LinkedData::SampleData::Ontology.create_ontologies_and_submissions({ + process_submission: true, + process_options: { process_rdf: true, extract_metadata: false, generate_missing_labels: false}, + acronym: 'INRAETHESDEREF', + name: 'INRAETHES', + file_path: './test/data/ontology_files/thesaurusINRAE_nouv_structure.rdf', + ont_count: 1, + ontology_format: 'SKOS', + submission_count: 1 + }) + + @@graph = "INRAETHESDEREF-0" + @@uri = CGI.escape("http://opendata.inrae.fr/thesaurusINRAE/c_6496") + end + + def test_dereference_resource_controller_json + get "/ontologies/#{@@graph}/resolve/#{@@uri}?output_format=json" + assert last_response.ok? + + result = last_response.body + expected_result = <<-JSON { "@context": { "ns0": "http://opendata.inrae.fr/thesaurusINRAE/", "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "owl": "http://www.w3.org/2002/07/owl#", - "skos": "http://www.w3.org/2004/02/skos/core#", - "metadata_def": "http://data.bioontology.org/metadata/def/" + "skos": "http://www.w3.org/2004/02/skos/core#" }, "@graph": [ { @@ -59,12 +56,7 @@ def test_dereference_resource_controller_json "skos:prefLabel": { "@value": "altération de l'ADN", "@language": "fr" - }, - "metadata_def:prefLabel": "c_6496", - "metadata_def:mappingSameURI": { - "@id": "ns0:c_6496" - }, - "metadata_def:mappingLoom": "c6496" + } }, { "@id": "ns0:mt_65", @@ -74,21 +66,21 @@ def test_dereference_resource_controller_json } ] } - JSON - a = sort_nested_hash(JSON.parse(result)) - b = sort_nested_hash(JSON.parse(expected_result)) - assert_equal b, a - end + JSON + a = sort_nested_hash(JSON.parse(result)) + b = sort_nested_hash(JSON.parse(expected_result)) + assert_equal b, a + end - def test_dereference_resource_controller_xml - get "/ontologies/#{@@graph}/resolve/#{@@uri}?output_format=xml" - assert last_response.ok? + def test_dereference_resource_controller_xml + get "/ontologies/#{@@graph}/resolve/#{@@uri}?output_format=xml" + assert last_response.ok? - result = last_response.body + result = last_response.body - expected_result_1 = <<-XML + expected_result_1 = <<-XML - + @@ -96,57 +88,47 @@ def test_dereference_resource_controller_xml altération de l'ADN - c_6496 - - c6496 - - - - - + - XML + XML - expected_result_2 = <<-XML + expected_result_2 = <<-XML - + - - altération de l'ADN - c_6496 - - c6496 + + - - - - - + XML - a = result.gsub('\\"', '"').gsub(" ", "")[1..-2].split("\\n").reject(&:empty?) - b_1 = expected_result_1.gsub(' ', '').split("\n").reject(&:empty?) - b_2 = expected_result_2.gsub(' ', '').split("\n").reject(&:empty?) - assert(b_1.sort == a.sort || b_2.sort == a.sort) - end + clean_xml = -> (x) { x.strip.gsub('/>', '').gsub('', '').split(' ').reject(&:empty?)} + - def test_dereference_resource_controller_ntriples - get "/ontologies/#{@@graph}/resolve/#{@@uri}?output_format=ntriples" - assert last_response.ok? + a = result.gsub('\\"', '"')[1..-2].split("\\n").map{|x| clean_xml.call(x)}.flatten + b_1 = expected_result_1.split("\n").map{|x| clean_xml.call(x)}.flatten + b_2 = expected_result_2.split("\n").map{|x| clean_xml.call(x)}.flatten + + assert_includes [b_1.sort, b_2.sort], a.sort + end + + def test_dereference_resource_controller_ntriples + get "/ontologies/#{@@graph}/resolve/#{@@uri}?output_format=ntriples" + assert last_response.ok? - result = last_response.body - expected_result = <<-NTRIPLES + result = last_response.body + expected_result = <<-NTRIPLES . . . @@ -154,33 +136,25 @@ def test_dereference_resource_controller_ntriples . . "alt\\\\u00E9rationdel'ADN"@fr . - "c_6496" . - . - "c6496" . . - . - NTRIPLES - a = result.gsub('\\"', '"').gsub(' ', '')[1..-2].split("\\n").reject(&:empty?) - b = expected_result.gsub(' ', '').split("\n").reject(&:empty?) - assert_equal b.sort, a.sort - end - - def test_dereference_resource_controller_turtle - get "/ontologies/#{@@graph}/resolve/#{@@uri}?output_format=turtle" - assert last_response.ok? - - result = last_response.body - expected_result = <<-TURTLE + NTRIPLES + a = result.gsub('\\"', '"').gsub(' ', '')[1..-2].split("\\n").reject(&:empty?) + b = expected_result.gsub(' ', '').split("\n").reject(&:empty?) + assert_equal b.sort, a.sort + end + + def test_dereference_resource_controller_turtle + get "/ontologies/#{@@graph}/resolve/#{@@uri}?output_format=turtle" + assert last_response.ok? + + result = last_response.body + expected_result = <<-TURTLE @prefix rdf: . @prefix ns0: . @prefix owl: . @prefix skos: . - @prefix metadata_def: . ns0:c_6496 - metadata_def:mappingLoom "c6496" ; - metadata_def:mappingSameURI ns0:c_6496 ; - metadata_def:prefLabel "c_6496" ; a owl:NamedIndividual, skos:Concept ; skos:broader ns0:c_a9d99f3a ; skos:inScheme ns0:mt_65, ns0:thesaurusINRAE ; @@ -189,29 +163,29 @@ def test_dereference_resource_controller_turtle ns0:mt_65 skos:hasTopConcept ns0:c_6496 . - TURTLE - a = result.gsub('\\"', '"').gsub(' ', '')[1..-2].split("\\n").reject(&:empty?) - b = expected_result.gsub(' ', '').split("\n").reject(&:empty?) + TURTLE + a = result.gsub('\\"', '"').gsub(' ', '')[1..-2].split("\\n").reject(&:empty?) + b = expected_result.gsub(' ', '').split("\n").reject(&:empty?) - assert_equal b.sort, a.sort - end + assert_equal b.sort, a.sort + end - private + private - def sort_nested_hash(hash) - sorted_hash = {} - - hash.each do |key, value| - if value.is_a?(Hash) - sorted_hash[key] = sort_nested_hash(value) - elsif value.is_a?(Array) - sorted_hash[key] = value.map { |item| item.is_a?(Hash) ? sort_nested_hash(item) : item }.sort_by { |item| item.to_s } - else - sorted_hash[key] = value - end + def sort_nested_hash(hash) + sorted_hash = {} + + hash.each do |key, value| + if value.is_a?(Hash) + sorted_hash[key] = sort_nested_hash(value) + elsif value.is_a?(Array) + sorted_hash[key] = value.map { |item| item.is_a?(Hash) ? sort_nested_hash(item) : item }.sort_by { |item| item.to_s } + else + sorted_hash[key] = value end - - sorted_hash.sort.to_h end + sorted_hash.sort.to_h + end + end \ No newline at end of file