Module: RdfHelper

Included in:
SkosExporter
Defined in:
app/helpers/rdf_helper.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.

Instance Method Summary collapse

Instance Method Details

#render_collection(document, collection) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/helpers/rdf_helper.rb', line 84

def render_collection(document, collection)
  # You can not eager load polymorphic associations. That's why we're loading
  # the collections _one_ time and remember them for further _render_concept_
  # calls in the future.
  @rdf_helper_cached_collections ||= Iqvoc::Collection.base_class.select('id, origin').load.each_with_object({}) do |c, hash|
    hash[c.id] = c.origin
  end

  document << collection.build_rdf_subject do |c|

    collection.labelings.each do |labeling|
      labeling.build_rdf(document, c)
    end

    if Iqvoc::rdf_show_change_notes
      collection.note_skos_definitions.each do |note|
        note.build_rdf(document, c)
      end
    end

    collection.concepts.each do |concept|
      c.Skos::member(IqRdf.build_uri(concept.origin))
    end

    collection.subcollections.each do |subcollection|
      c.Skos::member(IqRdf.build_uri(subcollection.origin))
    end

  end
end

#render_concept(document, concept, suppress_extra_labels = false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'app/helpers/rdf_helper.rb', line 32

def render_concept(document, concept, suppress_extra_labels = false)
  # You can not eager load polymorphic associations. That's why we're loading
  # the collections _one_ time and remember them for further _render_concept_
  # calls in the future.
  @rdf_helper_cached_collections ||= Iqvoc::Collection.base_class.select('id, origin').load.each_with_object({}) do |c, hash|
    hash[c.id] = c.origin
  end

  document << concept.build_rdf_subject do |c|

    concept.collection_members.each do |collection_member|
      if @rdf_helper_cached_collections[collection_member.collection_id]
        c.Schema::memberOf(IqRdf.build_uri(@rdf_helper_cached_collections[collection_member.collection_id]))
      end
    end

    c.Schema::expires(concept.expired_at.to_s) if concept.expired_at
    c.Owl::deprecated(true) if concept.expired?

    c.Skos::topConceptOf IqRdf.build_uri(Iqvoc::Concept.root_class.instance.origin) if concept.top_term?
    c.Skos::inScheme IqRdf.build_uri(Iqvoc::Concept.root_class.instance.origin)

    concept.labelings.each do |labeling|
      labeling.build_rdf(document, c)
    end

    concept.relations.each do |relation|
      relation.build_rdf(document, c, suppress_extra_labels)
    end

    if Iqvoc::rdf_show_change_notes
      concept.notes.each do |note|
        note.build_rdf(document, c)
      end
    end

    concept.matches.each do |match|
      match.build_rdf(document, c)
    end

    concept.notations.each do |notation|
      notation.build_rdf(document, c)
    end

    Iqvoc::Concept.additional_association_class_names.keys.each do |class_name|
      concept.send(class_name.to_relation_name).each do |additional_object|
        additional_object.build_rdf(document, c)
      end
    end
  end
end

#render_scheme(document, scheme, top_concepts) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/rdf_helper.rb', line 18

def render_scheme(document, scheme, top_concepts)

  document << scheme.build_rdf_subject do |s|
    scheme.pref_labels.each do |pl|
      s.Dct::title pl.value, lang: pl.language
    end

    top_concepts.each do |top_concept|
      s.Skos::hasTopConcept IqRdf.build_uri(top_concept.origin)
    end
  end

end