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 collapse

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_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_subject_classes, #dwc_occurrences, gbif_status_of_object, gbif_status_of_subject, #is_combination?, #is_invalidating?, nomen_uri, nomenclatural_priority, #nomenclature_date, #object_properties, #object_status_tag, parent, required_taxon_name_relationships, #set_cached_names_for_taxon_names, #subject_and_object_in_same_project, #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_objective_synonym_relationship, #sv_fix_subject_parent_update, #sv_objective_synonym_relationship, #sv_synonym_linked_to_valid_name, #sv_validate_disjoint_object, #sv_validate_disjoint_relationships, #sv_validate_disjoint_subject, #sv_validate_required_relationships, #sv_validate_seniority, #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 Shared::IsData

#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar

Methods included from SoftValidation

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

Methods included from Shared::Notes

#concatenated_notes_string, #reject_notes

Methods included from Shared::Citations

#cited?, #mark_citations_for_destruction, #nomenclature_date, #origin_citation_source_id, #reject_citations, #requires_citation?, #sources_by_topic_id

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods inherited from ApplicationRecord

transaction_with_retry

Class Method Details

.assignment_methodObject



63
64
65
66
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 63

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

.disjoint_object_classesObject



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

def self.disjoint_object_classes
  self.parent.disjoint_object_classes +
    self.collect_descendants_and_itself_to_s(TaxonNameClassification::Iczn::Unavailable)
end

.disjoint_taxon_name_relationshipsObject

soft_validate(:sv_not_specific_relationship,

set: :not_specific_relationship,
fix: :sv_fix_not_specific_relationship,
name: 'Not specific homonym relationship',
description: 'Check if homonymy could be defined as primary or secondary.' )


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

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

.inverse_assignment_methodObject

as.



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

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

Instance Method Details

#object_statusObject



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

def object_status
  'senior homonym'
end

#object_status_connector_to_subjectObject



59
60
61
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 59

def object_status_connector_to_subject
  ' of'
end

#subject_propertiesObject



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

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

#subject_statusObject



51
52
53
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 51

def subject_status
  'homonym'
end

#subject_status_connector_to_objectObject



55
56
57
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 55

def subject_status_connector_to_object
  ' of'
end

#sv_fix_add_synonym_for_homonymObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 139

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

#sv_fix_not_specific_relationshipObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 112

def sv_fix_not_specific_relationship
  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 new_relationship_name && self.type_name != new_relationship_name
    self.type = new_relationship_name
    self.save
    return true
  end
  false
end

#sv_missing_nomen_novumObject



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

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 replacement or substitute name')
  end
end

#sv_missing_replacement_nameObject



86
87
88
89
90
91
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 86

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',
                         success_message: 'Synonym relationship was added')
  end
end

#sv_not_specific_relationshipObject



103
104
105
106
107
108
109
110
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 103

def sv_not_specific_relationship
  if self.subject_taxon_name.is_species_rank?
    soft_validations.add(
      :type, 'Please specify if this is a primary or secondary homonym',
      success_message: 'Homonym updated to being primary or secondary',
      failure_message:  'Failed to update the homonym relationship')
  end
end

#sv_specific_relationshipObject



93
94
95
96
97
98
99
100
101
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 93

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

#sv_synonym_relationshipObject



155
156
157
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 155

def sv_synonym_relationship
  true
end

#sv_validate_priorityObject



131
132
133
134
135
136
137
# File 'app/models/taxon_name_relationship/iczn/invalidating/homonym.rb', line 131

def sv_validate_priority
  date1 = self.subject_taxon_name.cached_nomenclature_date
  date2 = self.object_taxon_name.cached_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

#sv_validate_total_suppressionObject



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

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