Class: TaxonNameRelationship::Iczn::Invalidating::Homonym

Inherits:
TaxonNameRelationship::Iczn::Invalidating show all
Defined in:
app/models/taxon_name_relationship/iczn/invalidating/homonym.rb

Direct Known Subclasses

Primary, Secondary

Defined Under Namespace

Classes: Primary, Secondary

Constant Summary

NOMEN_URI =
'http://purl.obolibrary.org/obo/NOMEN_0000289'.freeze

Constants included from SoftValidation

SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS

Instance Attribute Summary

Attributes inherited from TaxonNameRelationship

#no_cached, #object_taxon_name_id, #project_id, #subject_taxon_name_id, #type

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from TaxonNameRelationship::Iczn::Invalidating

assignable, disjoint_subject_classes, gbif_status_of_subject, nomenclatural_priority, #similar_homonym_string

Methods inherited from TaxonNameRelationship::Iczn

disjoint_object_classes, disjoint_subject_classes, valid_object_ranks, valid_subject_ranks

Methods inherited from TaxonNameRelationship

assignable, collect_descendants_and_itself_to_s, collect_descendants_to_s, collect_to_s, disjoint_object_classes, disjoint_subject_classes, gbif_status_of_object, gbif_status_of_subject, #is_combination?, #is_invalidating?, nomen_uri, nomenclatural_priority, #nomenclature_date, #object_properties, #object_status_tag, required_taxon_name_relationships, #set_cached_names_for_taxon_names, #subject_invalid_statuses, #subject_status_tag, #sv_coordinated_taxa, #sv_coordinated_taxa_object, #sv_fix_combination_relationship, #sv_fix_coordinated_object_taxa, #sv_fix_coordinated_subject_taxa, #sv_fix_subject_parent_update, #sv_objective_synonym_relationship, #sv_synonym_linked_to_valid_name, #sv_synonym_relationship, #sv_validate_disjoint_object, #sv_validate_disjoint_relationships, #sv_validate_disjoint_subject, #sv_validate_required_relationships, #type_class, #type_class=, #type_name, valid_object_ranks, valid_subject_ranks, #validate_object_and_subject_both_protonyms, #validate_object_must_equal_subject_for_uncertain_placement, #validate_rank_group, #validate_subject_and_object_are_not_identical, #validate_subject_and_object_ranks, #validate_subject_and_object_share_code, #validate_type, #validate_uniqueness_of_typification_object

Methods included from SoftValidation

#clear_soft_validations, #fix_soft_validations, #soft_fixed?, #soft_valid?, #soft_validate, #soft_validated?, #soft_validations

Methods included from Housekeeping

#has_polymorphic_relationship?

Class Method Details

+ (Object) assignment_method



41
42
43
44
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 41

def self.assignment_method
  # bus.set_as_iczn_homonym_of(aus)
  :iczn_set_as_homonym_of
end

+ (Object) disjoint_taxon_name_relationships



9
10
11
12
13
14
15
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 9

def self.disjoint_taxon_name_relationships
  self.parent.disjoint_taxon_name_relationships +
      self.collect_descendants_to_s(TaxonNameRelationship::Iczn::Invalidating::Usage) +
      self.collect_to_s(TaxonNameRelationship::Iczn::Invalidating,
          TaxonNameRelationship::Iczn::Invalidating::Synonym::Suppression::Total)

end

+ (Object) inverse_assignment_method

as.



47
48
49
50
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 47

def self.inverse_assignment_method
  # aus.iczn_homonym = bus
  :iczn_homonym
end

Instance Method Details

- (Object) object_status



25
26
27
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 25

def object_status
  'senior homonym'
end

- (Object) object_status_connector_to_subject



37
38
39
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 37

def object_status_connector_to_subject
  ' of'
end

- (Object) subject_properties

def self.disjoint_object_classes

  self.parent.disjoint_object_classes
end


21
22
23
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 21

def subject_properties
  [ TaxonNameClassification::Iczn::Available::Invalid::Homonym ]
end

- (Object) subject_status



29
30
31
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 29

def subject_status
  'homonym'
end

- (Object) subject_status_connector_to_object



33
34
35
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 33

def subject_status_connector_to_object
  ' of'
end

- (Object) sv_fix_add_synonym_for_homonym



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 52

