Class: Concept::Relation::SKOS::Base

Inherits:
Base show all
Defined in:
app/models/concept/relation/skos/base.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

Methods inherited from Base

bidirectional?, by_owner, by_owner_origin, by_target_origin, edit_partial_name, partial_name, published, published_with_newer_versions, #rank, #rank=, rankable?, reverse_relation_class, singular?, target_editor_selectable, target_in_edit_mode, unpublished, view_section, view_section_sort_key

Class Method Details

.build_from_rdf(rdf_subject, rdf_predicate, rdf_object) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/concept/relation/skos/base.rb', line 20

def self.build_from_rdf(rdf_subject, rdf_predicate, rdf_object)
  raise "#{self.name}#build_from_rdf: Subject (#{rdf_subject}) must be a Concept." unless rdf_subject.is_a? Concept::Base
  raise "#{self.name}#build_from_rdf: Object (#{rdf_object}) must be a Concept."   unless rdf_object.is_a? Concept::Base

  relation_class = RDFAPI::PREDICATE_DICTIONARY[rdf_predicate] || self

  relation_instance = rdf_subject.send(self.name.to_relation_name).select{ |rel| rel.target == rdf_object }
  if relation_instance.empty?
    relation_instance = relation_class.new(target: rdf_object)
    rdf_subject.send(self.name.to_relation_name) << relation_instance
  end

  if relation_class.bidirectional?
    reverse_class      = relation_class.reverse_relation_class
    reverse_collection = rdf_object.send(reverse_class.name.to_relation_name)
    if reverse_collection.select{ |rel| rel.target == rdf_subject }.empty?
      reverse_instance = reverse_class.new(target: rdf_subject)
      reverse_collection << reverse_instance
    end
  end
end

Instance Method Details

#build_rdf(document, subject, suppress_extra_labels = false) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/concept/relation/skos/base.rb', line 42

def build_rdf(document, subject, suppress_extra_labels = false)
  subject.send(self.rdf_namespace.camelcase).send(self.rdf_predicate, IqRdf.build_uri(target.origin))

  # Auto-include preferred labels for referenced concepts
  unless suppress_extra_labels
    document << IqRdf::build_uri(target.origin) do |subject|
      target.pref_labelings.each do |labeling|
        subject.Skos.send(labeling.rdf_predicate, labeling.target.value.to_s,
            lang: labeling.target.language)
      end
    end
  end
end