From 82ded7330b679ba122e5213378a16d1f96116aec Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Fri, 23 Aug 2024 13:01:12 +0200 Subject: [PATCH] Feature: Add unmapped, range and domain attributes for properties endpoints (#89) * implement in ontology property endpoint the display all attributes * add a new unit test for the ontology property display all option --- Gemfile.lock | 40 ++++++------- controllers/properties_controller.rb | 4 +- .../controllers/test_properties_controller.rb | 57 ++++++++++++------- 3 files changed, 61 insertions(+), 40 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 311e26ee..70183e15 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,7 +40,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ncbo_cron.git - revision: fabd04ef4fa37989d526fc6a7aa1e98830008dae + revision: bed0ff08408ad1241db3513992ad025a253eeef0 branch: master specs: ncbo_cron (0.0.1) @@ -57,7 +57,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git - revision: 552fbe5faed5bb195396251066ef0e7b930939a0 + revision: 651d2f4226004c2311120e900a936101ee509865 branch: development specs: ontologies_linked_data (0.0.1) @@ -108,7 +108,7 @@ GEM multi_json (~> 1.0) addressable (2.8.7) public_suffix (>= 2.0.2, < 7.0) - airbrussh (1.5.2) + airbrussh (1.5.3) sshkit (>= 1.6.1, != 1.7.0) backports (3.25.0) base64 (0.2.0) @@ -129,7 +129,7 @@ GEM capistrano (~> 3.1) sshkit (~> 1.3) coderay (1.1.3) - concurrent-ruby (1.3.3) + concurrent-ruby (1.3.4) connection_pool (2.4.1) crack (1.0.0) bigdecimal @@ -175,10 +175,10 @@ GEM grpc (~> 1.59) get_process_mem (0.2.7) ffi (~> 1.0) - google-analytics-data (0.6.0) + google-analytics-data (0.6.1) google-analytics-data-v1beta (>= 0.11, < 2.a) google-cloud-core (~> 1.6) - google-analytics-data-v1beta (0.13.0) + google-analytics-data-v1beta (0.13.1) gapic-common (>= 0.21.1, < 2.a) google-cloud-errors (~> 1.0) google-apis-analytics_v3 (0.16.0) @@ -220,7 +220,7 @@ GEM hashdiff (1.1.1) htmlentities (4.3.4) http-accept (1.7.0) - http-cookie (1.0.6) + http-cookie (1.0.7) domain_name (~> 0.5) httpclient (2.8.3) i18n (0.9.5) @@ -236,7 +236,7 @@ GEM kgio (2.11.4) libxml-ruby (5.0.3) link_header (0.0.8) - logger (1.6.0) + logger (1.6.1) macaddr (1.7.2) systemu (~> 2.6.5) mail (2.8.1) @@ -247,7 +247,7 @@ GEM method_source (1.1.0) mime-types (3.5.2) mime-types-data (~> 3.2015) - mime-types-data (3.2024.0702) + mime-types-data (3.2024.0903) mini_mime (1.1.5) minitest (4.7.5) minitest-stub_any_instance (1.0.3) @@ -256,9 +256,9 @@ GEM multi_json (1.15.0) multipart-post (2.4.1) mutex_m (0.2.0) - net-http-persistent (4.0.2) + net-http-persistent (4.0.4) connection_pool (~> 2.2) - net-imap (0.4.14) + net-imap (0.4.16) date net-protocol net-pop (0.1.2) @@ -273,12 +273,13 @@ GEM net-protocol net-ssh (7.2.3) netrc (0.11.0) - newrelic_rpm (9.12.0) + newrelic_rpm (9.13.0) oj (3.16.1) omni_logger (0.1.4) logger os (1.1.4) - parallel (1.25.1) + ostruct (0.6.0) + parallel (1.26.3) parseconfig (1.1.2) pony (1.13.1) mail (>= 2.0) @@ -320,14 +321,14 @@ GEM rdf (~> 3.2) rexml (~> 3.2) redcarpet (3.6.0) - redis (5.2.0) + redis (5.3.0) redis-client (>= 0.22.0) redis-client (0.22.2) connection_pool redis-rack-cache (2.2.1) rack-cache (>= 1.10, < 2) redis-store (>= 1.6, < 2) - redis-store (1.10.0) + redis-store (1.11.0) redis (>= 4, < 6) representable (3.2.0) declarative (< 0.1.0) @@ -341,8 +342,7 @@ GEM mime-types (>= 1.16, < 4.0) netrc (~> 0.8) retriable (3.1.2) - rexml (3.3.4) - strscan + rexml (3.3.7) rsolr (2.6.0) builder (>= 2.1.2) faraday (>= 0.9, < 3, != 2.0.0) @@ -363,7 +363,7 @@ GEM simplecov-cobertura (2.1.0) rexml simplecov (~> 0.19) - simplecov-html (0.12.3) + simplecov-html (0.13.1) simplecov_json_formatter (0.1.4) sinatra (1.4.8) rack (~> 1.5) @@ -378,12 +378,12 @@ GEM rack-test sinatra (~> 1.4.0) tilt (>= 1.3, < 3) - sshkit (1.23.0) + sshkit (1.23.1) base64 net-scp (>= 1.1.2) net-sftp (>= 2.1.2) net-ssh (>= 2.8.0) - strscan (3.1.0) + ostruct systemu (2.6.5) temple (0.10.3) tilt (2.4.0) diff --git a/controllers/properties_controller.rb b/controllers/properties_controller.rb index d32180d5..c20bc532 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, display_all_attributes: false) + 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 diff --git a/test/controllers/test_properties_controller.rb b/test/controllers/test_properties_controller.rb index 96879083..bbc64ba5 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"] + assert_equal results["properties"]["http://www.w3.org/2004/02/skos/core#prefLabel"], ["Originator"] + assert_equal results["properties"]["http://www.w3.org/1999/02/22-rdf-syntax-ns#type"], ["http://www.w3.org/2002/07/owl#DatatypeProperty"] + assert_equal results["properties"]["http://www.w3.org/2000/01/rdf-schema#domain"], ["http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Algorithm"] + assert_equal results["properties"]["http://www.w3.org/2000/01/rdf-schema#label"], ["Originator"] + + 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?