diff --git a/.gitignore b/.gitignore index 68d9c3f8..4045ab4b 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,5 @@ test/test_run.log test/data/ontology_files/catalog-v001.xml create_permissions.log + +ontologies_api.iml diff --git a/Gemfile b/Gemfile index fdc0aac6..9873e8a5 100644 --- a/Gemfile +++ b/Gemfile @@ -46,7 +46,7 @@ gem 'goo', github: 'ncbo/goo', branch: 'master' gem 'ncbo_annotator', github: 'ncbo/ncbo_annotator', branch: 'master' gem 'ncbo_cron', github: 'ncbo/ncbo_cron', branch: 'master' gem 'ncbo_ontology_recommender', github: 'ncbo/ncbo_ontology_recommender', branch: 'master' -gem 'ontologies_linked_data', github: 'ncbo/ontologies_linked_data', branch: 'master' +gem 'ontologies_linked_data', github: 'ontoportal-lirmm/ontologies_linked_data', branch: 'pr/feature/add-rest-mapping-bulk-loader' gem 'sparql-client', github: 'ncbo/sparql-client', branch: 'master' group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 2bea0ca4..3603c57a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -52,9 +52,19 @@ GIT redis GIT - remote: https://github.com/ncbo/ontologies_linked_data.git - revision: 8196bf34b45c75f8104bb76dfcba1db0f2c048e4 + remote: https://github.com/ncbo/sparql-client.git + revision: fb4a89b420f8eb6dda5190a126b6c62e32c4c0c9 branch: master + specs: + sparql-client (1.0.1) + json_pure (>= 1.4) + net-http-persistent (= 2.9.4) + rdf (>= 1.0) + +GIT + remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git + revision: df75e275a52071dd4083ef4ef04cc4e23772bec7 + branch: pr/feature/add-rest-mapping-bulk-loader specs: ontologies_linked_data (0.0.1) activesupport @@ -71,16 +81,6 @@ GIT rsolr rubyzip -GIT - remote: https://github.com/ncbo/sparql-client.git - revision: fb4a89b420f8eb6dda5190a126b6c62e32c4c0c9 - branch: master - specs: - sparql-client (1.0.1) - json_pure (>= 1.4) - net-http-persistent (= 2.9.4) - rdf (>= 1.0) - GIT remote: https://github.com/palexander/rack-post-body-to-params.git revision: 0fd30e710386d0cb8a3a6833d9549d7b655d5398 @@ -103,8 +103,8 @@ GEM activesupport (3.2.22.5) i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) - addressable (2.8.0) - public_suffix (>= 2.0.2, < 5.0) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) airbrussh (1.4.1) sshkit (>= 1.6.1, != 1.7.0) backports (3.23.0) @@ -131,7 +131,7 @@ GEM docile (1.4.0) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) - faraday (1.10.1) + faraday (1.10.2) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) faraday-excon (~> 1.1) @@ -159,7 +159,7 @@ GEM ffi (~> 1.0) google-apis-analytics_v3 (0.10.0) google-apis-core (>= 0.7, < 2.a) - google-apis-core (0.7.0) + google-apis-core (0.7.2) addressable (~> 2.5, >= 2.5.1) googleauth (>= 0.16.2, < 2.a) httpclient (>= 2.8.1, < 3.a) @@ -188,7 +188,7 @@ GEM json-schema (2.8.1) addressable (>= 2.4) json_pure (2.6.2) - jwt (2.4.1) + jwt (2.5.0) kgio (2.11.4) libxml-ruby (3.2.3) logger (1.5.1) @@ -213,7 +213,7 @@ GEM net-ssh (>= 2.6.5) net-ssh (7.0.1) netrc (0.11.0) - newrelic_rpm (8.9.0) + newrelic_rpm (8.10.1) oj (2.18.5) omni_logger (0.1.4) logger @@ -224,7 +224,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-accept (0.4.5) rack (>= 0.4) @@ -246,7 +246,7 @@ GEM rdf (1.0.8) addressable (>= 2.2) redcarpet (3.5.1) - redis (4.7.1) + redis (4.8.0) redis-activesupport (5.3.0) activesupport (>= 3, < 8) redis-store (>= 1.3, < 2) @@ -301,7 +301,7 @@ GEM rack-test sinatra (~> 1.4.0) tilt (>= 1.3, < 3) - sshkit (1.21.2) + sshkit (1.21.3) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) systemu (2.6.5) @@ -325,6 +325,7 @@ GEM webrick (1.7.0) PLATFORMS + x86_64-darwin-21 x86_64-linux DEPENDENCIES diff --git a/controllers/mappings_controller.rb b/controllers/mappings_controller.rb index 29e26483..65925bd3 100644 --- a/controllers/mappings_controller.rb +++ b/controllers/mappings_controller.rb @@ -11,7 +11,7 @@ class MappingsController < ApplicationController end mappings = LinkedData::Mappings.mappings_ontology(submission, - 0,0, + 0, 0, cls.id) populate_mapping_classes(mappings.to_a) reply mappings @@ -21,15 +21,15 @@ class MappingsController < ApplicationController get '/ontologies/:ontology/mappings' do ontology = ontology_from_acronym(@params[:ontology]) if ontology.nil? - error(404, "Ontology not found") + error(404, "Ontology not found") end page, size = page_params submission = ontology.latest_submission if submission.nil? - error(404, "Submission not found for ontology " + ontology.acronym) + error(404, "Submission not found for ontology " + ontology.acronym) end mappings = LinkedData::Mappings.mappings_ontology(submission, - page,size, + page, size, nil) populate_mapping_classes(mappings) reply mappings @@ -55,8 +55,8 @@ class MappingsController < ApplicationController if sub2.nil? error(404, "Submission not found for ontology " + ontologies[1].id.to_s) end - mappings = LinkedData::Mappings.mappings_ontologies(sub1,sub2, - page,size) + mappings = LinkedData::Mappings.mappings_ontologies(sub1, sub2, + page, size) populate_mapping_classes(mappings) reply mappings end @@ -70,7 +70,7 @@ class MappingsController < ApplicationController else mappings = LinkedData::Mappings.recent_rest_mappings(size + 15) populate_mapping_classes(mappings) - reply mappings[0..size-1] + reply mappings[0..size - 1] end end @@ -147,6 +147,18 @@ class MappingsController < ApplicationController reply(201, mapping) end + post '/load' do + begin + mappings = parse_bulk_load_file + loaded_mappings, errors = LinkedData::Mappings.bulk_load_mappings(mappings, current_user, check_exist: true) + response = {} + response[:created] = loaded_mappings unless loaded_mappings.empty? + response[:errors] = errors unless errors.empty? + reply(201, response) + rescue ::JSON::ParserError => e + error(404, "File parsing error: #{e.message}") + end + end # Delete a mapping delete '/:mapping' do mapping_id = RDF::URI.new(replace_url_prefix(params[:mapping])) @@ -166,9 +178,9 @@ class MappingsController < ApplicationController persistent_counts = {} f = Goo::Filter.new(:pair_count) == false LinkedData::Models::MappingCount.where.filter(f) - .include(:ontologies,:count) - .all - .each do |m| + .include(:ontologies, :count) + .all + .each do |m| persistent_counts[m.ontologies.first] = m.count end reply persistent_counts @@ -189,9 +201,9 @@ class MappingsController < ApplicationController persistent_counts = {} LinkedData::Models::MappingCount.where(pair_count: true) .and(ontologies: ontology.acronym) - .include(:ontologies,:count) - .all - .each do |m| + .include(:ontologies, :count) + .all + .each do |m| other = m.ontologies.first if other == ontology.acronym other = m.ontologies[1] diff --git a/helpers/application_helper.rb b/helpers/application_helper.rb index 18163099..75f93df0 100644 --- a/helpers/application_helper.rb +++ b/helpers/application_helper.rb @@ -421,6 +421,23 @@ def include_param_contains?(str) return class_params_include || params_include end + + ## + # Checks to see if the request has a file attached + def request_has_file? + @params.any? {|p,v| v.instance_of?(Hash) && v.key?(:tempfile) && v[:tempfile].instance_of?(Tempfile)} + end + + ## + # Looks for a file that was included as a multipart in a request + def file_from_request + @params.each do |param, value| + if value.instance_of?(Hash) && value.has_key?(:tempfile) && value[:tempfile].instance_of?(Tempfile) + return value[:filename], value[:tempfile] + end + end + return nil, nil + end private def naive_expiring_cache_write(key, object, timeout = 60) diff --git a/helpers/mappings_helper.rb b/helpers/mappings_helper.rb index e65a98d3..63b38531 100644 --- a/helpers/mappings_helper.rb +++ b/helpers/mappings_helper.rb @@ -33,6 +33,18 @@ def populate_mapping_classes(mappings) mappings end + ## + # Parse the uploaded mappings file + def parse_bulk_load_file + filename, tmpfile = file_from_request + if tmpfile + if filename.nil? + error 400, "Failure to resolve mappings json filename from upload file." + end + Array(::JSON.parse(tmpfile.read,{:symbolize_names => true})) + end + + end end end end diff --git a/helpers/ontology_helper.rb b/helpers/ontology_helper.rb index e5798ff7..898ce103 100644 --- a/helpers/ontology_helper.rb +++ b/helpers/ontology_helper.rb @@ -35,22 +35,6 @@ def create_submission(ont) ont_submission end - ## - # Checks to see if the request has a file attached - def request_has_file? - @params.any? {|p,v| v.instance_of?(Hash) && v.key?(:tempfile) && v[:tempfile].instance_of?(Tempfile)} - end - - ## - # Looks for a file that was included as a multipart in a request - def file_from_request - @params.each do |param, value| - if value.instance_of?(Hash) && value.has_key?(:tempfile) && value[:tempfile].instance_of?(Tempfile) - return value[:filename], value[:tempfile] - end - end - return nil, nil - end ## # Add a file to the submission if a file exists in the params diff --git a/test/controllers/test_mappings_controller.rb b/test/controllers/test_mappings_controller.rb index 44bfa032..d5cef2d4 100644 --- a/test/controllers/test_mappings_controller.rb +++ b/test/controllers/test_mappings_controller.rb @@ -4,7 +4,7 @@ class TestMappingsController < TestCase def self.before_suite - ["BRO-TEST-MAP-0","CNO-TEST-MAP-0","FAKE-TEST-MAP-0"].each do |acr| + ["BRO-TEST-MAP-0", "CNO-TEST-MAP-0", "FAKE-TEST-MAP-0"].each do |acr| LinkedData::Models::OntologySubmission.where(ontology: [acronym: acr]).to_a.each do |s| s.delete end @@ -14,29 +14,29 @@ def self.before_suite end end LinkedData::SampleData::Ontology.create_ontologies_and_submissions({ - process_submission: true, - acronym: "BRO-TEST-MAP", - name: "BRO-TEST-MAP", - file_path: "./test/data/ontology_files/BRO_v3.2.owl", - ont_count: 1, - submission_count: 1 - }) + process_submission: true, + acronym: "BRO-TEST-MAP", + name: "BRO-TEST-MAP", + file_path: "./test/data/ontology_files/BRO_v3.2.owl", + ont_count: 1, + submission_count: 1 + }) LinkedData::SampleData::Ontology.create_ontologies_and_submissions({ - process_submission: true, - acronym: "CNO-TEST-MAP", - name: "CNO-TEST-MAP", - file_path: "./test/data/ontology_files/CNO_05.owl", - ont_count: 1, - submission_count: 1 - }) + process_submission: true, + acronym: "CNO-TEST-MAP", + name: "CNO-TEST-MAP", + file_path: "./test/data/ontology_files/CNO_05.owl", + ont_count: 1, + submission_count: 1 + }) LinkedData::SampleData::Ontology.create_ontologies_and_submissions({ - process_submission: true, - acronym: "FAKE-TEST-MAP", - name: "FAKE-TEST-MAP", - file_path: "./test/data/ontology_files/fake_for_mappings.owl", - ont_count: 1, - submission_count: 1 - }) + process_submission: true, + acronym: "FAKE-TEST-MAP", + name: "FAKE-TEST-MAP", + file_path: "./test/data/ontology_files/fake_for_mappings.owl", + ont_count: 1, + submission_count: 1 + }) NcboCron::Models::QueryWarmer.new(Logger.new(TestLogFile.new)).run end @@ -54,6 +54,91 @@ def test_mappings_controllers_in_order mappings_statistics_for_ontology end + def test_mappings_file_load + LinkedData::Models::RestBackupMapping.all.each do |m| + LinkedData::Mappings.delete_rest_mapping(m.id) + end + + mappings, mapping_ont_a, mapping_ont_b, mapping_term_a, mapping_term_b, relations = build_mappings_hash(old_style: false) + file = Tempfile.open do |file| + file.write(mappings.to_json) + file.rewind + file + end + + user = User.all.first + user.bring :apikey + + header 'Authorization', "apikey token=#{user.apikey}" + post '/mappings/load', + file: Rack::Test::UploadedFile.new(file.to_path, 'application/json') + + assert last_response.status == 201 + response = MultiJson.load(last_response.body) + created = response["created"] + + LinkedData::Mappings.create_mapping_counts(Logger.new(TestLogFile.new)) + commun_created_mappings_test(created, mapping_ont_a, mapping_ont_b, + mapping_term_a, mapping_term_b, relations) + end + + private + + def commun_created_mappings_test(created, mapping_ont_a, mapping_ont_b, mapping_term_a, mapping_term_b, relations) + assert_equal 3, created.size + created.each_with_index do |mapping, i| + + assert_equal "comment for mapping test #{i}", mapping["process"]["comment"] + refute_nil mapping["process"]["creator"]["users/tim"] + assert_equal [relations[i]], mapping["process"]["relation"] + refute_nil mapping["process"]["date"] + + mapping["classes"].each do |cls| + if cls["links"]["ontology"].split("/")[-1] == mapping_ont_a[i] + assert_equal mapping_term_a[i], cls["@id"] + elsif cls["links"]["ontology"].split("/")[-1] == mapping_ont_b[i] + assert_equal mapping_term_b[i], cls["@id"] + else + assert 1 == 0, 'uncontrolled mapping response in post' + end + end + end + + #there three mappings in BRO with processes + NcboCron::Models::QueryWarmer.new(Logger.new(TestLogFile.new)).run + ontology = "BRO-TEST-MAP-0" + get "/ontologies/#{ontology}/mappings?pagesize=1000&page=1" + assert last_response.ok? + mappings = MultiJson.load(last_response.body) + mappings = mappings["collection"] + assert_equal 21, mappings.length + rest_count = 0 + mappings.each do |x| + if x["process"] != nil + rest_count += 1 + #assert x["@id"] != nil + end + end + assert rest_count == 3 + + get "/mappings/recent/" + assert last_response.status == 200 + response = MultiJson.load(last_response.body) + assert (response.length == 5) + date = nil + response.each do |x| + assert x["@id"] != nil + assert x["classes"].length == 2 + assert x["process"] != nil + date_x = DateTime.iso8601(x["process"]["date"]) + if date + assert date >= date_x + end + date = date_x + end + + end + def mappings_for_ontology LinkedData::Models::RestBackupMapping.all.each do |m| LinkedData::Mappings.delete_rest_mapping(m.id) @@ -162,7 +247,7 @@ def mappings_with_display get "/ontologies/#{ontology}/mappings?pagesize=#{pagesize}&page=#{page}&display=prefLabel" assert last_response.ok? mappings = MultiJson.load(last_response.body) - assert mappings["collection"].all? {|m| m["classes"].all? {|c| c["prefLabel"].is_a?(String) && c["prefLabel"].length > 0} } + assert mappings["collection"].all? { |m| m["classes"].all? { |c| c["prefLabel"].is_a?(String) && c["prefLabel"].length > 0 } } def_count = 0 next_page = 1 @@ -170,7 +255,7 @@ def mappings_with_display get "/ontologies/#{ontology}/mappings?pagesize=#{pagesize}&page=#{next_page}&display=prefLabel,definition" assert last_response.ok? mappings = MultiJson.load(last_response.body) - def_count += mappings["collection"].map {|m| m["classes"].map {|c| (c["definition"] || []).length }}.flatten.sum + def_count += mappings["collection"].map { |m| m["classes"].map { |c| (c["definition"] || []).length } }.flatten.sum next_page = mappings["nextPage"] end while (next_page) assert 10, def_count @@ -192,88 +277,24 @@ def create_mapping LinkedData::Models::RestBackupMapping.all.each do |m| LinkedData::Mappings.delete_rest_mapping(m.id) end + mappings, mapping_ont_a, mapping_ont_b, mapping_term_a, mapping_term_b, relations = build_mappings_hash + created = [] - 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_ont_a = ["BRO-TEST-MAP-0","BRO-TEST-MAP-0","BRO-TEST-MAP-0"] - - - 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" ] - mapping_ont_b = ["CNO-TEST-MAP-0","CNO-TEST-MAP-0","CNO-TEST-MAP-0"] - - 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" ] - - 3.times do |i| - classes = {} - classes[mapping_term_a[i]] = mapping_ont_a[i] - classes[mapping_term_b[i]] = mapping_ont_b[i] - - mapping = { classes: classes, - comment: "comment for mapping test #{i}", - relation: relations[i], - creator: "http://data.bioontology.org/users/tim" - } - - post "/mappings/", - MultiJson.dump(mapping), - "CONTENT_TYPE" => "application/json" + mappings.each_with_index do |mapping, i| + post '/mappings/', + MultiJson.dump(mapping), + "CONTENT_TYPE" => "application/json" assert last_response.status == 201 - response = MultiJson.load(last_response.body) - assert response["process"]["comment"] == "comment for mapping test #{i}" - assert response["process"]["creator"]["users/tim"] - assert response["process"]["relation"] == relations[i] - assert response["process"]["date"] != nil - response["classes"].each do |cls| - if cls["links"]["ontology"].split("/")[-1] == mapping_ont_a[i] - assert cls["@id"] == mapping_term_a[i] - elsif cls["links"]["ontology"].split("/")[-1] == mapping_ont_b[i] - assert cls["@id"] == mapping_term_b[i] - else - assert 1==0, "uncontrolled mapping response in post" - end - end + created << MultiJson.load(last_response.body) # to ensure different in times in dates. Later test on recent mappings sleep(1.2) end - #there three mappings in BRO with processes - NcboCron::Models::QueryWarmer.new(Logger.new(TestLogFile.new)).run - ontology = "BRO-TEST-MAP-0" - get "/ontologies/#{ontology}/mappings?pagesize=1000&page=1" - assert last_response.ok? - mappings = MultiJson.load(last_response.body) - mappings = mappings["collection"] - assert mappings.length == 21 - rest_count = 0 - mappings.each do |x| - if x["process"] != nil - rest_count += 1 - #assert x["@id"] != nil - end - end - assert rest_count == 3 + commun_created_mappings_test(created, mapping_ont_a, + mapping_ont_b, mapping_term_a, + mapping_term_b, relations) - get "/mappings/recent/" - assert last_response.status == 200 - response = MultiJson.load(last_response.body) - assert (response.length == 5) - date = nil - response.each do |x| - assert x["@id"] != nil - assert x["classes"].length == 2 - assert x["process"] != nil - date_x = DateTime.iso8601(x["process"]["date"]) - if date - assert date >= date_x - end - date = date_x - end end def delete_mapping @@ -284,24 +305,23 @@ def delete_mapping rest_predicate = LinkedData::Mappings.mapping_predicates()["REST"][0] epr = Goo.sparql_query_client(:main) epr.query("SELECT (count(?s) as ?c) WHERE { ?s <#{rest_predicate}> ?o . }") - .each do |sol| + .each do |sol| assert sol[:c].object == 0 end 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_ont_a = ["BRO-TEST-MAP-0","BRO-TEST-MAP-0","BRO-TEST-MAP-0"] - + "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Image", + "http://bioontology.org/ontologies/BiomedicalResourceOntology.owl#Integration_and_Interoperability_Tools"] + mapping_ont_a = ["BRO-TEST-MAP-0", "BRO-TEST-MAP-0", "BRO-TEST-MAP-0"] 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" ] - mapping_ont_b = ["CNO-TEST-MAP-0","CNO-TEST-MAP-0","CNO-TEST-MAP-0"] + "http://purl.org/incf/ontology/Computational_Neurosciences/cno_alpha.owl#cno_0000203", + "http://purl.org/incf/ontology/Computational_Neurosciences/cno_alpha.owl#cno_0000205"] + mapping_ont_b = ["CNO-TEST-MAP-0", "CNO-TEST-MAP-0", "CNO-TEST-MAP-0"] - 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" ] + 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"] 3.times do |i| classes = {} @@ -315,8 +335,8 @@ def delete_mapping } post "/mappings/", - MultiJson.dump(mapping), - "CONTENT_TYPE" => "application/json" + MultiJson.dump(mapping), + "CONTENT_TYPE" => "application/json" assert last_response.status == 201 response = MultiJson.load(last_response.body) @@ -330,7 +350,7 @@ def delete_mapping elsif cls["links"]["ontology"].split("/")[-1] == mapping_ont_b[i] assert cls["@id"] == mapping_term_b[i] else - assert 1==0, "uncontrolled mapping response in post" + assert 1 == 0, "uncontrolled mapping response in post" end end sleep(1.2) # to ensure different in times in dates. Later test on recent mappings @@ -352,7 +372,7 @@ def delete_mapping epr = Goo.sparql_query_client(:main) epr.query("SELECT (count(?s) as ?c) WHERE { ?s <#{rest_predicate}> ?o . }") - .each do |sol| + .each do |sol| assert sol[:c].object == 0 end end @@ -392,4 +412,40 @@ def mappings_statistics_for_ontology assert_equal 9, stats["CNO-TEST-MAP-0"] end + def build_mappings_hash(old_style: true) + # old_style is to remove when update and harmonize how we post a rest mapping + 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_ont_a = ["BRO-TEST-MAP-0", "BRO-TEST-MAP-0", "BRO-TEST-MAP-0"] + + 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"] + mapping_ont_b = ["CNO-TEST-MAP-0", "CNO-TEST-MAP-0", "CNO-TEST-MAP-0"] + + 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"] + + mappings = [] + 3.times do |i| + + if old_style + classes = {} + classes[mapping_term_a[i]] = mapping_ont_a[i] + classes[mapping_term_b[i]] = mapping_ont_b[i] + else + classes = [mapping_term_a[i], mapping_term_b[i]] + end + + mappings << { classes: classes, + name: "name for mapping test #{i}", + comment: "comment for mapping test #{i}", + relation: relations[i], + creator: "http://data.bioontology.org/users/tim" + } + end + [mappings, mapping_ont_a, mapping_ont_b, mapping_term_a, mapping_term_b, relations] + end end