diff --git a/lib/ontologies_linked_data/concerns/mappings/mapping_counts.rb b/lib/ontologies_linked_data/concerns/mappings/mapping_counts.rb index ea692f44..b3324a57 100644 --- a/lib/ontologies_linked_data/concerns/mappings/mapping_counts.rb +++ b/lib/ontologies_linked_data/concerns/mappings/mapping_counts.rb @@ -2,68 +2,34 @@ module LinkedData module Concerns module Mappings module Count - def mapping_counts(enable_debug = false, logger = nil, reload_cache = false, arr_acronyms = []) + def mapping_counts(enable_debug, logger, reload_cache = false, arr_acronyms = []) logger = nil unless enable_debug - t = Time.now - latest = self.retrieve_latest_submissions(options = { acronyms: arr_acronyms }) + start_time = Time.now counts = {} - # Counting for External mappings - t0 = Time.now - external_uri = LinkedData::Models::ExternalClass.graph_uri - exter_counts = mapping_ontologies_count(external_uri, nil, reload_cache = reload_cache) - exter_total = 0 - exter_counts.each do |k, v| - exter_total += v - end - counts[external_uri.to_s] = exter_total - logger.info("Time for External Mappings took #{Time.now - t0} sec. records #{exter_total}") if enable_debug - LinkedData.settings.interportal_hash ||= {} - # Counting for Interportal mappings - LinkedData.settings.interportal_hash.each_key do |acro| - t0 = Time.now - interportal_uri = LinkedData::Models::InterportalClass.graph_uri(acro) - inter_counts = mapping_ontologies_count(interportal_uri, nil, reload_cache = reload_cache) - inter_total = 0 - inter_counts.each do |k, v| - inter_total += v - end - counts[interportal_uri.to_s] = inter_total - if enable_debug - logger.info("Time for #{interportal_uri.to_s} took #{Time.now - t0} sec. records #{inter_total}") - end - end - # Counting for mappings between the ontologies hosted by the BioPortal appliance - i = 0 - epr = Goo.sparql_query_client(:main) - - latest.each do |acro, sub| - self.handle_triple_store_downtime(logger) if Goo.backend_4s? - t0 = Time.now - s_counts = self.mapping_ontologies_count(sub, nil, reload_cache = reload_cache) - s_total = 0 - - s_counts.each do |k, v| - s_total += v - end - counts[acro] = s_total - i += 1 - next unless enable_debug + # Process External and Interportal Mappings + counts[LinkedData::Models::ExternalClass.graph_uri.to_s] = calculate_and_log_counts( + LinkedData::Models::ExternalClass.graph_uri, logger, reload_cache, 'External Mappings', enable_debug + ) - logger.info("#{i}/#{latest.count} " + - "Retrieved #{s_total} records for #{acro} in #{Time.now - t0} seconds.") - logger.flush + LinkedData.settings.interportal_hash&.each_key do |acro| + uri = LinkedData::Models::InterportalClass.graph_uri(acro) + counts[uri.to_s] = + calculate_and_log_counts(uri, logger, reload_cache, "Interportal Mappings for #{acro}", enable_debug) end - if enable_debug - logger.info("Total time #{Time.now - t} sec.") - logger.flush + # Process Hosted Ontologies + retrieve_latest_submissions(acronyms: arr_acronyms).each_with_index do |(acro, sub), index| + counts[acro] = + calculate_and_log_counts(sub, logger, reload_cache, "Hosted Ontology #{acro} (#{index + 1})", enable_debug) end - return counts + + logger&.info("Total time #{Time.now - start_time} sec.") if enable_debug + counts end def create_mapping_counts(logger, arr_acronyms = []) - ont_msg = arr_acronyms.empty? ? "all ontologies" : "ontologies [#{arr_acronyms.join(', ')}]" + ont_msg = arr_acronyms.empty? ? 'all ontologies' : "ontologies [#{arr_acronyms.join(', ')}]" time = Benchmark.realtime do create_mapping_count_totals_for_ontologies(logger, arr_acronyms) @@ -79,20 +45,10 @@ def create_mapping_counts(logger, arr_acronyms = []) end def create_mapping_count_totals_for_ontologies(logger, arr_acronyms) - new_counts = mapping_counts(enable_debug = true, logger = logger, reload_cache = true, arr_acronyms) - persistent_counts = {} - f = Goo::Filter.new(:pair_count) == false - - LinkedData::Models::MappingCount.where.filter(f) - .include(:ontologies, :count) - .include(:all) - .all - .each do |m| - persistent_counts[m.ontologies.first] = m - end - - latest = self.retrieve_latest_submissions(options = { acronyms: arr_acronyms }) - delete_zombie_mapping_count(persistent_counts.values, latest.values.compact.map { |sub| sub.ontology.acronym }) + new_counts = mapping_counts(true, logger, true, arr_acronyms) + persistent_counts = all_existent_mapping_counts(pair_count: false) + latest = retrieve_latest_submissions + delete_zombie_submission_count(persistent_counts, latest) num_counts = new_counts.keys.length ctr = 0 @@ -100,137 +56,52 @@ def create_mapping_count_totals_for_ontologies(logger, arr_acronyms) new_counts.each_key do |acr| new_count = new_counts[acr] ctr += 1 - - if persistent_counts.include?(acr) - inst = persistent_counts[acr] - if new_count.zero? - inst.delete if inst.persistent? - elsif new_count != inst.count - inst.bring_remaining - inst.count = new_count - - begin - if inst.valid? - inst.save - else - logger.error("Error updating mapping count for #{acr}: #{inst.id.to_s}. #{inst.errors}") - next - end - rescue Exception => e - logger.error("Exception updating mapping count for #{acr}: #{inst.id.to_s}. #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}") - next - end - end - else - m = LinkedData::Models::MappingCount.new - m.ontologies = [acr] - m.pair_count = false - m.count = new_count - - begin - if m.valid? - m.save - else - logger.error("Error saving new mapping count for #{acr}. #{m.errors}") - next - end - rescue Exception => e - logger.error("Exception saving new mapping count for #{acr}. #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}") - next - end - end + update_mapping_count(persistent_counts, new_counts, acr, acr, new_count, false) remaining = num_counts - ctr - logger.info("Total mapping count saved for #{acr}: #{new_count}. " << ((remaining.positive?) ? "#{remaining} counts remaining..." : "All done!")) + logger.info("Total mapping count saved for #{acr}: #{new_count}. " << (remaining.positive? ? "#{remaining} counts remaining..." : 'All done!')) end end # This generates pair mapping counts for the given # ontologies to ALL other ontologies in the system def create_mapping_count_pairs_for_ontologies(logger, arr_acronyms) + all_latest_submissions = retrieve_latest_submissions + latest_submissions = if Array(arr_acronyms).empty? + all_latest_submissions + else + all_latest_submissions.select { |k, _v| arr_acronyms.include?(k) } + end - latest_submissions = self.retrieve_latest_submissions(options = { acronyms: arr_acronyms }) - all_latest_submissions = self.retrieve_latest_submissions ont_total = latest_submissions.length logger.info("There is a total of #{ont_total} ontologies to process...") ont_ctr = 0 - # filename = 'mapping_pairs.ttl' - # temp_dir = Dir.tmpdir - # temp_file_path = File.join(temp_dir, filename) - # temp_dir = '/Users/mdorf/Downloads/test/' - # temp_file_path = File.join(File.dirname(file_path), "test.ttl") - # fsave = File.open(temp_file_path, "a") + + persistent_counts = all_existent_mapping_counts(pair_count: true) + delete_zombie_submission_count(persistent_counts, all_latest_submissions) + latest_submissions.each do |acr, sub| - self.handle_triple_store_downtime(logger) if Goo.backend_4s? new_counts = nil time = Benchmark.realtime do - new_counts = self.mapping_ontologies_count(sub, nil, reload_cache = true) + new_counts = mapping_ontologies_count(sub, nil, true) end logger.info("Retrieved new mapping pair counts for #{acr} in #{time} seconds.") ont_ctr += 1 - persistent_counts = {} - LinkedData::Models::MappingCount.where(pair_count: true).and(ontologies: acr) - .include(:ontologies, :count).all.each do |m| - other = m.ontologies.first - other = m.ontologies.last if other == acr - persistent_counts[other] = m - end - delete_zombie_mapping_count(persistent_counts.values, all_latest_submissions.values.compact.map { |s| s.ontology.acronym }) + persistent_counts = all_existent_mapping_counts(acr: acr, pair_count: true) + delete_zombie_mapping_count(persistent_counts, new_counts) num_counts = new_counts.keys.length logger.info("Ontology: #{acr}. #{num_counts} mapping pair counts to record...") - logger.info("------------------------------------------------") + logger.info('------------------------------------------------') ctr = 0 new_counts.each_key do |other| new_count = new_counts[other] ctr += 1 - - if persistent_counts.include?(other) - inst = persistent_counts[other] - if new_count.zero? - inst.delete - elsif new_count != inst.count - inst.bring_remaining if inst.persistent? - inst.pair_count = true - inst.count = new_count - - begin - if inst.valid? - inst.save() - # inst.save({ batch: fsave }) - else - logger.error("Error updating mapping count for the pair [#{acr}, #{other}]: #{inst.id.to_s}. #{inst.errors}") - next - end - rescue Exception => e - logger.error("Exception updating mapping count for the pair [#{acr}, #{other}]: #{inst.id.to_s}. #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}") - next - end - end - else - next unless new_counts.key?(other) - - m = LinkedData::Models::MappingCount.new - m.count = new_count - m.ontologies = [acr, other] - m.pair_count = true - begin - if m.valid? - m.save() - # m.save({ batch: fsave }) - else - logger.error("Error saving new mapping count for the pair [#{acr}, #{other}]. #{m.errors}") - next - end - rescue Exception => e - logger.error("Exception saving new mapping count for the pair [#{acr}, #{other}]. #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}") - next - end - end + update_mapping_count(persistent_counts, new_counts, acr, other, new_count, true) remaining = num_counts - ctr - logger.info("Mapping count saved for the pair [#{acr}, #{other}]: #{new_count}. " << ((remaining.positive?) ? "#{remaining} counts remaining for #{acr}..." : "All done!")) + logger.info("Mapping count saved for the pair [#{acr}, #{other}]: #{new_count}. " << (remaining.positive? ? "#{remaining} counts remaining for #{acr}..." : 'All done!')) wait_interval = 250 next unless (ctr % wait_interval).zero? @@ -240,27 +111,90 @@ def create_mapping_count_pairs_for_ontologies(logger, arr_acronyms) sleep(sec_to_wait) end remaining_ont = ont_total - ont_ctr - logger.info("Completed processing pair mapping counts for #{acr}. " << ((remaining_ont.positive?) ? "#{remaining_ont} ontologies remaining..." : "All ontologies processed!")) + logger.info("Completed processing pair mapping counts for #{acr}. " << (remaining_ont.positive? ? "#{remaining_ont} ontologies remaining..." : 'All ontologies processed!')) end - # fsave.close end private - def delete_zombie_mapping_count(existent_counts, submissions_ready) + def calculate_and_log_counts(uri, logger, reload_cache, label, enable_debug) + start_time = Time.now + count = mapping_ontologies_count(uri, nil, reload_cache).values.sum + logger&.info("#{label} took #{Time.now - start_time} sec. records #{count}") if enable_debug + count + end + + def update_mapping_count(persistent_counts, new_counts, acr, other, new_count, pair_count) + if persistent_counts.key?(other) + inst = persistent_counts[other] + if new_count.zero? && pair_count + inst.delete + elsif new_count != inst.count + inst.pair_count = pair_count + inst.count = new_count + inst.save + end + else + return if !new_counts.key?(other) && pair_count + + m = LinkedData::Models::MappingCount.new + m.count = new_count + m.ontologies = if pair_count + [acr, other] + else + [acr] + end + m.pair_count = pair_count + return if m.exist? + + m.save + end + end + + def delete_zombie_mapping_count(persistent_counts, new_counts) + persistent_counts.each do |acronym, mapping| + next if mapping.ontologies.all? { |x| new_counts.key?(x) } + + mapping.delete + persistent_counts.delete(acronym) + end + end + + def delete_zombie_submission_count(persistent_counts, all_latest_submissions) special_mappings = ["http://data.bioontology.org/metadata/ExternalMappings", "http://data.bioontology.org/metadata/InterportalMappings/agroportal", "http://data.bioontology.org/metadata/InterportalMappings/ncbo", "http://data.bioontology.org/metadata/InterportalMappings/sifr"] - existent_counts.each do |mapping| + persistent_counts.each do |acronym, mapping| next if mapping.ontologies.size == 1 && !(mapping.ontologies & special_mappings).empty? - next if mapping.ontologies.all? { |x| submissions_ready.include?(x) } - next unless mapping.persistent? + next if mapping.ontologies.all? { |x| all_latest_submissions.key?(x) } mapping.delete + persistent_counts.delete(acronym) + end + end + + def all_existent_mapping_counts(acr: nil, pair_count: true) + persistent_counts = {} + query = LinkedData::Models::MappingCount + query = if acr + query.where(ontologies: acr) + else + query.where + end + + f = Goo::Filter.new(:pair_count) == pair_count + query = query.filter(f) + + query.include(:ontologies, :count).all.each do |m| + other = m.ontologies.first + other = m.ontologies.last if acr && (other == acr) + persistent_counts[other] = m end + persistent_counts end + end end end diff --git a/test/models/test_mappings.rb b/test/models/test_mappings.rb index 356c45ce..d3ec5e01 100644 --- a/test/models/test_mappings.rb +++ b/test/models/test_mappings.rb @@ -1,5 +1,5 @@ -require_relative "./test_ontology_common" -require "logger" +require_relative './test_ontology_common' +require 'logger' class TestMapping < LinkedData::TestOntologyCommon @@ -16,20 +16,20 @@ def self.before_suite def self.ontologies_parse helper = LinkedData::TestOntologyCommon.new(self) helper.submission_parse(ONT_ACR1, - "MappingOntTest1", - "./test/data/ontology_files/BRO_v3.3.owl", 11, + 'MappingOntTest1', + './test/data/ontology_files/BRO_v3.3.owl', 11, process_rdf: true, extract_metadata: false) helper.submission_parse(ONT_ACR2, - "MappingOntTest2", - "./test/data/ontology_files/CNO_05.owl", 22, + 'MappingOntTest2', + './test/data/ontology_files/CNO_05.owl', 22, process_rdf: true, extract_metadata: false) helper.submission_parse(ONT_ACR3, - "MappingOntTest3", - "./test/data/ontology_files/aero.owl", 33, + 'MappingOntTest3', + './test/data/ontology_files/aero.owl', 33, process_rdf: true, extract_metadata: false) helper.submission_parse(ONT_ACR4, - "MappingOntTest4", - "./test/data/ontology_files/fake_for_mappings.owl", 44, + 'MappingOntTest4', + './test/data/ontology_files/fake_for_mappings.owl', 44, process_rdf: true, extract_metadata: false) end @@ -47,8 +47,8 @@ def test_mapping_count_ontology_delete counts = LinkedData::Models::MappingCount.where.include(:ontologies).all.map(&:ontologies) refute(counts.any? { |x| x.include?(ONT_ACR4) }, 'Mapping count of deleted ontologies should not exist anymore') submission_parse(ONT_ACR4, - "MappingOntTest4", - "./test/data/ontology_files/fake_for_mappings.owl", 45, + 'MappingOntTest4', + './test/data/ontology_files/fake_for_mappings.owl', 45, process_rdf: true, extract_metadata: false) end @@ -71,35 +71,36 @@ def test_mapping_count_submission_delete LinkedData::Models::Ontology.find(ONT_ACR4).first.delete submission_parse(ONT_ACR4, - "MappingOntTest4", - "./test/data/ontology_files/fake_for_mappings.owl", 46, + 'MappingOntTest4', + './test/data/ontology_files/fake_for_mappings.owl', 46, process_rdf: true, extract_metadata: false) end + def test_mapping_count_models LinkedData::Models::MappingCount.where.all(&:delete) m = LinkedData::Models::MappingCount.new assert !m.valid? - m.ontologies = ["BRO"] + m.ontologies = ['BRO'] m.pair_count = false m.count = 123 assert m.valid? m.save - assert LinkedData::Models::MappingCount.where(ontologies: "BRO").all.count == 1 + assert LinkedData::Models::MappingCount.where(ontologies: 'BRO').all.count == 1 m = LinkedData::Models::MappingCount.new assert !m.valid? - m.ontologies = ["BRO", "FMA"] + m.ontologies = ['BRO', 'FMA'] m.count = 321 m.pair_count = true assert m.valid? m.save - assert LinkedData::Models::MappingCount.where(ontologies: "BRO").all.count == 2 - result = LinkedData::Models::MappingCount.where(ontologies: "BRO") - .and(ontologies: "FMA").include(:count).all + assert LinkedData::Models::MappingCount.where(ontologies: 'BRO').all.count == 2 + result = LinkedData::Models::MappingCount.where(ontologies: 'BRO') + .and(ontologies: 'FMA').include(:count).all assert result.length == 1 assert result.first.count == 321 - result = LinkedData::Models::MappingCount.where(ontologies: "BRO") + result = LinkedData::Models::MappingCount.where(ontologies: 'BRO') .and(pair_count: true) .include(:count) .all @@ -108,6 +109,26 @@ def test_mapping_count_models LinkedData::Models::MappingCount.where.all(&:delete) end + def test_count_mapping_creation + LinkedData::Models::MappingCount.where.all(&:delete) + assert create_count_mapping > 2, 'Mapping count should exceed the value of 2' + assert_equal 12, LinkedData::Models::MappingCount.where.all.size + + puts "run count mapping to #{ONT_ACR1} and #{ONT_ACR2}" + LinkedData::Mappings.create_mapping_counts(Logger.new(TestLogFile.new), [ONT_ACR1, ONT_ACR2]) + assert_equal 12, LinkedData::Models::MappingCount.where.all.size + + puts "run count mapping to only #{ONT_ACR1}" + LinkedData::Mappings.create_mapping_counts(Logger.new(TestLogFile.new), [ONT_ACR1]) + + + assert_equal 12, LinkedData::Models::MappingCount.where.all.size + + puts 'run count mapping to all ontologies' + LinkedData::Mappings.create_mapping_counts(Logger.new(TestLogFile.new)) + assert_equal 12, LinkedData::Models::MappingCount.where.all.size + end + def test_mappings_ontology LinkedData::Models::RestBackupMapping.all.each do |m| LinkedData::Mappings.delete_rest_mapping(m.id) @@ -130,23 +151,23 @@ def test_mappings_ontology mappings += page page_no += 1 end - assert mappings.length > 0 + refute mappings.empty? cui = 0 same_uri = 0 loom = 0 mappings.each do |map| assert_equal(map.classes[0].submission.ontology.acronym, latest_sub.ontology.acronym) - if map.source == "CUI" + if map.source == 'CUI' cui += 1 - elsif map.source == "SAME_URI" + elsif map.source == 'SAME_URI' same_uri += 1 - elsif map.source == "LOOM" + elsif map.source == 'LOOM' loom += 1 else - assert 1 == 0, "unknown source for this ontology #{map.source}" + assert 1.zero?, "unknown source for this ontology #{map.source}" end - assert validate_mapping(map), "mapping is not valid" + assert validate_mapping(map), 'mapping is not valid' end assert create_count_mapping > 2 @@ -156,11 +177,11 @@ def test_mappings_ontology total += v end assert(by_ont_counts.length == 2) - ["MAPPING_TEST2", "MAPPING_TEST4"].each do |x| + ['MAPPING_TEST2', 'MAPPING_TEST4'].each do |x| assert(by_ont_counts.include?(x)) end - assert_equal(by_ont_counts["MAPPING_TEST2"], 10) - assert_equal(by_ont_counts["MAPPING_TEST4"], 8) + assert_equal(by_ont_counts['MAPPING_TEST2'], 10) + assert_equal(by_ont_counts['MAPPING_TEST4'], 8) assert_equal(total, 18) assert_equal(mappings.length, 18) assert_equal(same_uri, 10) @@ -169,7 +190,7 @@ def test_mappings_ontology mappings.each do |map| class_mappings = LinkedData::Mappings.mappings_ontology( latest_sub, 1, 100, map.classes[0].id) - assert class_mappings.length > 0 + assert class_mappings.length.positive? class_mappings.each do |cmap| assert validate_mapping(map) end @@ -177,7 +198,7 @@ def test_mappings_ontology end def test_mappings_two_ontologies - assert create_count_mapping > 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 @@ -206,16 +227,16 @@ def test_mappings_two_ontologies latest_sub1.ontology.acronym) assert_equal(map.classes[1].submission.ontology.acronym, latest_sub2.ontology.acronym) - if map.source == "CUI" + if map.source == 'CUI' cui += 1 - elsif map.source == "SAME_URI" + elsif map.source == 'SAME_URI' same_uri += 1 - elsif map.source == "LOOM" + elsif map.source == 'LOOM' loom += 1 else - assert 1 == 0, "unknown source for this ontology #{map.source}" + assert 1.zero?, "unknown source for this ontology #{map.source}" end - assert validate_mapping(map), "mapping is not valid" + assert validate_mapping(map), 'mapping is not valid' end count = LinkedData::Mappings.mapping_ontologies_count(latest_sub1, latest_sub2, true) @@ -243,20 +264,20 @@ def test_mappings_rest name: "proc#{i}") end - ont_id = submissions_a.first.split("/")[0..-3].join("/") + ont_id = submissions_a.first.split('/')[0..-3].join('/') latest_sub = LinkedData::Models::Ontology.find(RDF::URI.new(ont_id)).first.latest_submission assert create_count_mapping > 2 mappings = LinkedData::Mappings.mappings_ontology(latest_sub, 1, 1000) rest_mapping_count = 0 mappings.each do |m| - if m.source == "REST" + if m.source == 'REST' rest_mapping_count += 1 assert_equal m.classes.length, 2 c1 = m.classes.select { - |c| c.submission.id.to_s["TEST1"] }.first + |c| c.submission.id.to_s['TEST1'] }.first c2 = m.classes.select { - |c| c.submission.id.to_s["TEST2"] }.first + |c| c.submission.id.to_s['TEST2'] }.first assert c1 != nil assert c2 != nil ia = mapping_term_a.index c1.id.to_s @@ -271,9 +292,9 @@ def test_mappings_rest assert rest_mapping_count > 1 || rest_mapping_count < 4 # in a new submission we should have moved the rest mappings submission_parse(ONT_ACR1, - "MappingOntTest1", - "./test/data/ontology_files/BRO_v3.3.owl", 12, - process_rdf: true, extract_metadata: false) + 'MappingOntTest1', + './test/data/ontology_files/BRO_v3.3.owl', 12, + process_rdf: true, extract_metadata: false) assert create_count_mapping > 2 @@ -281,7 +302,7 @@ def test_mappings_rest mappings = LinkedData::Mappings.mappings_ontology(latest_sub1, 1, 1000) rest_mapping_count = 0 mappings.each do |m| - rest_mapping_count += 1 if m.source == "REST" + rest_mapping_count += 1 if m.source == 'REST' end assert_equal 3, rest_mapping_count end @@ -327,23 +348,23 @@ def get_mapping_classes(term_a:, term_b:, submissions_a:, submissions_b:) end def rest_mapping_data - mapping_term_a = ["http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Image_Algorithm", - "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Image", - "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Integration_and_Interoperability_Tools"] + mapping_term_a = ['http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Image_Algorithm', + 'http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Image', + 'http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Integration_and_Interoperability_Tools'] submissions_a = [ - "http://data.bioontology.org/ontologies/MAPPING_TEST1/submissions/latest", - "http://data.bioontology.org/ontologies/MAPPING_TEST1/submissions/latest", - "http://data.bioontology.org/ontologies/MAPPING_TEST1/submissions/latest"] - mapping_term_b = ["http://purl.org/incf/ontology/Computational_Neurosciences/cno_alpha.owl#cno_0000202", - "http://purl.org/incf/ontology/Computational_Neurosciences/cno_alpha.owl#cno_0000203", - "http://purl.org/incf/ontology/Computational_Neurosciences/cno_alpha.owl#cno_0000205"] + 'http://data.bioontology.org/ontologies/MAPPING_TEST1/submissions/latest', + 'http://data.bioontology.org/ontologies/MAPPING_TEST1/submissions/latest', + 'http://data.bioontology.org/ontologies/MAPPING_TEST1/submissions/latest'] + mapping_term_b = ['http://purl.org/incf/ontology/Computational_Neurosciences/cno_alpha.owl#cno_0000202', + 'http://purl.org/incf/ontology/Computational_Neurosciences/cno_alpha.owl#cno_0000203', + 'http://purl.org/incf/ontology/Computational_Neurosciences/cno_alpha.owl#cno_0000205'] submissions_b = [ - "http://data.bioontology.org/ontologies/MAPPING_TEST2/submissions/latest", - "http://data.bioontology.org/ontologies/MAPPING_TEST2/submissions/latest", - "http://data.bioontology.org/ontologies/MAPPING_TEST2/submissions/latest"] - relations = ["http://www.w3.org/2004/02/skos/core#exactMatch", - "http://www.w3.org/2004/02/skos/core#closeMatch", - "http://www.w3.org/2004/02/skos/core#relatedMatch"] + 'http://data.bioontology.org/ontologies/MAPPING_TEST2/submissions/latest', + 'http://data.bioontology.org/ontologies/MAPPING_TEST2/submissions/latest', + 'http://data.bioontology.org/ontologies/MAPPING_TEST2/submissions/latest'] + relations = ['http://www.w3.org/2004/02/skos/core#exactMatch', + 'http://www.w3.org/2004/02/skos/core#closeMatch', + 'http://www.w3.org/2004/02/skos/core#relatedMatch'] user = LinkedData::Models::User.where.include(:username).all[0] assert user != nil @@ -362,8 +383,8 @@ def create_rest_mapping(relation:, user:, name:, classes:) def validate_mapping(map) prop = map.source.downcase.to_sym - prop = :prefLabel if map.source == "LOOM" - prop = nil if map.source == "SAME_URI" + prop = :prefLabel if map.source == 'LOOM' + prop = nil if map.source == 'SAME_URI' classes = [] map.classes.each do |t| @@ -376,16 +397,16 @@ def validate_mapping(map) cls = cls.first classes << cls unless cls.nil? end - if map.source == "SAME_URI" + if map.source == 'SAME_URI' return classes[0].id.to_s == classes[1].id.to_s end - if map.source == "LOOM" + 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" + if map.source == 'CUI' return classes[0].cui == classes[1].cui end return false