logic_mapping_population.rb revision ee5342a8882c2fc7631fcffb5497e6597747887c
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale# A logic_mapping propulation procedure.
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase#
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale# TODO Transform this code in an iterator to enable unit testing
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale#
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale# Author: Daniel Couto Vale <danielvale@uni-bremen.de>
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale#
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Valeclass LogicMappingPopulation
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale # A triple store with logic_mappings
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale @store
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale def initialize(store, logic_map)
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale @store = store
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale @logic_map = logic_map
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale end
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale def list()
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale type_iri = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type'
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale label_iri = 'http://www.w3.org/2000/01/rdf-schema#label'
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale comment_iri = 'http://www.w3.org/2000/01/rdf-schema#comment'
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale defined_iri = 'http://www.w3.org/2000/01/rdf-schema#isDefinedBy'
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale mapping_type_iri = 'http://purl.net/dol/1.0/rdf#LogicMapping'
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale default_iri = 'http://purl.net/dol/1.0/rdf#DefaultMapping'
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale maps_from_iri = 'http://purl.net/dol/1.0/rdf#mapsFrom'
b082ee0b1778a9f417c67d89247f4c3b4a29e9baChristian Clausen maps_to_iri = 'http://purl.net/dol/1.0/rdf#mapsTo'
592ea9c0e6e3018d9ef6d89e256efc0de70c71daDaniel Couto Vale status_iri = 'http://purl.net/dol/1.0/standardization#standardizationStatus'
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale faithfulness_iris = [
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale 'http://purl.net/dol/1.0/rdf#UnfaithfulMapping',
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale 'http://purl.net/dol/1.0/rdf#FaithfulMapping',
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale 'http://purl.net/dol/1.0/rdf#ModelExpansiveMapping',
592ea9c0e6e3018d9ef6d89e256efc0de70c71daDaniel Couto Vale 'http://purl.net/dol/1.0/rdf#ModelBijectiveMapping',
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale 'http://purl.net/dol/1.0/rdf#EmbeddingMapping',
592ea9c0e6e3018d9ef6d89e256efc0de70c71daDaniel Couto Vale 'http://purl.net/dol/1.0/rdf#SubLogic'
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale ]
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale theoroidalness_iris = [
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale 'http://purl.net/dol/1.0/rdf#PlainMapping',
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale 'http://purl.net/dol/1.0/rdf#SimpleTheoroidalMapping',
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale 'http://purl.net/dol/1.0/rdf#TheoroidalMapping',
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale 'http://purl.net/dol/1.0/rdf#GeneralizedMapping'
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale ]
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale exactness_iris = [
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale 'http://purl.net/dol/1.0/rdf#InexactMapping',
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale 'http://purl.net/dol/1.0/rdf#WeaklyMonoExactMapping',
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale 'http://purl.net/dol/1.0/rdf#WeaklyExactMapping',
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale 'http://purl.net/dol/1.0/rdf#ExactMapping'
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale ]
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale
08464a6b0d787688a7a3d60e22c7dc9a62e30b71Julian Kornberger mapping_iris = @store.subjects(type_iri, mapping_type_iri)
08464a6b0d787688a7a3d60e22c7dc9a62e30b71Julian Kornberger mapping_iris.map do |mapping_iri|
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale mapping_names = @store.objects(mapping_iri, label_iri)
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale mapping_defis = @store.objects(mapping_iri, defined_iri)
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale mapping_source_ids = @store.objects(mapping_iri, maps_from_iri)
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale mapping_target_ids = @store.objects(mapping_iri, maps_to_iri)
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale mapping_types = @store.objects(mapping_iri, type_iri)
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale mapping_name = mapping_names == [] ? mapping_iri : mapping_names[0]
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale mapping_defi = mapping_defis == [] ? mapping_iri : mapping_defis[0]
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale mapping_source = mapping_source_ids == [] ? nil : @logic_map[mapping_source_ids[0]]
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale mapping_target = mapping_target_ids == [] ? nil : @logic_map[mapping_target_ids[0]]
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale default = false
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale faithfulness_i = 0
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale theoroidalness_i = 0
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale exactness_i = 0
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale mapping_types.each do |type|
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale default = type == default_iri ? true : default
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale index = faithfulness_iris.index(type)
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale faithfulness_i = index != nil ? index : faithfulness_i
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale index = theoroidalness_iris.index(type)
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale theoroidalness_i = index != nil ? index : theoroidalness_i
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale index = exactness_iris.index(type)
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale exactness_i = index != nil ? index : exactness_i
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale end
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale if faithfulness_i > 2 then
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale exactness_i = 3
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale end
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase
08464a6b0d787688a7a3d60e22c7dc9a62e30b71Julian Kornberger LogicMapping.new \
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale :iri => mapping_iri,
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale #:name => mapping_name,
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale :defined_by => mapping_defi,
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale :source_id => mapping_source.iri,
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale :target_id => mapping_target.iri,
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale :source => mapping_source,
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale :target => mapping_target,
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale :default => default,
ca68055161f6beb2ec248e789ab787e6de69bd18Christian Clausen :faithfulness => LogicMapping::FAITHFULNESSES[faithfulness_i],
ca68055161f6beb2ec248e789ab787e6de69bd18Christian Clausen :theoroidalness => LogicMapping::THEOROIDALNESSES[theoroidalness_i],
ca68055161f6beb2ec248e789ab787e6de69bd18Christian Clausen :exactness => LogicMapping::EXACTNESSES[exactness_i]
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale end
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale end
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Valeend
56eec2b208d9de8883ab7be46027e358b99347a0Daniel Couto Vale