Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexskr committed Aug 19, 2022
2 parents 8196bf3 + 53cd329 commit b5057b4
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 40 deletions.
26 changes: 12 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/ncbo/goo.git
revision: fd7d45cb862c5c2c1833b64a5c8c14154384edc2
revision: 562826ba21f7da641159071531375776a1414207
branch: master
specs:
goo (0.0.2)
Expand Down Expand Up @@ -32,8 +32,8 @@ GEM
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
ansi (1.5.0)
ast (2.4.2)
bcrypt (3.1.18)
Expand All @@ -50,7 +50,7 @@ GEM
launchy (~> 2.1)
mail (~> 2.7)
eventmachine (1.2.7)
faraday (1.10.0)
faraday (1.10.1)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
Expand Down Expand Up @@ -110,7 +110,7 @@ GEM
omni_logger (0.1.4)
logger
parallel (1.22.1)
parser (3.1.2.0)
parser (3.1.2.1)
ast (~> 2.4.1)
pony (1.13.1)
mail (>= 2.0)
Expand All @@ -119,7 +119,7 @@ GEM
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
public_suffix (4.0.7)
public_suffix (5.0.0)
rack (1.6.13)
rack-test (0.8.3)
rack (>= 1.0, < 3)
Expand All @@ -137,17 +137,17 @@ GEM
rexml (3.2.5)
rsolr (1.1.2)
builder (>= 2.1.2)
rubocop (1.31.2)
rubocop (1.35.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.1.0.0)
parser (>= 3.1.2.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.18.0, < 2.0)
rubocop-ast (>= 1.20.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.19.1)
rubocop-ast (1.21.0)
parser (>= 3.1.1.0)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
Expand All @@ -169,7 +169,7 @@ GEM
eventmachine (~> 1.0, >= 1.0.4)
rack (>= 1, < 3)
thread_safe (0.3.6)
tzinfo (0.3.60)
tzinfo (0.3.61)
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
Expand All @@ -178,8 +178,6 @@ GEM
macaddr (~> 1.0)

PLATFORMS
x86_64-darwin-18
x86_64-darwin-21
x86_64-linux

DEPENDENCIES
Expand Down Expand Up @@ -213,4 +211,4 @@ DEPENDENCIES
thin

BUNDLED WITH
2.3.14
2.3.15
Binary file not shown.
64 changes: 41 additions & 23 deletions lib/ontologies_linked_data/metrics/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ def self.metrics_for_submission(submission, logger)
metrics.properties = prop_count
logger.info("properties finished")
logger.flush

# re-generate metrics file
submission.generate_metrics_file(cls_metrics[:classes], indiv_count, prop_count)
submission.generate_metrics_file2(cls_metrics[:classes], indiv_count, prop_count, cls_metrics[:maxDepth])
logger.info("generation of metrics file finished")
logger.flush

rescue Exception => e
logger.error(e.message)
logger.error(e)
Expand All @@ -46,35 +48,51 @@ def self.metrics_for_submission(submission, logger)
metrics
end

def self.max_depth_fn(submission, logger, is_flat, rdfsSC)
max_depth = 0
mx_from_file = submission.metrics_from_file(logger)
if (mx_from_file && mx_from_file.length == 2 && mx_from_file[0].length >= 4)
then
max_depth = mx_from_file[1][3].to_i
else
logger.info("Unable to find metrics providing max_depth in file for submission #{submission.id.to_s}. Using ruby calculation of max_depth.")
roots = submission.roots

unless is_flat
depths = []
roots.each do |root|
ok = true
n=1
while ok
ok = hierarchy_depth?(submission.id.to_s,root.id.to_s,n,rdfsSC)
if ok
n += 1
end
if n > 40
#safe guard
ok = false
end
end
n -= 1
depths << n
end
max_depth = depths.max
end
end
max_depth
end

def self.class_metrics(submission, logger)
t00 = Time.now
submission.ontology.bring(:flat) if submission.ontology.bring?(:flat)

is_flat = submission.ontology.flat
roots = submission.roots

max_depth = 0
rdfsSC = nil
unless is_flat
depths = []
rdfsSC = Goo.namespaces[:rdfs][:subClassOf]
roots.each do |root|
ok = true
n=1
while ok
ok = hierarchy_depth?(submission.id.to_s,root.id.to_s,n,rdfsSC)
if ok
n += 1
end
if n > 40
#safe guard
ok = false
end
end
n -= 1
depths << n
end
max_depth = depths.max
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
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 @@ -414,6 +414,13 @@ def generate_metrics_file(class_count, indiv_count, prop_count)
end
end

def 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 generate_umls_metrics_file(tr_file_path=nil)
tr_file_path ||= self.triples_file_path
class_count = 0
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.0.jar"
@input_file = input_file
@output_repo = output_repo
@master_file = opts[:master_file]
Expand Down
5 changes: 3 additions & 2 deletions test/models/test_ontology_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ def test_submission_metrics
assert_equal 0, metrics.classesWithMoreThan25Children
assert_equal 18, metrics.maxChildCount
assert_equal 3, metrics.averageChildCount
assert_equal 3, metrics.maxDepth
assert_equal 4, metrics.maxDepth

submission_parse("BROTEST-METRICS", "BRO testing metrics",
"./test/data/ontology_files/BRO_v3.2.owl", 33,
Expand Down Expand Up @@ -1006,12 +1006,13 @@ def test_submission_metrics
assert_equal 63, metrics.properties
assert_equal 124, metrics.individuals
assert_equal 0, metrics.classesWithOneChild
assert_equal 7, metrics.maxDepth
#cause it has not the subproperty added
assert_equal 474, metrics.classesWithNoDefinition
assert_equal 0, metrics.classesWithMoreThan25Children
assert_equal 0, metrics.maxChildCount
assert_equal 0, metrics.averageChildCount
assert_equal 0, metrics.maxDepth


#test UMLS metrics
acronym = 'UMLS-TST'
Expand Down

0 comments on commit b5057b4

Please sign in to comment.