Class: Labimotion::DatasetKlass

Inherits:
ApplicationRecord
  • Object
show all
Includes:
GenericKlass, GenericKlassRevisions, MetadataValidation
Defined in:
lib/labimotion/models/dataset_klass.rb

Class Method Summary collapse

Methods included from GenericKlassRevisions

#check_identifier, #create_klasses_revision

Class Method Details

.find_assigned_templates(ols_term_id) ⇒ Object



47
48
49
# File 'lib/labimotion/models/dataset_klass.rb', line 47

def self.find_assigned_templates(ols_term_id)
  find_by_mode(ols_term_id, 'assigned')
end

.find_by_mode(ols_term_id, mode) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/labimotion/models/dataset_klass.rb', line 39

def self.find_by_mode(ols_term_id, mode)
  where(
    "super_class_of @> jsonb_build_object(:id, jsonb_build_object('mode', :mode))",
    id: ols_term_id,
    mode: mode.to_s
  )
end

.find_inferred_templates(ols_term_id) ⇒ Object



51
52
53
# File 'lib/labimotion/models/dataset_klass.rb', line 51

def self.find_inferred_templates(ols_term_id)
  find_by_mode(ols_term_id, 'inferred')
end

.init_seedsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/labimotion/models/dataset_klass.rb', line 24

def self.init_seeds
  seeds_path = File.join(Rails.root, 'db', 'seeds', 'json', 'dataset_klasses.json')
  seeds = JSON.parse(File.read(seeds_path))

  seeds['chmo'].each do |term|
    next if Labimotion::DatasetKlass.where(ols_term_id: term['id']).any?

    attributes = { ols_term_id: term['id'], label: "#{term['label']} (#{term['synonym']})",
                   desc: "#{term['label']} (#{term['synonym']})", place: term['position'],
                   created_by: Admin.first&.id || 0 }
    Labimotion::DatasetKlass.create!(attributes)
  end
  true
end