def sv_fix_add_synonym_for_homonym
  if self.subject_taxon_name.iczn_set_as_synonym_of.nil?
    unless self.subject_taxon_name.iczn_replacement_names.empty?
      self.subject_taxon_name.iczn_set_as_synonym_of = self.object_taxon_name
      begin
        TaxonNameRelationship.transaction do
          self.save
          return true
        end
      rescue
      end
    end
  end
  false
end

- (Object) sv_fix_specify_homonymy_type



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 104

def sv_fix_specify_homonymy_type
  subject_original_genus = self.subject_taxon_name.original_genus
  object_original_genus = self.object_taxon_name.original_genus
  subject_genus = self.subject_taxon_name.ancestor_at_rank('genus')
  object_genus = self.object_taxon_name.ancestor_at_rank('genus')
  new_relationship_name = nil
  if subject_original_genus == object_original_genus && !subject_original_genus.nil?
    new_relationship_name = 'TaxonNameRelationship::Iczn::Invalidating::Homonym::Primary'
  elsif subject_genus != object_genus && !subject_genus.nil?
    new_relationship_name = 'TaxonNameRelationship::Iczn::Invalidating::Homonym::Secondary'
  end
  if self.type_name != new_relationship_name
    self.type = new_relationship_name
    begin
      TaxonNameRelationship.transaction do
        self.save
        return true
      end
    rescue
    end
  end
  false
end

- (Object) sv_missing_nomen_novum



74
75
76
77
78
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 74

def sv_missing_nomen_novum
  if self.subject_taxon_name.iczn_set_as_synonym_of.nil? && self.subject_taxon_name.iczn_replacement_names.empty?
    soft_validations.add(:type, 'Please select a nomen novum and/or valid name')
  end
end

- (Object) sv_missing_replacement_name



80
81
82
83
84
85
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 80

def sv_missing_replacement_name
  if self.subject_taxon_name.iczn_set_as_synonym_of.nil? && !self.subject_taxon_name.iczn_replacement_names.empty?
    soft_validations.add(:type, 'Please select a valid name using synonym relationships',
                         fix: :sv_fix_add_synonym_for_homonym, success_message: 'Synonym relationship was added')
  end
end

- (Object) sv_not_specific_relationship



97
98
99
100
101
102
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 97

def sv_not_specific_relationship
    if SPECIES_RANK_NAMES_ICZN.include?(self.subject_taxon_name.rank_string)
      soft_validations.add(:type, 'Please specify if this is a primary or secondary homonym',
                           fix: :sv_fix_specify_homonymy_type, success_message: 'Homonym updated to being primary or secondary')
    end
end

- (Object) sv_specific_relationship



87
88
89
90
91
92
93
94
95
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 87

def sv_specific_relationship
  s = subject_taxon_name
  o = object_taxon_name
  if (s.cached_primary_homonym_alternative_spelling != o.cached_primary_homonym_alternative_spelling)
    if (s.cached_secondary_homonym_alternative_spelling.blank? && o.cached_secondary_homonym_alternative_spelling.blank?) || (s.cached_secondary_homonym_alternative_spelling != o.cached_secondary_homonym_alternative_spelling)
      soft_validations.add(:type, "#{subject_taxon_name.cached_html_name_and_author_year} and #{object_taxon_name.cached_html_name_and_author_year} are not similar enough to be homonyms")
    end
  end
end

- (Object) sv_validate_priority



128
129
130
131
132
133
134
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 128

def sv_validate_priority
  date1 = self.subject_taxon_name.nomenclature_date
  date2 = self.object_taxon_name.nomenclature_date
  if !!date1 && !!date2 && date2 > date1 && subject_invalid_statuses.empty?
    soft_validations.add(:type, "#{self.subject_status.capitalize} #{self.subject_taxon_name.cached_html_name_and_author_year} should not be older than #{self.object_status} #{self.object_taxon_name.cached_html_name_and_author_year}")
  end
end

- (Object) sv_validate_total_suppression



68
69
70
71
72
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 68

def sv_validate_total_suppression
  if !self.object_taxon_name.iczn_set_as_total_suppression_of.nil?
    soft_validations.add(:type, 'Taxon should not be treated as homonym, since the related taxon is totally suppressed')
  end
end