Skip to content

Commit

Permalink
add the serialize_defaults if attributes to load set to :all and some…
Browse files Browse the repository at this point in the history
… refactor
  • Loading branch information
syphax-bouazzouni committed May 6, 2024
1 parent 5391eb6 commit 37f74d3
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.bundle/
*.swp
*.gemtags
.bundle
Expand Down
60 changes: 41 additions & 19 deletions lib/ontologies_linked_data/config/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,13 @@ def config(&block)
yield @settings, overide_connect_goo if block_given?

# Check to make sure url prefix has trailing slash
@settings.rest_url_prefix = @settings.rest_url_prefix + '/' unless @settings.rest_url_prefix[-1].eql?('/')
@settings.rest_url_prefix = "#{@settings.rest_url_prefix}/" unless @settings.rest_url_prefix[-1].eql?('/')

puts "(LD) >> Using rdf store #{@settings.goo_host}:#{@settings.goo_port}#{@settings.goo_path_query}"
puts "(LD) >> Using term search server at #{@settings.search_server_url}"
puts "(LD) >> Using property search server at #{@settings.property_search_server_url}"
puts '(LD) >> Using HTTP Redis instance at '+
"#{@settings.http_redis_host}:#{@settings.http_redis_port}"
puts '(LD) >> Using Goo Redis instance at '+
"#{@settings.goo_redis_host}:#{@settings.goo_redis_port}"
puts "(LD) >> Using HTTP Redis instance at #{@settings.http_redis_host}:#{@settings.http_redis_port}"
puts "(LD) >> Using Goo Redis instance at #{@settings.goo_redis_host}:#{@settings.goo_redis_port}"

connect_goo unless overide_connect_goo
end
Expand Down Expand Up @@ -132,15 +130,14 @@ def connect_goo
port: @settings.goo_redis_port)

