Class: Labeling::SKOSXL::Base
- Inherits:
-
Base
- Object
- Base
- Labeling::SKOSXL::Base
show all
- Defined in:
- app/models/labeling/skosxl/base.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.build_from_rdf(rdf_subject, rdf_predicate, rdf_object) ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
|
# File 'app/models/labeling/skosxl/base.rb', line 139
def self.build_from_rdf(rdf_subject, rdf_predicate, rdf_object)
unless rdf_subject.is_a?(Concept::Base)
raise "#{self.name}#build_from_rdf: Subject (#{rdf_subject}) must be a Concept."
end
predicate_class = RDFAPI::PREDICATE_DICTIONARY[rdf_predicate] || self
predicate_class.create do |klass|
klass.owner = rdf_subject
klass.target = rdf_object
end
end
|
.by_label_language(language) ⇒ Object
14
15
16
|
# File 'app/models/labeling/skosxl/base.rb', line 14
def self.by_label_language(language)
includes(:target).references(:labels).merge(self.label_class.by_language(language))
end
|
.by_label_origin(origin) ⇒ Object
10
11
12
|
# File 'app/models/labeling/skosxl/base.rb', line 10
def self.by_label_origin(origin)
includes(:target).references(:labels).merge(self.label_class.by_origin(origin))
end
|
.create_for(o, t) ⇒ Object
22
23
24
|
# File 'app/models/labeling/skosxl/base.rb', line 22
def self.create_for(o, t)
find_or_create_by(owner_id: o.id, target_id: t.id)
end
|
.edit_partial_name(obj) ⇒ Object
131
132
133
|
# File 'app/models/labeling/skosxl/base.rb', line 131
def self.edit_partial_name(obj)
'partials/labeling/skosxl/edit_base'
end
|
.label_class ⇒ Object
31
32
33
|
# File 'app/models/labeling/skosxl/base.rb', line 31
def self.label_class
Iqvoc::XLLabel.base_class
end
|
.label_editor_selectable ⇒ Object
18
19
20
|
# File 'app/models/labeling/skosxl/base.rb', line 18
def self.label_editor_selectable
includes(:target).references(:labels).merge(self.label_class.editor_selectable)
end
|
.only_one_allowed? ⇒ Boolean
135
136
137
|
# File 'app/models/labeling/skosxl/base.rb', line 135
def self.only_one_allowed?
false
end
|
.partial_name(obj) ⇒ Object
127
128
129
|
# File 'app/models/labeling/skosxl/base.rb', line 127
def self.partial_name(obj)
'partials/labeling/skosxl/base'
end
|
.search_result_partial_name ⇒ Object
123
124
125
|
# File 'app/models/labeling/skosxl/base.rb', line 123
def self.search_result_partial_name
'partials/labeling/skosxl/search_result'
end
|
.single_query(params = {}) ⇒ Object
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
83
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
114
115
116
117
118
119
120
121
|
# File 'app/models/labeling/skosxl/base.rb', line 35
def self.single_query(params = {})
query_str = build_query_string(params)
scope = self.includes(:target)
.references(:labels, :concepts)
.joins(:target)
.order(Arel.sql("LENGTH(#{Label::Base.table_name}.value), #{Label::Base.table_name}.value ASC"))
if params[:query].present?
labels = label_class.by_query_value(query_str)
.by_language(params[:languages].to_a)
.published
scope = scope.merge(labels)
else
scope = scope.merge(label_class.by_language(params[:languages].to_a).published)
end
if params[:collection_origin].present?
collection = Iqvoc::Collection.base_class.where(origin: params[:collection_origin]).last
if collection
scope = scope.includes(owner: { collection_members: :collection })
scope = scope.where("#{Collection::Member::Base.table_name}.collection_id" => collection.id)
else
raise "Collection with Origin #{params[:collection_origin]} not found!"
end
end
scope = case params[:for]
when 'concept'
scope.includes(:owner).merge(Iqvoc::Concept.base_class.published)
when 'collection'
scope.includes(:owner).merge(Iqvoc::Collection.base_class.published)
else
scope.includes(:owner)
end
scope = if params[:include_expired]
scope.merge(Concept::Base.not_expired).or(scope.merge(Concept::Base.expired))
else
scope.merge(Concept::Base.not_expired)
end
if params[:change_note_date_from].present? || params[:change_note_date_to].present?
change_note_relation = Iqvoc.change_note_class_name.to_relation_name
concepts = Concept::Base.base_class.published
.includes(change_note_relation.to_sym => :annotations)
.references(change_note_relation)
.references('note_annotations')
concepts = case params[:change_note_type]
when 'created'
concepts.where('note_annotations.predicate = ?', 'created')
when 'modified'
concepts.where('note_annotations.predicate = ?', 'modified')
else
concepts.where('note_annotations.predicate = ? OR note_annotations.predicate = ?', 'created', 'modified')
end
if params[:change_note_date_from].present?
begin
DateTime.parse(params[:change_note_date_from])
date_from = params[:change_note_date_from]
concepts = concepts.where('note_annotations.value >= ?', date_from)
rescue ArgumentError
Rails.logger.error "Invalid date was entered for search"
end
end
if params[:change_note_date_to].present?
begin
date_to = DateTime.parse(params[:change_note_date_to]).end_of_day.to_s
concepts = concepts.where('note_annotations.value <= ?', date_to)
rescue ArgumentError
Rails.logger.error "Invalid date was entered for search"
end
end
scope = scope.includes(:owner).merge(concepts)
end
scope = yield(scope) if block_given?
scope.map { |result| SearchResult.new(result) }
end
|
.target_in_edit_mode ⇒ Object
6
7
8
|
# File 'app/models/labeling/skosxl/base.rb', line 6
def self.target_in_edit_mode
includes(:target).references(:labels).merge(Iqvoc::XLLabel.base_class.unpublished)
end
|
Instance Method Details
#<=>(other) ⇒ Object
FIXME: Hmm… Why should I sort labelings (not necessarily pref_labelings) by pref_label???
27
28
29
|
# File 'app/models/labeling/skosxl/base.rb', line 27
def <=>(other)
owner.pref_label <=> other.owner.pref_label
end
|
#build_rdf(document, subject) ⇒ Object
151
152
153
154
|
# File 'app/models/labeling/skosxl/base.rb', line 151
def build_rdf(document, subject)
subject.send(self.rdf_namespace.camelcase).send(self.rdf_predicate, IqRdf.build_uri(target.origin))
subject.Skos.send(self.rdf_predicate, target.value.to_s, lang: target.language)
end
|
#build_search_result_rdf(document, result) ⇒ Object
156
157
158
159
|
# File 'app/models/labeling/skosxl/base.rb', line 156
def build_search_result_rdf(document, result)
result.Sdc::link(IqRdf.build_uri(owner.origin))
build_rdf(document, result)
end
|