Skip to content

Commit

Permalink
use owlapi_wrapper for max_depth calculation
Browse files Browse the repository at this point in the history
add back changes in PR#182 that were overwritten by PR#143
  • Loading branch information
alexskr committed Apr 25, 2024
1 parent cf3ff84 commit da1642e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
9 changes: 2 additions & 7 deletions lib/ontologies_linked_data/metrics/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,7 @@ def self.max_depth_fn(submission, logger, is_flat, rdfsSC)
end
max_depth
end
def self.generate_metrics_file2(class_count, indiv_count, prop_count, max_depth)
CSV.open(self.metrics_path, "wb") do |csv|
csv << ["Class Count", "Individual Count", "Property Count", "Max Depth"]
csv << [class_count, indiv_count, prop_count, max_depth]
end
end

def self.class_metrics(submission, logger)
t00 = Time.now
submission.ontology.bring(:flat) if submission.ontology.bring?(:flat)
Expand All @@ -99,7 +94,7 @@ def self.class_metrics(submission, logger)
rdfsSC = Goo.namespaces[:rdfs][:subClassOf]
end
max_depth = max_depth_fn(submission, logger, is_flat, rdfsSC)

cls_metrics = {}
cls_metrics[:classes] = 0
cls_metrics[:averageChildCount] = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,23 @@ def generate_umls_metrics_file(tr_file_path=nil)
class_count = 0
indiv_count = 0
prop_count = 0
max_depth = 0

File.foreach(tr_file_path) do |line|
class_count += 1 if line =~ /owl:Class/
indiv_count += 1 if line =~ /owl:NamedIndividual/
prop_count += 1 if line =~ /owl:ObjectProperty/
prop_count += 1 if line =~ /owl:DatatypeProperty/
end
generate_metrics_file(class_count, indiv_count, prop_count)

# Get max depth from the metrics.csv file which is already generated
# by owlapi_wrapper when new submission of UMLS ontology is created.
# Ruby code/sparql for calculating max_depth fails for large UMLS
# ontologies with AllegroGraph backend
metrics_from_owlapi = @submission.metrics_from_file
max_depth = metrics_from_owlapi[1][3] unless metrics_from_owlapi.empty?

generate_metrics_file(class_count, indiv_count, prop_count, max_depth)
end

private
Expand Down Expand Up @@ -78,7 +87,7 @@ def metrics_for_submission(logger)
logger.info('properties finished')
logger.flush
# re-generate metrics file
generate_metrics_file(cls_metrics[:classes], indiv_count, prop_count)
generate_metrics_file(cls_metrics[:classes], indiv_count, prop_count, cls_metrics[:maxDepth])
logger.info('generation of metrics file finished')
logger.flush
rescue StandardError => e
Expand All @@ -90,10 +99,10 @@ def metrics_for_submission(logger)
metrics
end

def generate_metrics_file(class_count, indiv_count, prop_count)
def generate_metrics_file(class_count, indiv_count, prop_count, max_depth)
CSV.open(@submission.metrics_path, 'wb') do |csv|
csv << ['Class Count', 'Individual Count', 'Property Count']
csv << [class_count, indiv_count, prop_count]
csv << ['Class Count', 'Individual Count', 'Property Count', 'Max Depth']
csv << [class_count, indiv_count, prop_count, max_depth]
end
end

Expand Down

0 comments on commit da1642e

Please sign in to comment.