Skip to content

Commit

Permalink
refactor tests to be faster by doing the indexation step only if nedded
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed May 6, 2024
1 parent b6134ff commit 4304cc4
Show file tree
Hide file tree
Showing 12 changed files with 433 additions and 325 deletions.
89 changes: 47 additions & 42 deletions lib/ontologies_linked_data/sample_data/ontology.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def self.create_ontologies_and_submissions(options = {})
submission_count = options[:submission_count] || 5
random_submission_count = options[:random_submission_count] || false
process_submission = options[:process_submission] || false
process_options = options[:process_options] || { process_rdf: true, index_search: true, index_properties: true,
run_metrics: true, reasoning: true }

submissions_to_process = options[:submissions_to_process]
acronym = options[:acronym] || "TEST-ONT"
pref_label_property = options[:pref_label_property] || false
Expand All @@ -43,12 +46,12 @@ def self.create_ontologies_and_submissions(options = {})
ont_acronyms << acronym_count

o = LinkedData::Models::Ontology.new({
acronym: acronym_count,
name: name || "#{acronym_count} Ontology",
administeredBy: [u],
summaryOnly: false,
ontologyType: ontology_type
})
acronym: acronym_count,
name: name ? "#{name}#{count > 0 ? count : ''}" : "#{acronym_count} Ontology",
administeredBy: [u],
summaryOnly: false,
ontologyType: ontology_type
})

if o.exist?
o = LinkedData::Models::Ontology.find(acronym_count).include(LinkedData::Models::Ontology.attributes(:all)).first
Expand Down Expand Up @@ -110,14 +113,12 @@ def self.create_ontologies_and_submissions(options = {})
o.submissions.each do |ss|
ss.bring(:submissionId) if ss.bring?(:submissionId)
next if (!submissions_to_process.nil? && !submissions_to_process.include?(ss.submissionId))

test_log_file = TestLogFile.new
tmp_log = Logger.new(test_log_file)

begin
ss.process_submission(tmp_log,
process_rdf: true, index_search: true, index_properties: true,
run_metrics: true, reasoning: true)
ss.process_submission(tmp_log, process_options)
rescue Exception => e
puts "Error processing submission: #{ss.id.to_s}"
puts "See test log for errors: #{test_log_file.path}"
Expand All @@ -135,15 +136,15 @@ def self.load_semantic_types_ontology(options = {})
file_path = "../../../../test/data/ontology_files/umls_semantictypes.ttl" if file_path.nil?

count, acronyms, sty = create_ontologies_and_submissions({
ont_count: 1,
submission_count: 1,
process_submission: true,
acronym: "STY",
ontology_format: "UMLS",
name: "Semantic Types Ontology",
acronym_suffix: "",
file_path: file_path
})
ont_count: 1,
submission_count: 1,
process_submission: true,
acronym: "STY",
ontology_format: "UMLS",
name: "Semantic Types Ontology",
acronym_suffix: "",
file_path: file_path
})
sty
end

Expand Down Expand Up @@ -176,35 +177,39 @@ def self.delete_ontologies_and_submissions
u.delete unless u.nil?
end

def self.sample_owl_ontologies
def self.sample_owl_ontologies(process_submission: false, process_options: nil)
process_options ||= {process_rdf: true, extract_metadata: false, index_search: false}
count, acronyms, bro = create_ontologies_and_submissions({
process_submission: true,
acronym: "BROTEST",
name: "ontTEST Bla",
file_path: "../../../../test/data/ontology_files/BRO_v3.2.owl",
ont_count: 1,
submission_count: 1
})
process_submission: process_submission,
process_options: process_options,
acronym: "BROTEST",
name: "ontTEST Bla",
file_path: "../../../../test/data/ontology_files/BRO_v3.2.owl",
ont_count: 1,
submission_count: 1
})

# This one has some nasty looking IRIS with slashes in the anchor
count, acronyms, mccl = create_ontologies_and_submissions({
process_submission: true,
acronym: "MCCLTEST",
name: "MCCLS TEST",
file_path: "../../../../test/data/ontology_files/CellLine_OWL_BioPortal_v1.0.owl",
ont_count: 1,
submission_count: 1
})
process_submission: process_submission,
process_options: process_options,
acronym: "MCCLTEST",
name: "MCCLS TEST",
file_path: "../../../../test/data/ontology_files/CellLine_OWL_BioPortal_v1.0.owl",
ont_count: 1,
submission_count: 1
})

