Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: extract ontology URI automatically in submissions process #153

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
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,39 @@
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
22 changes: 3 additions & 19 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 @@ -473,28 +475,9 @@ def generate_rdf(logger, file_path, reasoning=true)
logger.flush
end
delete_and_append(triples_file_path, logger, mime_type)
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 @@ -971,6 +954,7 @@ def process_submission(logger, options={})
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
2 changes: 1 addition & 1 deletion lib/ontologies_linked_data/parser/owlapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RDFFileNotGeneratedException < Parser::ParserException

class OWLAPICommand
def initialize(input_file, output_repo, opts = {})
@owlapi_wrapper_jar_path = LinkedData.bindir + "/owlapi-wrapper-1.3.8.jar"
@owlapi_wrapper_jar_path = LinkedData.bindir + "/owlapi-wrapper-1.4.1.jar"
@input_file = input_file
@output_repo = output_repo
@master_file = opts[:master_file]
Expand Down