Class: Concept::SKOS::Scheme

Inherits:
Base
  • Object
show all
Defined in:
app/models/concept/skos/scheme.rb

Overview

Copyright 2011-2013 innoQ Deutschland GmbH

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build_from_rdf(rdf_subject, rdf_predicate, rdf_object) ⇒ Object



34
35
36
# File 'app/models/concept/skos/scheme.rb', line 34

def self.build_from_rdf(rdf_subject, rdf_predicate, rdf_object)
  rdf_subject.update_attribute :top_term, true
end

.create(attributes = nil, &block) ⇒ Object

Raises:

  • (TypeError)


42
43
44
45
# File 'app/models/concept/skos/scheme.rb', line 42

def self.create(attributes = nil, &block)
  raise TypeError, 'Singleton' if first
  super
end

.create!(attributes = nil, &block) ⇒ Object

Raises:

  • (TypeError)


47
48
49
50
# File 'app/models/concept/skos/scheme.rb', line 47

def self.create!(attributes = nil, &block)
  raise TypeError, 'Singleton' if first
  super
end

.instanceObject



38
39
40
# File 'app/models/concept/skos/scheme.rb', line 38

def self.instance
  first_or_create!(origin: 'scheme', published_at: Time.now)
end

.rdf_classObject



22
23
24
# File 'app/models/concept/skos/scheme.rb', line 22

def self.rdf_class
  'ConceptScheme'
end

.rdf_namespaceObject



30
31
32
# File 'app/models/concept/skos/scheme.rb', line 30

def self.rdf_namespace
  'skos'
end

.rdf_predicateObject



26
27
28
# File 'app/models/concept/skos/scheme.rb', line 26

def self.rdf_predicate
  'topConceptOf'
end

Instance Method Details

#build_rdf_subject(&block) ⇒ Object



52
53
54
55
56
# File 'app/models/concept/skos/scheme.rb', line 52

def build_rdf_subject(&block)
  ns = IqRdf::Namespace.find_namespace_class(self.class.rdf_namespace.to_sym)
  raise "Namespace '#{rdf_namespace}' is not defined in IqRdf document." unless ns
  IqRdf.build_uri(origin, ns.build_uri(self.class.rdf_class), &block)
end

#inline_top_concept_originsObject



67
68
69
# File 'app/models/concept/skos/scheme.rb', line 67

def inline_top_concept_origins
  @inline_top_concept_origins || top_concepts.map { |c| c.origin }.uniq
end

#inline_top_concept_origins=(origins) ⇒ Object



62
63
64
65
# File 'app/models/concept/skos/scheme.rb', line 62

def inline_top_concept_origins=(origins)
  @inline_top_concept_origins = origins.to_s.
    split(InlineDataHelper::SPLITTER).map(&:strip)
end

#inline_top_conceptsObject



71
72
73
74
75
76
77
# File 'app/models/concept/skos/scheme.rb', line 71

def inline_top_concepts
  if @inline_top_concept_origins
    Iqvoc::Concept.base_class.editor_selectable.where(origin: @inline_top_concept_origins)
  else
    top_concepts.select { |c| c.editor_selectable? }
  end
end

#mono_hierarchy?Boolean

Returns:

  • (Boolean)


88
89
90
91
92
# File 'app/models/concept/skos/scheme.rb', line 88

def mono_hierarchy?
  Iqvoc::Concept.broader_relation_class.new.kind_of?(
    Concept::Relation::SKOS::Broader::Mono
  )
end

#poly_hierarchy?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'app/models/concept/skos/scheme.rb', line 94

def poly_hierarchy?
  !mono_hierarchy?
end

#redeclare_top_conceptsObject



79
80
81
82
83
84
85
86
# File 'app/models/concept/skos/scheme.rb', line 79

def redeclare_top_concepts
  return if inline_top_concept_origins.nil? # There is nothing to do

  Iqvoc::Concept.base_class.transaction do
    Iqvoc::Concept.base_class.tops.update_all top_term: false
    Iqvoc::Concept.base_class.where(origin: @inline_top_concept_origins).update_all(top_term: true)
  end
end

#top_conceptsObject



58
59
60
# File 'app/models/concept/skos/scheme.rb', line 58

def top_concepts
  Iqvoc::Concept.base_class.tops
end