Class: ControlledVocabularyTerm

Inherits:
ApplicationRecord show all
Includes:
Housekeeping, Shared::AlternateValues, Shared::HasPapertrail, Shared::IsData
Defined in:
app/models/controlled_vocabulary_term.rb

Overview

A controlled vocabulary term is a user defineable attribute, a name and definition is required.

Direct Known Subclasses

BiocurationClass, BiologicalProperty, ConfidenceLevel, Keyword, Predicate, Topic

Constant Summary

ALTERNATE_VALUES_FOR =

Class constants

[:name, :definition]

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods included from ActiverecordUtilities

#trim_attributes

Instance Attribute Details

- (String) definition

Returns The term definition, required.

Returns:

  • (String)

    The term definition, required.



27
28
29
30
31
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
83
84
85
# File 'app/models/controlled_vocabulary_term.rb', line 27

class ControlledVocabularyTerm < ApplicationRecord

  include Housekeeping
  include Shared::AlternateValues
  include Shared::HasPapertrail
  include Shared::IsData
  # include Shared::Taggable <- NO!!

  acts_as_list scope: [:project_id, :type]

  # Class constants
  ALTERNATE_VALUES_FOR = [:name, :definition]

  validates_presence_of :name, :definition, :type
  validates_length_of :definition, minimum: 20 

  validates_uniqueness_of :name, scope: [:type, :project_id]
  validates_uniqueness_of :definition, scope: [:project_id]
  validates_uniqueness_of :uri, scope: [:project_id, :uri_relation], allow_blank: true
  validates_presence_of :uri_relation, unless: -> {uri.blank?}, message: 'must be provided if uri is provided'
  validates_presence_of :uri, unless: -> {uri_relation.blank?}, message: 'must be provided if uri_relation is provided'

  validate :uri_relation_is_a_skos_relation, unless: -> {uri_relation.blank?}

  scope :of_type, -> (type) { where(type: type.to_s.capitalize) }

  def self.find_for_autocomplete(params)
    term = "#{params[:term]}%"
    # where('name LIKE ? OR definition ILIKE ? OR name ILIKE ? OR name = ?', term, "#{term}%", "%term", term )
    where("name LIKE '#{term}' OR name ILIKE '%#{term}' OR name = '#{term}' OR definition ILIKE '%#{term}'")
        .where(project_id: params[:project_id])
  end

# def self.to_select(params)

#   data = {
#     quick: []
#     recent: []
#     pinboard: []
#   }

#   data[:recent] = ControlledVocabularyTerm.where(
#     type: params[:type],
#     project_id: params[:project_id],
#     user_id: params[:user_id]
#   ).order(updated_at: :desc).limit(10)
#     .recently_

#   user_id

# end

  protected

  def uri_relation_is_a_skos_relation
    errors.add(:uri_relation, 'is not a valid uri relation') if !SKOS_RELATIONS.keys.include?(uri_relation)
  end

end

- (String) name

Returns The term name.

Returns:

  • (String)

    The term name.



27
28
29
30
31
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
83
84
85
# File 'app/models/controlled_vocabulary_term.rb', line 27

class ControlledVocabularyTerm < ApplicationRecord

  include Housekeeping
  include Shared::AlternateValues
  include Shared::HasPapertrail
  include Shared::IsData
  # include Shared::Taggable <- NO!!

  acts_as_list scope: [:project_id, :type]

  # Class constants
  ALTERNATE_VALUES_FOR = [:name, :definition]

  validates_presence_of :name, :definition, :type
  validates_length_of :definition, minimum: 20 

  validates_uniqueness_of :name, scope: [:type, :project_id]
  validates_uniqueness_of :definition, scope: [:project_id]
  validates_uniqueness_of :uri, scope: [:project_id, :uri_relation], allow_blank: true
  validates_presence_of :uri_relation, unless: -> {uri.blank?}, message: 'must be provided if uri is provided'
  validates_presence_of :uri, unless: -> {uri_relation.blank?}, message: 'must be provided if uri_relation is provided'

  validate :uri_relation_is_a_skos_relation, unless: -> {uri_relation.blank?}

  scope :of_type, -> (type) { where(type: type.to_s.capitalize) }

  def self.find_for_autocomplete(params)
    term = "#{params[:term]}%"
    # where('name LIKE ? OR definition ILIKE ? OR name ILIKE ? OR name = ?', term, "#{term}%", "%term", term )
    where("name LIKE '#{term}' OR name ILIKE '%#{term}' OR name = '#{term}' OR definition ILIKE '%#{term}'")
        .where(project_id: params[:project_id])
  end

# def self.to_select(params)

#   data = {
#     quick: []
#     recent: []
#     pinboard: []
#   }

#   data[:recent] = ControlledVocabularyTerm.where(
#     type: params[:type],
#     project_id: params[:project_id],
#     user_id: params[:user_id]
#   ).order(updated_at: :desc).limit(10)
#     .recently_

#   user_id

# end

  protected

  def uri_relation_is_a_skos_relation
    errors.add(:uri_relation, 'is not a valid uri relation') if !SKOS_RELATIONS.keys.include?(uri_relation)
  end

