dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksaclass Ontology
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa module OwlClasses
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa extend ActiveSupport::Concern
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa class Error < ::StandardError; end
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa class WrongLogicError < Error; end
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa def superclass_of?(superclass, subclass)
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa check_logic_is_owl
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa superclasses(subclass).include?(superclass)
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa end
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa def superclasses(cls)
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa check_logic_is_owl
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa result = []
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa direct_superclasses(cls).each do |superclass|
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa result << superclass
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa result += superclasses(superclass)
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa end
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa result.uniq
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa end
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa def direct_superclasses(cls)
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa check_logic_is_owl
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa result = []
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa sentences.where('text LIKE ?', "Class: #{cls}%SubClassOf:%").
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa each do |sentence|
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa match = sentence.text.match(/SubClassOf: (?<superclass>\w+)\z/)
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa result << match[:superclass] if match
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa end
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa result
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa end
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa def subclasses(cls)
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa check_logic_is_owl
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa result = []
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa direct_subclasses(cls).each do |subclass|
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa result << subclass
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa result += subclasses(subclass)
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa end
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa result.uniq
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa end
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa def direct_subclasses(cls)
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa check_logic_is_owl
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa result = []
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa sentences.where('text LIKE ?', "Class: %SubClassOf: #{cls}").
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa each do |sentence|
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa match = sentence.text.match(/^Class: (?<subclass>\w+)/)
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa result << match[:subclass] if match
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa end
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa result
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa end
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa protected
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa def check_logic_is_owl
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa raise WrongLogicError('Expected OWL') unless logic.name.start_with?('OWL')
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa end
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksa end
dca00e3e210f3a3f814c63511f426128b1f3308cEugen Kuksaend