# This one has resources wih accents.
count, acronyms, onto_matest = create_ontologies_and_submissions({
process_submission: true,
acronym: "ONTOMATEST",
name: "OntoMA TEST",
file_path: "../../../../test/data/ontology_files/OntoMA.1.1_vVersion_1.1_Date__11-2011.OWL",
ont_count: 1,
submission_count: 1
})
process_submission: process_submission,
process_options: process_options,
acronym: "ONTOMATEST",
name: "OntoMA TEST",
file_path: "../../../../test/data/ontology_files/OntoMA.1.1_vVersion_1.1_Date__11-2011.OWL",
ont_count: 1,
submission_count: 1
})

return bro.concat(mccl).concat(onto_matest)
end
Expand Down
6 changes: 4 additions & 2 deletions test/models/notes/test_note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ def self.after_suite
end

def _ontology_and_class
count, acronyms, ontologies = create_ontologies_and_submissions(ont_count: 1, submission_count: 1, process_submission: true)
count, acronyms, ontologies = create_ontologies_and_submissions(ont_count: 1, submission_count: 1,
process_submission: true,
process_options: {process_rdf: true, extract_metadata: false})
ontology = ontologies.first
cls = LinkedData::Models::Class.where.include(:prefLabel).in(ontology.latest_submission).read_only.page(1, 1).first
cls = LinkedData::Models::Class.where.include(:prefLabel).in(ontology.latest_submission).read_only.first
return ontology, cls
end

Expand Down
108 changes: 53 additions & 55 deletions test/models/test_mappings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,33 @@ class TestMapping < LinkedData::TestOntologyCommon


def self.before_suite
LinkedData::TestCase.backend_4s_delete
ontologies_parse()
backend_4s_delete
ontologies_parse
end

def self.ontologies_parse()
def self.ontologies_parse
helper = LinkedData::TestOntologyCommon.new(self)
helper.submission_parse(ONT_ACR1,
"MappingOntTest1",
"./test/data/ontology_files/BRO_v3.3.owl", 11,
process_rdf: true, index_search: false,
run_metrics: false, reasoning: true)
process_rdf: true, extract_metadata: false)
helper.submission_parse(ONT_ACR2,
"MappingOntTest2",
"./test/data/ontology_files/CNO_05.owl", 22,
process_rdf: true, index_search: false,
run_metrics: false, reasoning: true)
process_rdf: true, extract_metadata: false)
helper.submission_parse(ONT_ACR3,
"MappingOntTest3",
"./test/data/ontology_files/aero.owl", 33,
process_rdf: true, index_search: false,
run_metrics: false, reasoning: true)
process_rdf: true, extract_metadata: false)
helper.submission_parse(ONT_ACR4,
"MappingOntTest4",
"./test/data/ontology_files/fake_for_mappings.owl", 44,
process_rdf: true, index_search: false,
run_metrics: false, reasoning: true)
LinkedData::Mappings.create_mapping_counts(Logger.new(TestLogFile.new))
process_rdf: true, extract_metadata: false)
end

def test_mapping_count_models
LinkedData::Models::MappingCount.where.all do |x|
x.delete
end
LinkedData::Models::MappingCount.where.all(&:delete)

m = LinkedData::Models::MappingCount.new
assert !m.valid?
m.ontologies = ["BRO"]
Expand All @@ -70,48 +64,17 @@ def test_mapping_count_models
.all
assert result.length == 1
assert result.first.count == 321
LinkedData::Models::MappingCount.where.all do |x|
x.delete
end
LinkedData::Models::MappingCount.where.all(&:delete)
end

def validate_mapping(map)
prop = map.source.downcase.to_sym
prop = :prefLabel if map.source == "LOOM"
prop = nil if map.source == "SAME_URI"

classes = []
map.classes.each do |t|
sub = LinkedData::Models::Ontology.find(t.submission.ontology.id)
.first.latest_submission
cls = LinkedData::Models::Class.find(t.id).in(sub)
unless prop.nil?
cls.include(prop)
end
cls = cls.first
classes << cls unless cls.nil?
end
if map.source == "SAME_URI"
return classes[0].id.to_s == classes[1].id.to_s
end
if map.source == "LOOM"
ldOntSub = LinkedData::Models::OntologySubmission
label0 = ldOntSub.loom_transform_literal(classes[0].prefLabel)
label1 = ldOntSub.loom_transform_literal(classes[1].prefLabel)
return label0 == label1
end
if map.source == "CUI"
return classes[0].cui == classes[1].cui
end
return false
end