end

- (Integer) project_id

the project ID

Returns:

  • (Integer)


27
28
29
30
31
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
83
84
85
# File 'app/models/controlled_vocabulary_term.rb', line 27

class ControlledVocabularyTerm < ApplicationRecord

  include Housekeeping
  include Shared::AlternateValues
  include Shared::HasPapertrail
  include Shared::IsData
  # include Shared::Taggable <- NO!!

  acts_as_list scope: [:project_id, :type]

  # Class constants
  ALTERNATE_VALUES_FOR = [:name, :definition]

  validates_presence_of :name, :definition, :type
  validates_length_of :definition, minimum: 20 

  validates_uniqueness_of :name, scope: [:type, :project_id]
  validates_uniqueness_of :definition, scope: [:project_id]
  validates_uniqueness_of :uri, scope: [:project_id, :uri_relation], allow_blank: true
  validates_presence_of :uri_relation, unless: -> {uri.blank?}, message: 'must be provided if uri is provided'
  validates_presence_of :uri, unless: -> {uri_relation.blank?}, message: 'must be provided if uri_relation is provided'

  validate :uri_relation_is_a_skos_relation, unless: -> {uri_relation.blank?}

  scope :of_type, -> (type) { where(type: type.to_s.capitalize) }

  def self.find_for_autocomplete(params)
    term = "#{params[:term]}%"
    # where('name LIKE ? OR definition ILIKE ? OR name ILIKE ? OR name = ?', term, "#{term}%", "%term", term )
    where("name LIKE '#{term}' OR name ILIKE '%#{term}' OR name = '#{term}' OR definition ILIKE '%#{term}'")
        .where(project_id: params[:project_id])
  end

# def self.to_select(params)

#   data = {
#     quick: []
#     recent: []
#     pinboard: []
#   }

#   data[:recent] = ControlledVocabularyTerm.where(
#     type: params[:type],
#     project_id: params[:project_id],
#     user_id: params[:user_id]
#   ).order(updated_at: :desc).limit(10)
#     .recently_

#   user_id

# end

  protected

  def uri_relation_is_a_skos_relation
    errors.add(:uri_relation, 'is not a valid uri relation') if !SKOS_RELATIONS.keys.include?(uri_relation)
  end

end

- (String) type

Returns The subclass of the CVT.

Returns:

  • (String)

    The subclass of the CVT.



27
28
29
30
31
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
83
84
85
# File 'app/models/controlled_vocabulary_term.rb', line 27

class ControlledVocabularyTerm < ApplicationRecord

  include Housekeeping
  include Shared::AlternateValues
  include Shared::HasPapertrail
  include Shared::IsData
  # include Shared::Taggable <- NO!!

  acts_as_list scope: [:project_id, :type]

  # Class constants
  ALTERNATE_VALUES_FOR = [:name, :definition]

  validates_presence_of :name, :definition, :type
  validates_length_of :definition, minimum: 20 

  validates_uniqueness_of :name, scope: [:type, :project_id]
  validates_uniqueness_of :definition, scope: [:project_id]
  validates_uniqueness_of :uri, scope: [:project_id, :uri_relation], allow_blank: true
  validates_presence_of :uri_relation, unless: -> {uri.blank?}, message: 'must be provided if uri is provided'
  validates_presence_of :uri, unless: -> {uri_relation.blank?}, message: 'must be provided if uri_relation is provided'

  validate :uri_relation_is_a_skos_relation, unless: -> {uri_relation.blank?}

  scope :of_type, -> (type) { where(type: type.to_s.capitalize) }

  def self.find_for_autocomplete(params)
    term = "#{params[:term]}%"
    # where('name LIKE ? OR definition ILIKE ? OR name ILIKE ? OR name = ?', term, "#{term}%", "%term", term )
    where("name LIKE '#{term}' OR name ILIKE '%#{term}' OR name = '#{term}' OR definition ILIKE '%#{term}'")
        .where(project_id: params[:project_id])
  end

# def self.to_select(params)

#   data = {
#     quick: []
#     recent: []
#     pinboard: []
#   }

#   data[:recent] = ControlledVocabularyTerm.where(
#     type: params[:type],
#     project_id: params[:project_id],
#     user_id: params[:user_id]
#   ).order(updated_at: :desc).limit(10)
#     .recently_

#   user_id

# end

  protected

  def uri_relation_is_a_skos_relation
    errors.add(:uri_relation, 'is not a valid uri relation') if !SKOS_RELATIONS.keys.include?(uri_relation)
  end

end

- (String) uri

Returns A URI for an external concept that matches this CVT.

Returns:

  • (String)

    A URI for an external concept that matches this CVT.



27
28
29
30
31
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
83
84
85
# File 'app/models/controlled_vocabulary_term.rb', line 27

