Skip to content

Commit

Permalink
merged PR #153 that adds the ontology IRI metadata attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
mdorf committed Feb 13, 2024
2 parents 81c0e33 + c1e485b commit bf438b1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
4 changes: 4 additions & 0 deletions lib/ontologies_linked_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
# Require all models
project_root = File.dirname(File.absolute_path(__FILE__))

models = Dir.glob("#{project_root}/ontologies_linked_data/concerns/**/*.rb").sort
models.each do |m|
require m
end
# We need to require deterministic - that is why we have the sort.
models = Dir.glob(project_root + '/ontologies_linked_data/models/**/*.rb').sort
models.each do |m|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module LinkedData
module Concerns
module OntologySubmission
module MetadataExtractor

def extract_metadata
version_info = extract_version
ontology_iri = extract_ontology_iri

self.version = version_info if version_info
self.uri = ontology_iri if ontology_iri

end

def extract_version
query = Goo.sparql_query_client.select(:versionInfo).distinct
.from(self.id)
.where([RDF::URI.new('http://bioportal.bioontology.org/ontologies/versionSubject'),
RDF::URI.new('http://www.w3.org/2002/07/owl#versionInfo'),
:versionInfo])

sol = query.each_solution.first || {}
sol[:versionInfo]&.to_s
end

def extract_ontology_iri
query = Goo.sparql_query_client.select(:uri).distinct
.from(self.id)
.where([:uri,
RDF::URI.new('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'),
RDF::URI.new('http://www.w3.org/2002/07/owl#Ontology')])
sol = query.each_solution.first || {}
sol[:uri]&.to_s
end
end
end
end
end
26 changes: 6 additions & 20 deletions lib/ontologies_linked_data/models/ontology_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module Models

class OntologySubmission < LinkedData::Models::Base

include LinkedData::Concerns::OntologySubmission::MetadataExtractor

FILES_TO_DELETE = ['labels.ttl', 'mappings.ttl', 'obsolete.ttl', 'owlapi.xrdf', 'errors.log']
FLAT_ROOTS_LIMIT = 1000

Expand Down Expand Up @@ -497,28 +499,9 @@ def generate_rdf(logger, reasoning: true)
logger.error("Error sending data to triple store - #{e.response.code} #{e.class}: #{e.response.body}") if e.response&.body
raise e
end
version_info = extract_version()

if version_info
self.version = version_info
end
end

def extract_version

query_version_info = <<eos
SELECT ?versionInfo
FROM #{self.id.to_ntriples}
WHERE {
<http://bioportal.bioontology.org/ontologies/versionSubject>
<http://www.w3.org/2002/07/owl#versionInfo> ?versionInfo .
}
eos
Goo.sparql_query_client.query(query_version_info).each_solution do |sol|
return sol[:versionInfo].to_s
end
return nil
end

def process_callbacks(logger, callbacks, action_name, &block)
callbacks.delete_if do |_, callback|
Expand Down Expand Up @@ -1017,7 +1000,10 @@ def process_submission(logger, options={})
end
status = LinkedData::Models::SubmissionStatus.find("RDF").first
remove_submission_status(status) #remove RDF status before starting
generate_rdf(logger, reasoning: reasoning)
zip_dst = unzip_submission(logger)
file_path = zip_dst ? zip_dst.to_s : self.uploadFilePath.to_s
generate_rdf(logger, file_path, reasoning=reasoning)
extract_metadata
add_submission_status(status)
self.save
rescue Exception => e
Expand Down

0 comments on commit bf438b1

Please sign in to comment.