Skip to content

Commit ae7774b

Browse files
Feat: Add sampleQueries to ontology and catalog models (#231)
* Add sampleQueries to ontology and catalog models * Fix test * Fix test
1 parent 46982d5 commit ae7774b

4 files changed

Lines changed: 47 additions & 3 deletions

File tree

lib/ontologies_linked_data/models/mod/semantic_artefact_catalog.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class SemanticArtefactCatalog < LinkedData::Models::ModBase
4040
attribute :bugDatabase, namespace: :doap, enforce: [:string]
4141
attribute :relation, namespace: :dcterms, enforce: [:string]
4242
attribute :hasPolicy, namespace: :mod, enforce: [:string]
43+
attribute :sampleQueries, namespace: :mod, enforce: [:list, :string]
4344

4445
attribute :created, namespace: :dcterms, enforce: [:date]
4546
attribute :curatedOn, namespace: :pav, enforce: [:date]
@@ -173,7 +174,7 @@ class SemanticArtefactCatalog < LinkedData::Models::ModBase
173174
serialize_default :acronym, :title, :color, :description, :logo,:identifier, :status, :language, :type, :accessRights, :license, :rightsHolder,
174175
:landingPage, :keyword, :bibliographicCitation, :created, :modified , :contactPoint, :creator, :contributor,
175176
:publisher, :subject, :coverage, :createdWith, :accrualMethod, :accrualPeriodicity, :wasGeneratedBy, :accessURL,
176-
:numberOfArtefacts, :federated_portals, :fundedBy
177+
:numberOfArtefacts, :federated_portals, :fundedBy, :sampleQueries
177178

178179
embed :rightsHolder, :contactPoint, :creator, :contributor, :curatedBy, :translator, :publisher, :endorsedBy
179180

lib/ontologies_linked_data/models/ontology.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class OntologyAnalyticsError < StandardError; end
4848
attribute :flat, enforce: [:boolean]
4949
attribute :hasDomain, namespace: :omv, enforce: [:list, :category]
5050
attribute :summaryOnly, enforce: [:boolean]
51+
attribute :sampleQueries, namespace: :mod, enforce: [:list, :string]
5152

5253
attribute :acl, enforce: [:list, :user]
5354

@@ -56,7 +57,7 @@ class OntologyAnalyticsError < StandardError; end
5657
attribute :ontologyType, enforce: [:ontology_type], default: lambda { |record| LinkedData::Models::OntologyType.find("ONTOLOGY").include(:code).first }
5758

5859
# Hypermedia settings
59-
serialize_default :administeredBy, :acronym, :name, :summaryOnly, :flat, :ontologyType, :group, :hasDomain, :viewingRestriction, :viewOf, :views
60+
serialize_default :administeredBy, :acronym, :name, :summaryOnly, :flat, :ontologyType, :group, :hasDomain, :viewingRestriction, :viewOf, :views, :sampleQueries
6061
links_load :acronym
6162
link_to LinkedData::Hypermedia::Link.new("submissions", lambda {|s| "ontologies/#{s.acronym}/submissions"}, LinkedData::Models::OntologySubmission.uri_type),
6263
LinkedData::Hypermedia::Link.new("properties", lambda {|s| "ontologies/#{s.acronym}/properties"}, "#{Goo.namespaces[:metadata].to_s}Property"),

test/models/mod/test_artefact_catalog.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_create_artefact_catalog
2525
description: "Welcome to OntoPortal Appliance, your ontology repository for your ontologies",
2626
status: "alpha",
2727
accessRights: "public",
28+
sampleQueries: [],
2829
logo: "https://ontoportal.org/images/logo.png",
2930
license: "https://opensource.org/licenses/BSD-2-Clause",
3031
federated_portals: [
@@ -56,7 +57,7 @@ def test_goo_attrs_to_load
5657
default_attrs = LinkedData::Models::SemanticArtefactCatalog.goo_attrs_to_load([])
5758
assert_equal [:acronym, :title, :color, :description, :logo, :identifier, :status, :language, :type, :accessRights, :license, :rightsHolder,
5859
:landingPage, :keyword, :bibliographicCitation, :created, :modified, :contactPoint, :creator, :contributor, :publisher, :subject,
59-
:coverage, :createdWith, :accrualMethod, :accrualPeriodicity, :wasGeneratedBy, :accessURL, :numberOfArtefacts, :federated_portals, :fundedBy].sort, (default_attrs.flat_map { |e| e.is_a?(Hash) ? e.keys : e }).sort
60+
:coverage, :createdWith, :accrualMethod, :accrualPeriodicity, :wasGeneratedBy, :accessURL, :numberOfArtefacts, :federated_portals, :fundedBy, :sampleQueries].sort, (default_attrs.flat_map { |e| e.is_a?(Hash) ? e.keys : e }).sort
6061

6162
specified_attrs = LinkedData::Models::SemanticArtefactCatalog.goo_attrs_to_load([:acronym, :title, :keyword, :featureList])
6263
assert_equal [:acronym, :title, :keyword, :featureList], specified_attrs
@@ -74,4 +75,20 @@ def test_bring_all_attrs
7475
sac.bring(*all_attrs_to_bring)
7576
assert_equal (all_attrs_to_bring.flat_map { |e| e.is_a?(Hash) ? e.keys : e }).sort, (sac.loaded_attributes.to_a + [:type]).sort
7677
end
78+
79+
def test_semantic_artefact_catalog_sample_queries
80+
catalog = LinkedData::Models::SemanticArtefactCatalog.new
81+
catalog.acronym = "TEST-CAT-SQ"
82+
catalog.title = "Test Catalog Sample Queries"
83+
queries = ["SELECT * WHERE {\n ?s ?p ?o \n} LIMIT 5"]
84+
catalog.sampleQueries = queries
85+
assert_equal queries, catalog.sampleQueries
86+
if catalog.valid?
87+
catalog.save
88+
saved_catalog = LinkedData::Models::SemanticArtefactCatalog.find(catalog.id).first
89+
saved_catalog.bring(*LinkedData::Models::SemanticArtefactCatalog.goo_attrs_to_load([]))
90+
assert_equal queries, saved_catalog.sampleQueries
91+
catalog.delete
92+
end
93+
end
7794
end

test/models/test_ontology.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,4 +496,29 @@ def test_ontology_bring_remaining
496496
assert_equal "test 1", otest.name
497497
end
498498

499+
def test_ontology_sample_queries
500+
user = LinkedData::Models::User.new(username: "test_user_sq", email: "test_sq@example.org")
501+
user.passwordHash = "test_password"
502+
user.save
503+
504+
ontology = LinkedData::Models::Ontology.new
505+
ontology.acronym = "TEST-ONT-SQ"
506+
ontology.name = "Test Ontology Sample Queries"
507+
ontology.administeredBy = [user]
508+
queries = [
509+
"SELECT * WHERE {\n ?s ?p ?o \n} LIMIT 10",
510+
"SELECT ?s \nWHERE { \n?s a owl:Class \n}"
511+
]
512+
ontology.sampleQueries = queries
513+
514+
assert ontology.valid?
515+
ontology.save
516+
517+
saved_ontology = LinkedData::Models::Ontology.find(ontology.id).include(:sampleQueries).first
518+
assert_equal queries.sort, saved_ontology.sampleQueries.sort
519+
520+
ontology.delete
521+
user.delete
522+
end
523+
499524
end

0 commit comments

Comments
 (0)