class ControlledVocabularyTerm < ApplicationRecord

  include Housekeeping
  include Shared::AlternateValues
  include Shared::HasPapertrail
  include Shared::IsData
  # include Shared::Taggable <- NO!!

  acts_as_list scope: [:project_id, :type]

  # Class constants
  ALTERNATE_VALUES_FOR = [:name, :definition]

  validates_presence_of :name, :definition, :type
  validates_length_of :definition, minimum: 20 

  validates_uniqueness_of :name, scope: [:type, :project_id]
  validates_uniqueness_of :definition, scope: [:project_id]
  validates_uniqueness_of :uri, scope: [:project_id, :uri_relation], allow_blank: true
  validates_presence_of :uri_relation, unless: -> {uri.blank?}, message: 'must be provided if uri is provided'
  validates_presence_of :uri, unless: -> {uri_relation.blank?}, message: 'must be provided if uri_relation is provided'

  validate :uri_relation_is_a_skos_relation, unless: -> {uri_relation.blank?}

  scope :of_type, -> (type) { where(type: type.to_s.capitalize) }

  def self.find_for_autocomplete(params)
    term = "#{params[:term]}%"
    # where('name LIKE ? OR definition ILIKE ? OR name ILIKE ? OR name = ?', term, "#{term}%", "%term", term )
    where("name LIKE '#{term}' OR name ILIKE '%#{term}' OR name = '#{term}' OR definition ILIKE '%#{term}'")
        .where(project_id: params[:project_id])
  end

# def self.to_select(params)

#   data = {
#     quick: []
#     recent: []
#     pinboard: []
#   }

#   data[:recent] = ControlledVocabularyTerm.where(
#     type: params[:type],
#     project_id: params[:project_id],
#     user_id: params[:user_id]
#   ).order(updated_at: :desc).limit(10)
#     .recently_

#   user_id

# end

  protected

  def uri_relation_is_a_skos_relation
    errors.add(:uri_relation, 'is not a valid uri relation') if !SKOS_RELATIONS.keys.include?(uri_relation)
  end

end

- (String) uri_relation

Returns A SKOS relationship that defines/describes the relationship between the concept identified by the URI and the concept defined in the definition.

Returns:

  • (String)

    A SKOS relationship that defines/describes the relationship between the concept identified by the URI and the concept defined in the definition.



27
28
29
30
31
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
83
84
85
# File 'app/models/controlled_vocabulary_term.rb', line 27

class ControlledVocabularyTerm < ApplicationRecord

  include Housekeeping
  include Shared::AlternateValues
  include Shared::HasPapertrail
  include Shared::IsData
  # include Shared::Taggable <- NO!!

  acts_as_list scope: [:project_id, :type]

  # Class constants
  ALTERNATE_VALUES_FOR = [:name, :definition]

  validates_presence_of :name, :definition, :type
  validates_length_of :definition, minimum: 20 

  validates_uniqueness_of :name, scope: [:type, :project_id]
  validates_uniqueness_of :definition, scope: [:project_id]
  validates_uniqueness_of :uri, scope: [:project_id, :uri_relation], allow_blank: true
  validates_presence_of :uri_relation, unless: -> {uri.blank?}, message: 'must be provided if uri is provided'
  validates_presence_of :uri, unless: -> {uri_relation.blank?}, message: 'must be provided if uri_relation is provided'

  validate :uri_relation_is_a_skos_relation, unless: -> {uri_relation.blank?}

  scope :of_type, -> (type) { where(type: type.to_s.capitalize) }

  def self.find_for_autocomplete(params)
    term = "#{params[:term]}%"
    # where('name LIKE ? OR definition ILIKE ? OR name ILIKE ? OR name = ?', term, "#{term}%", "%term", term )
    where("name LIKE '#{term}' OR name ILIKE '%#{term}' OR name = '#{term}' OR definition ILIKE '%#{term}'")
        .where(project_id: params[:project_id])
  end

# def self.to_select(params)

#   data = {
#     quick: []
#     recent: []
#     pinboard: []
#   }

#   data[:recent] = ControlledVocabularyTerm.where(
#     type: params[:type],
#     project_id: params[:project_id],
#     user_id: params[:user_id]
#   ).order(updated_at: :desc).limit(10)
#     .recently_

#   user_id

# end

  protected

  def uri_relation_is_a_skos_relation
    errors.add(:uri_relation, 'is not a valid uri relation') if !SKOS_RELATIONS.keys.include?(uri_relation)
  end

end

Class Method Details

+ (Object) find_for_autocomplete(params)



53
54
55
56
57
58
# File 'app/models/controlled_vocabulary_term.rb', line 53

def self.find_for_autocomplete(params)
  term = "#{params[:term]}%"
  # where('name LIKE ? OR definition ILIKE ? OR name ILIKE ? OR name = ?', term, "#{term}%", "%term", term )
  where("name LIKE '#{term}' OR name ILIKE '%#{term}' OR name = '#{term}' OR definition ILIKE '%#{term}'")
      .where(project_id: params[:project_id])
end

Instance Method Details

- (Object) uri_relation_is_a_skos_relation (protected)



81
82
83
# File 'app/models/controlled_vocabulary_term.rb', line 81

def uri_relation_is_a_skos_relation
  errors.add(:uri_relation, 'is not a valid uri relation') if !SKOS_RELATIONS.keys.include?(uri_relation)
end