ontology.rb revision dca00e3e210f3a3f814c63511f426128b1f3308c
380N/A # Ontohub Library Includes 214N/A # Ontology Model Includes 214N/A # Multiple Class Features ("ontology_versions"."file_extension" = :extname) OR (("ontology_versions"."file_extension" IS NULL) AND ("ontologies"."file_extension" = :extname)) with_basepath(File.basepath(path)). where(condition, extname: File.extname(path)). scope :with_basepath, ->(path) do LEFT JOIN "ontology_versions" ON "ontologies"."ontology_version_id" = "ontology_versions"."id" ("ontology_versions"."basepath" = :path) OR (("ontology_versions"."basepath" IS NULL) AND ("ontologies"."basepath" = :path)) joins(join).where(condition, path: path).readonly(false) scope :parents_first, order('(CASE WHEN ontologies.parent_id IS NULL THEN 1 ELSE 0 END) DESC, ontologies.parent_id asc') :// # A uri has a separation between schema and hierarchy (?<filename>[^/]+) # Match filename after a slash/hash filename = match[:filename].sub(/\.[\w\d]+\z/, '') capitalized_name = filename.split(/[_ ]/).map(&:capitalize).join(' ') def iri_for_child(child_name) child_name = child_name[1..-2] if child_name[0] == '<' child_name.include?("://") ? child_name : "#{iri}?#{child_name}" self.logic ? (self.logic.name == logic_name) : false self.is?('OWL') || self.is?('OWL2') def self.find_with_iri(iri) ontology = where('iri LIKE ?', '%' << iri).first ontology = AlternativeIri.where('iri LIKE ?', '%' << iri). def is_imported_from_other_repository? import_links_from_other_repositories.present? import_links.map(&:source) def destroy_with_parent(user) repository.delete_file(parent.path, user, "Delete #{Settings.OMS} #{parent}") do repository.delete_file(path, user, "Delete #{Settings.OMS} #{self}") do # if repository destroying, then check if imported externally (!repository.is_destroying? || is_imported_from_other_repository?) raise Ontology::DeleteError fetch_links_by_kind(self, 'import') def contains_logic_translations? query, args = contains_logic_translations_query(self) pluck_select([query, *args], :logically_translated).size > 1 def direct_imported_ontologies ontology_ids = Link.where(target_id: self, kind: 'import'). Ontology.where(id: ontology_ids) affected_ontology_ids = [self.id] + imported_ontologies.pluck(:id) Sentence.where(ontology_id: affected_ontology_ids) # list all sentences defined on this ontology, # those who are self defined and those which # are imported (ImpAxioms) where(ontology_id: self). where('imported = ? OR imported = ?', true, false) where(ontology_id: self). where('imported = ?', true) has_versions? ? current_version.basepath : read_attribute(:basepath) has_versions? ? current_version.file_extension : read_attribute(:file_extension) "#{basepath}#{file_extension}" repository.get_file(path) Link.where(source_id: self.id, kind: "import") def import_links_from_other_repositories import_links.select { |l| l.target.repository != self.repository }