diff --git a/lib/ontologies_linked_data/metrics/metrics.rb b/lib/ontologies_linked_data/metrics/metrics.rb index 79b893da..102f52e0 100644 --- a/lib/ontologies_linked_data/metrics/metrics.rb +++ b/lib/ontologies_linked_data/metrics/metrics.rb @@ -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) @@ -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 diff --git a/lib/ontologies_linked_data/services/submission_process/operations/submission_mertrics_calculator.rb b/lib/ontologies_linked_data/services/submission_process/operations/submission_mertrics_calculator.rb index 411c8194..d0408bf2 100644 --- a/lib/ontologies_linked_data/services/submission_process/operations/submission_mertrics_calculator.rb +++ b/lib/ontologies_linked_data/services/submission_process/operations/submission_mertrics_calculator.rb @@ -10,6 +10,7 @@ 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/ @@ -17,7 +18,15 @@ def generate_umls_metrics_file(tr_file_path=nil) 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 @@ -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 @@ -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