From 7136996340d1dd86582152b60ed01ac4aef16ff2 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Fri, 26 Jul 2024 00:12:25 +0200 Subject: [PATCH 1/2] implement in ontology property endpoint the display all attributes --- Gemfile | 2 +- Gemfile.lock | 34 ++++++++++++++-------------- controllers/properties_controller.rb | 4 +++- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Gemfile b/Gemfile index adaeb43a..ed7b82b9 100644 --- a/Gemfile +++ b/Gemfile @@ -51,7 +51,7 @@ gem 'ncbo_cron', git: 'https://github.com/ontoportal-lirmm/ncbo_cron.git', branc gem 'ncbo_ontology_recommender', git: 'https://github.com/ncbo/ncbo_ontology_recommender.git', branch: 'master' gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'development' gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'development' -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/add-range-domain-for-properties' 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 ccb0b5ee..853cb3da 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,7 +11,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/goo.git - revision: b2a635fb1e8206e6e3010be4dbe033b47eb58481 + revision: a95245b8c964431505ca6315907440996c59a00d branch: development specs: goo (0.0.2) @@ -40,7 +40,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ncbo_cron.git - revision: 6bb53a13f514a60513afe25e37c5c69475140452 + revision: fabd04ef4fa37989d526fc6a7aa1e98830008dae branch: master specs: ncbo_cron (0.0.1) @@ -57,8 +57,8 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git - revision: fd78d689dac4a7393e20a36ac930c6c9d191a619 - branch: development + revision: d465743e6ceafde3214b1ff06bc32a1ae683ed2e + branch: feature/add-range-domain-for-properties specs: ontologies_linked_data (0.0.1) activesupport @@ -117,7 +117,7 @@ GEM bcrypt_pbkdf (1.1.1-x86_64-darwin) bigdecimal (1.4.2) builder (3.3.0) - capistrano (3.19.0) + capistrano (3.19.1) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -139,7 +139,7 @@ GEM dante (0.2.0) date (3.3.4) declarative (0.0.20) - docile (1.4.0) + docile (1.4.1) domain_name (0.6.20240107) ed25519 (1.3.0) faraday (1.10.3) @@ -160,7 +160,7 @@ GEM faraday-httpclient (1.0.1) faraday-multipart (1.0.4) multipart-post (~> 2) - faraday-net_http (1.0.1) + faraday-net_http (1.0.2) faraday-net_http_persistent (1.2.0) faraday-patron (1.0.0) faraday-rack (1.0.0) @@ -214,14 +214,14 @@ GEM multi_json (~> 1.11) os (>= 0.9, < 2.0) signet (>= 0.16, < 2.a) - grpc (1.64.0) - google-protobuf (~> 3.25) + grpc (1.65.1) + google-protobuf (>= 3.25, < 5.0) googleapis-common-protos-types (~> 1.0) - grpc (1.64.0-x86_64-darwin) - google-protobuf (~> 3.25) + grpc (1.65.1-x86_64-darwin) + google-protobuf (>= 3.25, < 5.0) googleapis-common-protos-types (~> 1.0) - grpc (1.64.0-x86_64-linux) - google-protobuf (~> 3.25) + grpc (1.65.1-x86_64-linux) + google-protobuf (>= 3.25, < 5.0) googleapis-common-protos-types (~> 1.0) haml (5.2.2) temple (>= 0.8.0) @@ -256,7 +256,7 @@ GEM method_source (1.1.0) mime-types (3.5.2) mime-types-data (~> 3.2015) - mime-types-data (3.2024.0604) + mime-types-data (3.2024.0702) mini_mime (1.1.5) minitest (4.7.5) minitest-stub_any_instance (1.0.3) @@ -281,7 +281,7 @@ GEM net-protocol net-ssh (7.2.3) netrc (0.11.0) - newrelic_rpm (9.11.0) + newrelic_rpm (9.12.0) oj (3.16.1) omni_logger (0.1.4) logger @@ -349,7 +349,7 @@ GEM mime-types (>= 1.16, < 4.0) netrc (~> 0.8) retriable (3.1.2) - rexml (3.3.1) + rexml (3.3.2) strscan rsolr (2.6.0) builder (>= 2.1.2) @@ -394,7 +394,7 @@ GEM strscan (3.1.0) systemu (2.6.5) temple (0.10.3) - tilt (2.3.0) + tilt (2.4.0) timeout (0.4.1) trailblazer-option (0.1.2) tzinfo (2.0.6) diff --git a/controllers/properties_controller.rb b/controllers/properties_controller.rb index f98e9016..45267fe1 100644 --- a/controllers/properties_controller.rb +++ b/controllers/properties_controller.rb @@ -24,7 +24,9 @@ class PropertiesController < ApplicationController get '/:property' do prop = params[:property] ont, submission = get_ontology_and_submission - p = ont.property(prop, submission) + bring_unmapped = bring_unmapped?(includes_param) + + p = ont.property(prop, submission, display_all_attributes: bring_unmapped) error 404, "Property #{prop} not found in ontology #{ont.id.to_s}" if p.nil? reply 200, p end From 04946f08609af639da89371c05d6a7b08e99cfd5 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Fri, 26 Jul 2024 00:13:01 +0200 Subject: [PATCH 2/2] add a new unit test for the ontology property display all option --- Gemfile | 2 +- Gemfile.lock | 4 +- .../controllers/test_properties_controller.rb | 57 ++++++++++++------- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/Gemfile b/Gemfile index ed7b82b9..adaeb43a 100644 --- a/Gemfile +++ b/Gemfile @@ -51,7 +51,7 @@ gem 'ncbo_cron', git: 'https://github.com/ontoportal-lirmm/ncbo_cron.git', branc gem 'ncbo_ontology_recommender', git: 'https://github.com/ncbo/ncbo_ontology_recommender.git', branch: 'master' gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'development' gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'development' -gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'feature/add-range-domain-for-properties' +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 index 853cb3da..43616d10 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -57,8 +57,8 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git - revision: d465743e6ceafde3214b1ff06bc32a1ae683ed2e - branch: feature/add-range-domain-for-properties + revision: c4dbcc14a3eb75343e597679ea4532ba53785b8f + branch: development specs: ontologies_linked_data (0.0.1) activesupport diff --git a/test/controllers/test_properties_controller.rb b/test/controllers/test_properties_controller.rb index 96879083..d7f35d78 100644 --- a/test/controllers/test_properties_controller.rb +++ b/test/controllers/test_properties_controller.rb @@ -4,24 +4,24 @@ class TestPropertiesController < TestCase def self.before_suite count, acronyms, bro = LinkedData::SampleData::Ontology.create_ontologies_and_submissions({ - process_submission: true, - process_options:{process_rdf: true, extract_metadata: false}, - acronym: "BROSEARCHTEST", - name: "BRO Search Test", - file_path: "./test/data/ontology_files/BRO_v3.2.owl", - ont_count: 1, - submission_count: 1, - ontology_type: "VALUE_SET_COLLECTION" + process_submission: true, + process_options: { process_rdf: true, extract_metadata: false }, + acronym: "BROSEARCHTEST", + name: "BRO Search Test", + file_path: "./test/data/ontology_files/BRO_v3.2.owl", + ont_count: 1, + submission_count: 1, + ontology_type: "VALUE_SET_COLLECTION" }) count, acronyms, mccl = LinkedData::SampleData::Ontology.create_ontologies_and_submissions({ - process_submission: true, - process_options:{process_rdf: true, extract_metadata: true}, - acronym: "MCCLSEARCHTEST", - name: "MCCL Search Test", - file_path: "./test/data/ontology_files/CellLine_OWL_BioPortal_v1.0.owl", - ont_count: 1, - submission_count: 1 + process_submission: true, + process_options: { process_rdf: true, extract_metadata: true }, + acronym: "MCCLSEARCHTEST", + name: "MCCL Search Test", + file_path: "./test/data/ontology_files/CellLine_OWL_BioPortal_v1.0.owl", + ont_count: 1, + submission_count: 1 }) @@ontologies = bro.concat(mccl) @@acronyms = @@ontologies.map { |ont| ont.bring_remaining; ont.acronym } @@ -47,14 +47,33 @@ def test_single_property get "/ontologies/#{@@acronyms.first}/properties/http%3A%2F%2Fbioontology.org%2Fontologies%2FBiomedicalResourceOntology.owl%23Originator" assert last_response.ok? results = MultiJson.load(last_response.body) + assert results.is_a?(Hash) assert_equal ["Originator"], results["label"] assert_equal "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Originator", results["@id"] + assert results.key?('range') + assert results.key?('domain') get "/ontologies/#{@@acronyms.first}/properties/http%3A%2F%2Fbioontology.org%2Fontologies%2FBiomedicalResourceOntology.owl%23DummyProp" assert_equal 404, last_response.status end + def test_single_property_all_attributes + get "/ontologies/#{@@acronyms.first}/properties/http%3A%2F%2Fbioontology.org%2Fontologies%2FBiomedicalResourceOntology.owl%23Originator?display=all" + assert last_response.ok? + results = MultiJson.load(last_response.body) + assert_equal ["Originator"], results["label"] + assert results.key?('range') + assert results.key?('domain') + assert_equal results["properties"], { "http://www.w3.org/2000/01/rdf-schema#comment" => ["Originator of a class"], + "http://www.w3.org/2004/02/skos/core#prefLabel" => ["Originator"], + "http://data.bioontology.org/metadata/def/prefLabel" => ["Originator"], + "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" => ["http://www.w3.org/2002/07/owl#DatatypeProperty"], + "http://www.w3.org/2000/01/rdf-schema#domain" => ["http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Algorithm"], + "http://www.w3.org/2000/01/rdf-schema#label" => ["Originator"], + "http://www.w3.org/2004/02/skos/core#definition" => ["Originator of a class"] } + end + def test_property_roots get "/ontologies/#{@@acronyms.first}/properties/roots" assert last_response.ok? @@ -66,10 +85,10 @@ def test_property_roots assert_includes [18, 13], opr.length # count datatype properties dpr = pr.select { |p| p["@type"] == "http://www.w3.org/2002/07/owl#DatatypeProperty" } - assert_includes [32,31], dpr.length + assert_includes [32, 31], dpr.length # count annotation properties apr = pr.select { |p| p["@type"] == "http://www.w3.org/2002/07/owl#AnnotationProperty" } - assert_includes [12,8], apr.length + assert_includes [12, 8], apr.length # check for non-root properties assert_empty pr.select { |p| ["http://www.w3.org/2004/02/skos/core#broaderTransitive", @@ -174,7 +193,7 @@ def test_property_descendants dn = MultiJson.load(last_response.body) assert_equal 2, dn.length assert_equal ["http://www.semanticweb.org/ontologies/2009/9/12/Ontology1255323704656.owl#overExpress", - "http://www.semanticweb.org/ontologies/2009/9/12/Ontology1255323704656.owl#underExpress"].sort, dn.map { |d| d["@id"] }.sort + "http://www.semanticweb.org/ontologies/2009/9/12/Ontology1255323704656.owl#underExpress"].sort, dn.map { |d| d["@id"] }.sort end def test_property_parents @@ -207,7 +226,7 @@ def test_property_children assert_empty ch get "/ontologies/#{@@acronyms.first}/properties/http%3A%2F%2Fwww.w3.org%2F2004%2F02%2Fskos%2Fcore%23semanticRelation" - return unless last_response.ok? #depending if owlapi import SKOS + return unless last_response.ok? # depending if owlapi import SKOS get "/ontologies/#{@@acronyms.first}/properties/http%3A%2F%2Fwww.w3.org%2F2004%2F02%2Fskos%2Fcore%23semanticRelation/children" assert last_response.ok?