if @settings.enable_monitoring
puts "(LD) >> Enable SPARQL monitoring with cube #{@settings.cube_host}:"+
"#{@settings.cube_port}"
puts "(LD) >> Enable SPARQL monitoring with cube #{@settings.cube_host}:#{@settings.cube_port}"
conf.enable_cube do |opts|
opts[:host] = @settings.cube_host
opts[:port] = @settings.cube_port
end
end
end
rescue Exception => e
rescue StandardError => e
abort("EXITING: Cannot connect to triplestore and/or search server:\n #{e}\n#{e.backtrace.join("\n")}")
end
end
Expand All @@ -153,23 +150,48 @@ def goo_namespaces
conf.add_namespace(:omv, RDF::Vocabulary.new("http://omv.ontoware.org/2005/05/ontology#"))
conf.add_namespace(:skos, RDF::Vocabulary.new("http://www.w3.org/2004/02/skos/core#"))
conf.add_namespace(:owl, RDF::Vocabulary.new("http://www.w3.org/2002/07/owl#"))
conf.add_namespace(:rdf, RDF::Vocabulary.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#"))
conf.add_namespace(:rdfs, RDF::Vocabulary.new("http://www.w3.org/2000/01/rdf-schema#"))
conf.add_namespace(:metadata,
RDF::Vocabulary.new("http://data.bioontology.org/metadata/"),
default = true)
conf.add_namespace(:metadata_def,
RDF::Vocabulary.new("http://data.bioontology.org/metadata/def/"))
conf.add_namespace(:metadata, RDF::Vocabulary.new("http://data.bioontology.org/metadata/"), default = true)
conf.add_namespace(:metadata_def, RDF::Vocabulary.new("http://data.bioontology.org/metadata/def/"))
conf.add_namespace(:dc, RDF::Vocabulary.new("http://purl.org/dc/elements/1.1/"))
conf.add_namespace(:xsd, RDF::Vocabulary.new("http://www.w3.org/2001/XMLSchema#"))
conf.add_namespace(:oboinowl_gen,
RDF::Vocabulary.new("http://www.geneontology.org/formats/oboInOwl#"))
conf.add_namespace(:oboinowl_gen, RDF::Vocabulary.new("http://www.geneontology.org/formats/oboInOwl#"))
conf.add_namespace(:obo_purl, RDF::Vocabulary.new("http://purl.obolibrary.org/obo/"))
conf.add_namespace(:umls,
RDF::Vocabulary.new("http://bioportal.bioontology.org/ontologies/umls/"))
conf.id_prefix = "http://data.bioontology.org/"
conf.add_namespace(:umls, RDF::Vocabulary.new("http://bioportal.bioontology.org/ontologies/umls/"))
conf.add_namespace(:door, RDF::Vocabulary.new("http://kannel.open.ac.uk/ontology#"))
conf.add_namespace(:dct, RDF::Vocabulary.new("http://purl.org/dc/terms/"))

conf.add_namespace(:void, RDF::Vocabulary.new("http://rdfs.org/ns/void#"))
conf.add_namespace(:foaf, RDF::Vocabulary.new("http://xmlns.com/foaf/0.1/"))
conf.add_namespace(:vann, RDF::Vocabulary.new("http://purl.org/vocab/vann/"))
conf.add_namespace(:adms, RDF::Vocabulary.new("http://www.w3.org/ns/adms#"))
conf.add_namespace(:voaf, RDF::Vocabulary.new("http://purl.org/vocommons/voaf#"))
conf.add_namespace(:dcat, RDF::Vocabulary.new("http://www.w3.org/ns/dcat#"))
conf.add_namespace(:mod, RDF::Vocabulary.new("http://www.isibang.ac.in/ns/mod#"))
conf.add_namespace(:prov, RDF::Vocabulary.new("http://www.w3.org/ns/prov#"))
conf.add_namespace(:cc, RDF::Vocabulary.new("http://creativecommons.org/ns#"))
conf.add_namespace(:schema, RDF::Vocabulary.new("http://schema.org/"))
conf.add_namespace(:doap, RDF::Vocabulary.new("http://usefulinc.com/ns/doap#"))
conf.add_namespace(:bibo, RDF::Vocabulary.new("http://purl.org/ontology/bibo/"))
conf.add_namespace(:wdrs, RDF::Vocabulary.new("http://www.w3.org/2007/05/powder-s#"))
conf.add_namespace(:cito, RDF::Vocabulary.new("http://purl.org/spar/cito/"))
conf.add_namespace(:pav, RDF::Vocabulary.new("http://purl.org/pav/"))
conf.add_namespace(:oboInOwl, RDF::Vocabulary.new("http://www.geneontology.org/formats/oboInOwl#"))
conf.add_namespace(:idot, RDF::Vocabulary.new("http://identifiers.org/idot/"))
conf.add_namespace(:sd, RDF::Vocabulary.new("http://www.w3.org/ns/sparql-service-description#"))
conf.add_namespace(:org, RDF::Vocabulary.new("http://www.w3.org/ns/org#"))
conf.add_namespace(:cclicense, RDF::Vocabulary.new("http://creativecommons.org/licenses/"))
conf.add_namespace(:nkos, RDF::Vocabulary.new("http://w3id.org/nkos#"))
conf.add_namespace(:skosxl, RDF::Vocabulary.new("http://www.w3.org/2008/05/skos-xl#"))
conf.add_namespace(:dcterms, RDF::Vocabulary.new("http://purl.org/dc/terms/"))
conf.add_namespace(:uneskos, RDF::Vocabulary.new("http://purl.org/umu/uneskos#"))


conf.id_prefix = 'http://data.bioontology.org/'
conf.pluralize_models(true)
end
end
self.goo_namespaces
goo_namespaces

end
22 changes: 11 additions & 11 deletions lib/ontologies_linked_data/models/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ def self.goo_attrs_to_load(attributes = [], level = 0)
raise ArgumentError, "`attributes` should be an array" unless attributes.is_a?(Array)

# Get attributes, either provided, all, or default
if !attributes.empty?
if attributes.first == :all
default_attrs = self.attributes
else
default_attrs = attributes
end
elsif self.hypermedia_settings[:serialize_default].empty?
default_attrs = self.attributes
else
default_attrs = self.hypermedia_settings[:serialize_default].dup
end
default_attrs = if !attributes.empty?
if attributes.first == :all
(self.attributes + self.hypermedia_settings[:serialize_default]).uniq
else
attributes
end
elsif self.hypermedia_settings[:serialize_default].empty?
self.attributes
else
self.hypermedia_settings[:serialize_default].dup
end

embed_attrs = {}
extra_attrs = []
Expand Down
7 changes: 7 additions & 0 deletions lib/ontologies_linked_data/models/ontology_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ def synchronize(&block)
@mutex.synchronize(&block)
end

def URI=(value)
self.uri = value
end
def URI
self.uri
end

def self.ontology_link(m)
ontology_link = ""

Expand Down
17 changes: 14 additions & 3 deletions lib/ontologies_linked_data/monkeypatches/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def to_flex_hash(options = {}, &block)
# Add methods
methods = methods - do_not_serialize_nested(options)
methods.each do |method|
hash[method] = self.send(method.to_s) if self.respond_to?(method) rescue next
populate_attribute(hash, method) if self.respond_to?(method) rescue next
end

# Get rid of everything except the 'only'
Expand Down Expand Up @@ -245,7 +245,7 @@ def populate_attributes(hash, all = false, only = [], options = {})

attributes.each do |attribute|
next unless self.respond_to?(attribute)
hash[attribute] = self.send(attribute)
populate_attribute(hash, attribute)
end
elsif !only.empty?
# Only get stuff we need
Expand All @@ -257,13 +257,22 @@ def populate_attributes(hash, all = false, only = [], options = {})
hash
end

def populate_attribute(hash, attribute)
if self.method(attribute).parameters.eql?([[:rest, :args]])
hash[attribute] = self.send(attribute, include_languages: true)
else
# a serialized method
hash[attribute] = self.send(attribute)
end
end

def populate_hash_from_list(hash, attributes)
attributes.each do |attribute|
attribute = attribute.to_sym

next unless self.respond_to?(attribute)
begin
hash[attribute] = self.send(attribute)
populate_attribute(hash, attribute)
rescue Goo::Base::AttributeNotLoaded
next
rescue ArgumentError
Expand Down Expand Up @@ -338,6 +347,8 @@ def embed_goo_objects_just_values(hash, attribute, value, options, &block)
end

def add_goo_values(goo_object, embedded_values, attributes_to_embed, options, &block)
return if goo_object.nil?

if attributes_to_embed.length > 1
embedded_values_hash = {}
attributes_to_embed.each do |a|
Expand Down
4 changes: 2 additions & 2 deletions lib/ontologies_linked_data/security/access_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def access_for_all?
def read_restricted_based_on?(based_on)
if based_on.is_a?(Proc)
instance_to_base_on = based_on.call(self)
restricted = instance_to_base_on.read_restricted?
restricted = instance_to_base_on ? instance_to_base_on.read_restricted? : false
elsif based_on.is_a?(LinkedData::Models::Base)
restricted = based_on.read_restricted?
elsif based_on.is_a?(Symbol)
instance_to_base_on = based_on.send(based_on)
restricted = instance_to_base_on.read_restricted?
restricted = instance_to_base_on ? instance_to_base_on.read_restricted? : false
else
restricted = false
end
Expand Down
15 changes: 9 additions & 6 deletions lib/ontologies_linked_data/utils/triples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,26 @@ def self.rdf_for_custom_properties(ont_sub)
triples << triple(Goo.vocabulary(:rdfs)[:comment], subPropertyOf, Goo.vocabulary(:skos)[:definition])


# Add subPropertyOf triples for custom properties
unless ont_sub.prefLabelProperty.nil?
unless ont_sub.prefLabelProperty == Goo.vocabulary(:rdfs)[:label]
triples << triple(ont_sub.prefLabelProperty, subPropertyOf, Goo.vocabulary(:metadata_def)[:prefLabel])
unless ont_sub.prefLabelProperty == Goo.vocabulary(:rdfs)[:label] || ont_sub.prefLabelProperty == Goo.vocabulary(:metadata_def)[:prefLabel]
triples << triple(ont_sub.prefLabelProperty, subPropertyOf, Goo.vocabulary(:metadata_def)[:prefLabel])
end
end
unless ont_sub.definitionProperty.nil?
unless ont_sub.definitionProperty == Goo.vocabulary(:rdfs)[:label]
triples << triple(ont_sub.definitionProperty, subPropertyOf, Goo.vocabulary(:skos)[:definition])
unless ont_sub.definitionProperty == Goo.vocabulary(:rdfs)[:label] || ont_sub.definitionProperty == Goo.vocabulary(:skos)[:definition]
triples << triple(ont_sub.definitionProperty, subPropertyOf, Goo.vocabulary(:skos)[:definition])
end
end
unless ont_sub.synonymProperty.nil?
unless ont_sub.synonymProperty == Goo.vocabulary(:rdfs)[:label]
unless ont_sub.synonymProperty == Goo.vocabulary(:rdfs)[:label] || ont_sub.synonymProperty == Goo.vocabulary(:skos)[:altLabel]
triples << triple(ont_sub.synonymProperty, subPropertyOf, Goo.vocabulary(:skos)[:altLabel])
end
end
unless ont_sub.authorProperty.nil?
triples << triple(ont_sub.authorProperty, subPropertyOf, Goo.vocabulary(:dc)[:creator])
unless ont_sub.authorProperty == Goo.vocabulary(:dc)[:creator]
triples << triple(ont_sub.authorProperty, subPropertyOf, Goo.vocabulary(:dc)[:creator])
end
end

if ont_sub.hasOntologyLanguage.obo? || ont_sub.hasOntologyLanguage.owl?
Expand Down

0 comments on commit 37f74d3

Please sign in to comment.