Class: Labeling::SKOS::Base
- Inherits:
-
Base
- Object
- Base
- Labeling::SKOS::Base
show all
- Defined in:
- app/models/labeling/skos/base.rb
Overview
Copyright 2011 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(subject, predicate, object) ⇒ Object
84
85
86
87
88
89
90
91
92
|
# File 'app/models/labeling/skos/base.rb', line 84
def self.build_from_rdf(subject, predicate, object)
raise "Labeling::SKOS::Base#build_from_rdf: Subject (#{subject}) must be a Concept." unless subject.is_a?(Concept::Base)
raise "Labeling::SKOS::Base#build_from_rdf: Object (#{object}) must be a string literal" unless object =~ /^"(.+)"(@(.+))?$/
lang = $3
value = JSON.parse(%Q{["#{$1}"]})[0].gsub("\\n", "\n")
subject.send(self.name.to_relation_name) << self.new(:target => self.label_class.new(:value => value, :language => lang))
end
|
.by_label_with_language(label, language) ⇒ Object
27
28
29
|
# File 'app/models/labeling/skos/base.rb', line 27
def self.by_label_with_language(label, language)
includes(:target).merge(self.label_class.where(:value => label, :language => language))
end
|
.edit_partial_name(obj) ⇒ Object
41
42
43
|
# File 'app/models/labeling/skos/base.rb', line 41
def self.edit_partial_name(obj)
"partials/labeling/skos/edit_base"
end
|
.label_class ⇒ Object
33
34
35
|
# File 'app/models/labeling/skos/base.rb', line 33
def self.label_class
Iqvoc::Label.base_class
end
|
.partial_name(obj) ⇒ Object
37
38
39
|
# File 'app/models/labeling/skos/base.rb', line 37
def self.partial_name(obj)
"partials/labeling/skos/base"
end
|
.search_result_partial_name ⇒ Object
80
81
82
|
# File 'app/models/labeling/skos/base.rb', line 80
def self.search_result_partial_name
'partials/labeling/skos/search_result'
end
|
.single_query(params = {}) ⇒ Object
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
|
# File 'app/models/labeling/skos/base.rb', line 45
def self.single_query(params = {})
query_str = build_query_string(params)
scope = includes(:target).order("LOWER(#{Label::Base.table_name}.value)")
if params[:query].present?
scope = scope.merge(Label::Base.by_query_value(query_str).by_language(params[:languages].to_a).published)
else
scope = scope.merge(Label::Base.by_language(params[:languages].to_a).published)
end
if params[:collection_origin].present?
collection = Collection::Unordered.where(:origin => params[:collection_origin]).last
if collection
scope = scope.includes(:owner => :collection_members)
scope = scope.where("#{Collection::Member::Base.table_name}.collection_id" => collection)
else
raise "Collection with Origin #{params[:collection_origin]} not found!"
end
end
scope = scope.includes(:owner)
scope = case params[:for]
when "concept"
scope.where("concepts.type" => Iqvoc::Concept.base_class_name).merge(Concept::Base.published)
when "collection"
scope.where("concepts.type" => Iqvoc::Collection.base_class_name)
else
scope
end
scope
end
|
Instance Method Details
#build_rdf(document, subject) ⇒ Object
94
95
96
|
# File 'app/models/labeling/skos/base.rb', line 94
def build_rdf(document, subject)
subject.send(self.rdf_namespace.camelcase).send(self.rdf_predicate, target.to_s, :lang => target.language)
end
|
#build_search_result_rdf(document, result) ⇒ Object
98
99
100
101
|
# File 'app/models/labeling/skos/base.rb', line 98
def build_search_result_rdf(document, result)
result.Sdc::link(IqRdf.build_uri(owner.origin))
build_rdf(document, result)
end
|