def test_mappings_ontology
LinkedData::Models::RestBackupMapping.all.each do |m|
LinkedData::Mappings.delete_rest_mapping(m.id)
end
LinkedData::Mappings.create_mapping_counts(Logger.new(TestLogFile.new))
assert LinkedData::Models::MappingCount.where.all.length > 2

assert create_count_mapping > 2
#bro
ont1 = LinkedData::Models::Ontology.where({ :acronym => ONT_ACR1 }).to_a[0]

Expand Down Expand Up @@ -146,6 +109,8 @@ def test_mappings_ontology
end
assert validate_mapping(map), "mapping is not valid"
end
assert create_count_mapping > 2

by_ont_counts = LinkedData::Mappings.mapping_ontologies_count(latest_sub,nil)
total = 0
by_ont_counts.each do |k,v|
Expand Down Expand Up @@ -173,9 +138,7 @@ def test_mappings_ontology
end

def test_mappings_two_ontologies
LinkedData::Mappings.create_mapping_counts(Logger.new(TestLogFile.new))
map_ct = LinkedData::Models::MappingCount.where.all.length
assert map_ct > 2, "Mapping count should exceed the value of 2"
assert create_count_mapping > 2, "Mapping count should exceed the value of 2"
#bro
ont1 = LinkedData::Models::Ontology.where({ :acronym => ONT_ACR1 }).to_a[0]
#fake ont
Expand Down Expand Up @@ -226,6 +189,9 @@ def test_mappings_two_ontologies
end

def test_mappings_rest
LinkedData::Models::RestBackupMapping.all.each do |m|
LinkedData::Mappings.delete_rest_mapping(m.id)
end
mapping_term_a, mapping_term_b, submissions_a, submissions_b, relations, user = rest_mapping_data

mappings_created = []
Expand Down Expand Up @@ -271,8 +237,10 @@ def test_mappings_rest
helper.submission_parse(ONT_ACR1,
"MappingOntTest1",
"./test/data/ontology_files/BRO_v3.3.owl", 12,
process_rdf: true, index_search: false,
run_metrics: false, reasoning: true)
process_rdf: true, extract_metadata: false)

assert create_count_mapping > 2

latest_sub1 = LinkedData::Models::Ontology.find(RDF::URI.new(ont_id)).first.latest_submission
LinkedData::Mappings.create_mapping_counts(Logger.new(TestLogFile.new))
ct1 = LinkedData::Models::MappingCount.where.all.length
Expand Down Expand Up @@ -364,7 +332,37 @@ def create_rest_mapping(relation:, user:, name:, classes:)
process.relation = relation
process.creator = user
process.save

LinkedData::Mappings.create_rest_mapping(classes, process)
end

def validate_mapping(map)
prop = map.source.downcase.to_sym
prop = :prefLabel if map.source == "LOOM"
prop = nil if map.source == "SAME_URI"

classes = []
map.classes.each do |t|
sub = LinkedData::Models::Ontology.find(t.submission.ontology.id)
.first.latest_submission
cls = LinkedData::Models::Class.find(t.id).in(sub)
unless prop.nil?
cls.include(prop)
end
cls = cls.first
classes << cls unless cls.nil?
end
if map.source == "SAME_URI"
return classes[0].id.to_s == classes[1].id.to_s
end
if map.source == "LOOM"
ldOntSub = LinkedData::Models::OntologySubmission
label0 = ldOntSub.loom_transform_literal(classes[0].prefLabel)
label1 = ldOntSub.loom_transform_literal(classes[1].prefLabel)
return label0 == label1
end
if map.source == "CUI"
return classes[0].cui == classes[1].cui
end
return false
end
end
3 changes: 3 additions & 0 deletions test/models/test_metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ def create_submission
os.submissionId = id
os.contact = [contact]
os.released = DateTime.now - 4
os.description = "description example"
os.status = 'beta'
os.URI = RDF::URI.new('https://test.com')
bogus.name = name
o = LinkedData::Models::Ontology.find(acronym)
if o.nil?
Expand Down
Loading

0 comments on commit 4304cc4

Please sign in to comment.