Class: Concept::Base
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 Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#distinct_versions, #origin_has_to_be_escaped
#exclusive_pref_label, #exclusive_top_term, #pref_label_in_primary_thesaurus_language, #rooted_top_terms, #unique_alt_labels, #unique_pref_label, #unique_pref_label_language, #valid_rank_for_ranked_relations
Methods included from Versioning
#branch, #disable_validations_for_publishing, #editor_selectable?, #enable_validations_for_publishing, #in_review?, #lock_by_user, #locked?, #publish, #publish!, #publishable?, #published?, #state, #to_review, #unlock, #unpublish, #unpublished?, #validatable_for_publishing?, #with_validations_for_publishing
Instance Attribute Details
#reverse_match_service ⇒ Object
Returns the value of attribute reverse_match_service.
18
19
20
|
# File 'app/models/concept/base.rb', line 18
def reverse_match_service
@reverse_match_service
end
|
Class Method Details
.broader_tops ⇒ Object
313
314
315
316
317
318
|
# File 'app/models/concept/base.rb', line 313
def self.broader_tops
includes(:narrower_relations, :pref_labels).
where(concept_relations: { id: nil },
labelings: { type: Iqvoc::Concept.pref_labeling_class_name }).
order("LOWER(#{Label::Base.table_name}.value)")
end
|
.edit_link_partial_name ⇒ Object
351
352
353
|
# File 'app/models/concept/base.rb', line 351
def self.edit_link_partial_name
'partials/concept/edit_link_base'
end
|
.for_dashboard ⇒ Object
332
333
334
|
# File 'app/models/concept/base.rb', line 332
def self.for_dashboard
unpublished_or_follow_up.includes(:pref_labels, :locking_user)
end
|
.inline_partial_name ⇒ Object
343
344
345
|
# File 'app/models/concept/base.rb', line 343
def self.inline_partial_name
'partials/concept/inline_base'
end
|
.new_link_partial_name ⇒ Object
347
348
349
|
# File 'app/models/concept/base.rb', line 347
def self.new_link_partial_name
'partials/concept/new_link_base'
end
|
.parentless ⇒ Object
336
337
338
339
340
|
# File 'app/models/concept/base.rb', line 336
def self.parentless
includes(:broader_relations)
.where(concept_relations: {owner_id: nil}, top_term: false)
.references(:concept_relations)
end
|
.tops ⇒ Object
309
310
311
|
# File 'app/models/concept/base.rb', line 309
def self.tops
where(top_term: true)
end
|
.with_associations ⇒ Object
320
321
322
323
324
|
# File 'app/models/concept/base.rb', line 320
def self.with_associations
includes([
{ labelings: :target }, :relations, :matches, :notes, :notations
])
end
|
.with_pref_labels ⇒ Object
326
327
328
329
330
|
# File 'app/models/concept/base.rb', line 326
def self.with_pref_labels
includes(:pref_labels).
order("LOWER(#{Label::Base.table_name}.value)").
where(labelings: { type: Iqvoc::Concept.pref_labeling_class_name }) end
|
Instance Method Details
#additional_info ⇒ Object
This shows up (in brackets) to the right of a concept link if it doesn’t return nil
462
463
464
|
# File 'app/models/concept/base.rb', line 462
def additional_info
nil
end
|
#assigned_collection_origins ⇒ Object
398
399
400
|
# File 'app/models/concept/base.rb', line 398
def assigned_collection_origins
@assigned_collection_origins || collections.map(&:origin).uniq
end
|
#assigned_collection_origins=(origins) ⇒ Object
393
394
395
396
|
# File 'app/models/concept/base.rb', line 393
def assigned_collection_origins=(origins)
@assigned_collection_origins= origins.to_s
.split(InlineDataHelper::SPLITTER).map(&:strip)
end
|
#associated_objects_in_editing_mode ⇒ Object
474
475
476
477
478
|
# File 'app/models/concept/base.rb', line 474
def associated_objects_in_editing_mode
{
concept_relations: Concept::Relation::Base.by_owner(id).target_in_edit_mode,
}
end
|
#concept_relations_by_id(relation_name) ⇒ Object
382
383
384
385
386
|
# File 'app/models/concept/base.rb', line 382
def concept_relations_by_id(relation_name)
(@concept_relations_by_id && @concept_relations_by_id[relation_name]) ||
self.send(relation_name).map { |l| l.target.origin }.
join(InlineDataHelper::JOINER)
end
|
#concept_relations_by_id=(hash) ⇒ Object
378
379
380
|
# File 'app/models/concept/base.rb', line 378
def concept_relations_by_id=(hash)
@concept_relations_by_id = hash
end
|
#concept_relations_by_id_and_rank(relation_name) ⇒ Object
388
389
390
391
|
# File 'app/models/concept/base.rb', line 388
def concept_relations_by_id_and_rank(relation_name)
self.send(relation_name).each_with_object({}) { |rel, hsh| hsh[rel.target] = rel.rank }
end
|
#jobs ⇒ Object
480
481
482
483
|
# File 'app/models/concept/base.rb', line 480
def jobs
gid = self.to_global_id.to_s
Delayed::Backend::ActiveRecord::Job.where(delayed_global_reference_id: gid)
end
|
#labelings_by_text(relation_name, language) ⇒ Object
371
372
373
374
375
376
|
# File 'app/models/concept/base.rb', line 371
def labelings_by_text(relation_name, language)
(@labelings_by_text && @labelings_by_text[relation_name] &&
@labelings_by_text[relation_name][language]) ||
InlineDataHelper.generate_inline_values(self.send(relation_name).
by_label_language(language).map { |l| l.target.value })
end
|
#labelings_by_text=(hash) ⇒ Object
357
358
359
360
361
362
363
364
365
366
367
368
369
|
# File 'app/models/concept/base.rb', line 357
def labelings_by_text=(hash)
@labelings_by_text = hash
@labelings_by_text.each do |relation_name, labels_by_lang|
if labels_by_lang.is_a?(Array)
@labelings_by_text[relation_name] = { nil => labels_by_lang.first }
end
end
@labelings_by_text
end
|
#labels_for_labeling_class_and_language(labeling_class, lang = :en, only_published = true) ⇒ Object
424
425
426
427
428
429
430
431
432
433
434
435
436
437
|
# File 'app/models/concept/base.rb', line 424
def labels_for_labeling_class_and_language(labeling_class, lang = :en, only_published = true)
if lang == 'none'
lang = nil
elsif lang
lang = lang.to_s
end
labeling_class = labeling_class.name if labeling_class < ActiveRecord::Base @labels ||= labelings.each_with_object({}) do |labeling, hash|
((hash[labeling.class.name.to_s] ||= {})[labeling.target.language] ||= []) << labeling.target if labeling.target
end
((@labels && @labels[labeling_class] && @labels[labeling_class][lang]) || []).select{ |l| l.published? || !only_published }.sort_by(&:value)
end
|
#matches_for_class(match_class) ⇒ Object
445
446
447
448
|
# File 'app/models/concept/base.rb', line 445
def matches_for_class(match_class)
match_class = match_class.name if match_class < ActiveRecord::Base matches.select{ |match| match.class.name == match_class }
end
|
#notations_for_class(notation_class) ⇒ Object
455
456
457
458
|
# File 'app/models/concept/base.rb', line 455
def notations_for_class(notation_class)
notation_class = notation_class.name if notation_class < ActiveRecord::Base notations.select{ |notation| notation.class.name == notation_class }
end
|
#notes_for_class(note_class) ⇒ Object
450
451
452
453
|
# File 'app/models/concept/base.rb', line 450
def notes_for_class(note_class)
note_class = note_class.name if note_class < ActiveRecord::Base notes.select{ |note| note.class.name == note_class }
end
|
#pref_label ⇒ Object
returns the (one!) preferred label of a concept for the requested language. lang can either be a (lowercase) string or symbol with the (ISO .…) two letter code of the language (e.g. :en for English, :fr for French, :de for German). If no prefLabel for the requested language exists, a new label will be returned (if you modify it, don’t forget to save it afterwards!)
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
|
# File 'app/models/concept/base.rb', line 407
def pref_label
lang = I18n.locale.to_s == 'none' ? nil : I18n.locale.to_s
@cached_pref_labels ||= pref_labels.published.each_with_object({}) do |label, hash|
if hash[label.language]
Rails.logger.warn("Two pref_labels (#{hash[label.language]}, #{label}) for one language (#{label.language}). Taking the second one.")
end
hash[label.language] = label
end
if @cached_pref_labels[lang].nil?
@cached_pref_labels[lang] = pref_labels.select{ |l|
l.language.to_s == Iqvoc::Concept.pref_labeling_languages.first.to_s
}.first
end
@cached_pref_labels[lang]
end
|
439
440
441
442
443
|
# File 'app/models/concept/base.rb', line 439
def related_concepts_for_relation_class(relation_class, only_published = true)
relation_class = relation_class.name if relation_class < ActiveRecord::Base relations.select { |rel| rel.class.name == relation_class }.map(&:target).
select { |c| c.published? || !only_published }.sort_by(&:pref_label)
end
|
#to_param ⇒ Object
466
467
468
|
# File 'app/models/concept/base.rb', line 466
def to_param
"#{origin}"
end
|
#to_s ⇒ Object
470
471
472
|
# File 'app/models/concept/base.rb', line 470
def to_s
pref_label.to_s
end
|