mapping.rb revision dd257332b837f66515fb11c8d4f3b15fe712f7bf
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenclass Mapping < ActiveRecord::Base
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen include Permissionable
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen include Metadatable
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen KINDS = %w( import alignment view hiding minimization cofree free )
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen DEFAULT_MAPPING_KIND = KINDS.first
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen KINDS_MAPPING = {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen 'GlobalDef' => 'import',
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen 'GlobalDefInc' => 'import',
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen 'Thm' => 'view',
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen CONS_STATUSES = %w( inconsistent none cCons mcons mono def )
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen belongs_to :ontology
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen belongs_to :source, class_name: 'Ontology'
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen belongs_to :target, class_name: 'Ontology'
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen belongs_to :logic_mapping
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen belongs_to :mapping_version
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen has_many :symbol_mappings
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen has_many :versions,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen :dependent => :destroy,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen :order => :version_number,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen :class_name => 'MappingVersion' do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def current
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen reorder('version_number DESC').first
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen attr_accessible :iri, :source, :target, :kind, :theorem, :proven, :local,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen :inclusion, :logic_mapping, :parent, :ontology_id, :source_id,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen :target_id, :versions_attributes, :versions, :name
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen accepts_nested_attributes_for :versions
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def self.with_ontology_reference(ontology_id)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen Mapping.where('ontology_id = ? OR source_id = ? OR target_id = ?',
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ontology_id, ontology_id, ontology_id)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def current_version
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if self.mapping_version
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen self.mapping_version
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen else
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen self.versions.current
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def update_version!(to: nil)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen self.mapping_version_id = to ? to.id : versions.current.id
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen save!
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def to_s
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen string = ""
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen if name
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen string = name
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen else
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen array = iri.split("?")
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen string = array.last
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen end
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen string
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen def display_connection
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if theorem
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen if proven
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "badge badge-success"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen else
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "badge badge-important"
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen end
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen else
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen "badge badge-inverse"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen def get_symbol
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen if symbol_mappings.size > 1
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen "#{symbol_mappings.first}..."
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen else
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen "#{symbol_mappings.first}"
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenend
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen