Class: Protonym
- Inherits:
-
TaxonName
- Object
- ActiveRecord::Base
- ApplicationRecord
- TaxonName
- Protonym
- Extended by:
- SoftValidationExtensions::Klass
- Includes:
- Becomes, SoftValidationExtensions::Instance
- Defined in:
- app/models/protonym.rb
Overview
A monomial TaxonName, a record implies a first usage. This follows Pyle’s concept almost exactly.
We inject a lot of relationship helper methods here, in this format.
subject object
Aus original_genus of bus
aus type_species of Bus
Defined Under Namespace
Modules: Becomes, SoftValidationExtensions
Constant Summary collapse
- FAMILY_GROUP_ENDINGS =
%w{ini ina inae idae oidae odd ad oidea}.freeze
Constants included from SoftValidationExtensions::Klass
SoftValidationExtensions::Klass::VALIDATIONS
Constants inherited from TaxonName
TaxonName::ALTERNATE_VALUES_FOR, TaxonName::COMBINATION_ELEMENTS, TaxonName::NOMEN_VALID, TaxonName::NOT_LATIN, TaxonName::NO_CACHED_MESSAGE, TaxonName::ROOT_NAME, TaxonName::SPECIES_EPITHET_RANKS
Constants included from SoftValidation
SoftValidation::ANCESTORS_WITH_SOFT_VALIDATIONS
Instance Attribute Summary collapse
-
#_cached_build_state ⇒ Object
readonly
Hash !! Use only during building cached values.
-
#is_available ⇒ Boolean
readonly
Memoize ‘#is_avaiable?`.
-
#original_combination_elements ⇒ Hash
{ genus: [“”, ‘Aus’ ], … form: [‘frm’, ‘aus’] }.
Attributes inherited from TaxonName
#also_create_otu, #cached, #cached_author, #cached_author_year, #cached_classified_as, #cached_html, #cached_misspelling, #cached_original_combination, #cached_original_combination_html, #cached_primary_homonym, #cached_primary_homonym_alternative_spelling, #cached_secondary_homonym, #cached_secondary_homonym_alternative_spelling, #classifications, #etymology, #feminine_name, #masculine_name, #name, #neuter_name, #no_cached, #parent_id, #project_id, #rank_class, #related_relationships, #taxonomy, #type, #verbatim_author, #verbatim_name, #year_of_publication
Class Method Summary collapse
- .batch_move(params) ⇒ Hash
- .batch_update(params) ⇒ Object
- .family_group_base(name_string) ⇒ Object
- .family_group_name_at_rank(name_string, rank_string) ⇒ Object
-
.names_at_rank_group_for_collection_objects(rank: nil, collection_object_query: nil) ⇒ Object
!! Ensure collection_object_query is scoped to project.
-
.stub_root(project_id: nil, by: nil) ⇒ Protonym
A name ready to become the root.
Instance Method Summary collapse
- #_initialize_cached_build_state ⇒ Object protected
-
#all_generic_placements ⇒ Array of Strings
Genera where the species was placed.
-
#ancestors_and_descendants ⇒ Array
All descendant and ancestor protonyms for this Protonym.
-
#build_original_combination_from_biodiversity(biodiversity_result, relationship_housekeeping = {}) ⇒ Boolean
TODO: likley belongs in lib/vendor/biodiversity.rb.
- #build_original_combinations(combination, relationship_housekeeping) ⇒ Boolean
- #check_new_parent_class ⇒ Object protected
- #genus_suggested_gender ⇒ Object
-
#get_genus_species(genus_option, self_option) ⇒ nil, ...
This method is currently only used for setting cached_primary_homonym.
- #get_original_combination ⇒ Object
-
#get_original_combination_html ⇒ Object
This should never require hitting the database.
-
#get_primary_type ⇒ TypeMaterial, []
?!.
-
#get_valid_taxon_name ⇒ Protonym
The accepted “valid” version of this name in the present classification.
- #has_alternate_original? ⇒ Boolean
-
#has_latinized_classification? ⇒ Boolean
Boolean.
-
#has_latinized_exceptions? ⇒ Boolean
Whether this name has one of the TaxonNameClassifications that except it from being tested as latinized.
- #has_misspelling_or_misapplication_relationship? ⇒ Boolean
-
#has_misspelling_relationship? ⇒ Boolean
Whether this name has one of the TaxonNameRelationships which justify wrong form of the name.
-
#has_same_primary_type(taxon2) ⇒ Boolean
!! TODO: Should not be possible- fix the incoming data.
- #is_available?(refresh = false) ⇒ Boolean
- #is_family_or_genus_or_species_rank? ⇒ Boolean
- #is_family_rank? ⇒ Boolean
- #is_genus_or_species_rank? ⇒ Boolean
- #is_genus_rank? ⇒ Boolean
- #is_higher_rank? ⇒ Boolean
- #is_latin? ⇒ Boolean
-
#is_original_name? ⇒ Boolean
Boolean.
- #is_species_rank? ⇒ Boolean
- #list_of_coordinated_names ⇒ Object
-
#lowest_rank_coordinated_taxon ⇒ Object
TODO, make back half of this raw SQL.
- #name_is_latinized ⇒ Object protected
- #name_is_valid_format ⇒ Object protected
- #name_with_alternative_spelling ⇒ Object
- #new_parent_taxon_name ⇒ Object protected
- #nominotypical_sub_of?(protonym) ⇒ boolean
-
#number_of_taxa_by_year ⇒ Object
temporary method to get a number of taxa described by year.
-
#original_combination_class_relationships ⇒ Object
return [Array] TaxonNameRelationship classes that are applicable to this name, as deterimined by Rank.
-
#original_combination_infraspecific_element(elements = nil, remove_sic = false) ⇒ [rank_name, name]?
Used in ColDP export.
-
#original_combination_relationships_and_stubs ⇒ Array
A relationships for each possible original combination relationship.
-
#original_name ⇒ String?
A monominal, as originally rendered, with parens if subgenus.
- #predict_three_forms ⇒ Object
-
#predicted_child_rank(child_string) ⇒ Object
taxon_name.predicted_children_rank(‘Cicadellidae’) >> NomenclaturalRank::Iczn::FamilyGroup::Family.
- #reduce_list_of_synonyms(list) ⇒ Object
-
#reload ⇒ Object
Reset memomized and utility variable son reload.
- #set_cached ⇒ Object protected
- #set_cached_homonymy ⇒ Object protected
-
#set_cached_misspelling ⇒ Object
protected
The only reason this is needed on this side is because of the verbatim_name checks, otherwise we could drive it from the TaxonNameRelationship creation.
- #set_cached_names_for_dependants ⇒ Object
-
#set_cached_names_for_descendants ⇒ Object
TODO: Are there are times where names are dependant and descendant? Original Genus is Genus, for example.
- #set_cached_original_combination ⇒ Object protected
- #set_cached_original_combination_html ⇒ Object protected
- #set_cached_species_homonym ⇒ Object
-
#set_original_combination_cached_fields ⇒ Object
protected
All cached values that relate to an original combination should be referenced here so that they can be re-referenced indirectly from TaxonNameRelationships In particular those impacted by an OriginalCombination.
- #species_questionable_ending(taxon_name_classification_class, tested_name) ⇒ Object
-
#sv_cached_names ⇒ Object
protected
!! This has to go.
-
#synonymize_with(protonym) ⇒ Object
A convenience method to make this name a low-level synonym of another.
- #update_cached_original_combinations ⇒ Object
- #validate_child_rank_is_equal_or_lower ⇒ Object protected
- #validate_parent_rank_is_higher ⇒ Object protected
- #validate_rank_class_class ⇒ Object protected
- #validate_same_nomenclatural_code ⇒ Object protected
- #verbatim_author_with_closed_parens_when_present ⇒ Object protected
- #verbatim_author_without_digits ⇒ Object protected
Methods included from Becomes
#becomes_combination, #becomes_test_classifications, #becomes_test_for_original_genus, #becomes_test_for_original_relationships, #becomes_test_for_other_relationships, #becomes_test_for_relationship, #becomes_test_for_similarity, #convertable_to_combination?
Methods included from SoftValidationExtensions::Instance
#sv_author_is_not_required, #sv_duplicate_nomen_nudum, #sv_extant_children, #sv_family_is_invalid, #sv_family_is_invalid_no_substitute, #sv_fix_add_nominotypical_sub, #sv_fix_author_is_not_required, #sv_fix_coordinated_names_author, #sv_fix_coordinated_names_etymology, #sv_fix_coordinated_names_gender, #sv_fix_coordinated_names_original_form, #sv_fix_coordinated_names_original_genus, #sv_fix_coordinated_names_original_species, #sv_fix_coordinated_names_original_subgenus, #sv_fix_coordinated_names_original_subspecies, #sv_fix_coordinated_names_original_variety, #sv_fix_coordinated_names_page, #sv_fix_coordinated_names_part_of_speech, #sv_fix_coordinated_names_roles, #sv_fix_coordinated_names_source, #sv_fix_coordinated_names_type_genus, #sv_fix_coordinated_names_type_species, #sv_fix_coordinated_names_type_species_type, #sv_fix_coordinated_names_type_specimen, #sv_fix_coordinated_names_year, #sv_fix_missing_otu, #sv_fix_misspelling_author_is_not_required, #sv_fix_misspelling_roles_are_not_required, #sv_fix_misspelling_year_is_not_required, #sv_fix_presence_of_combination, #sv_fix_type_placement1, #sv_fix_year_is_not_required, #sv_homotypic_synonyms, #sv_missing_etymology, #sv_missing_gender, #sv_missing_infrasubspecific_status, #sv_missing_original_genus, #sv_missing_otu, #sv_missing_part_of_speech, #sv_missing_roles, #sv_missing_substitute_name, #sv_missing_type_genus, #sv_missing_type_species, #sv_misspelling_author_is_not_required, #sv_misspelling_roles_are_not_required, #sv_misspelling_year_is_not_required, #sv_original_combination_relationships, #sv_parent_priority, #sv_person_vs_year_of_publication, #sv_potential_family_homonyms, #sv_potential_genus_homonyms, #sv_potential_species_homonyms, #sv_potential_usage_duplicates, #sv_presence_of_combination, #sv_primary_types, #sv_primary_types_repository, #sv_protonym_to_combination, #sv_single_sub_taxon, #sv_source_not_older_then_description, #sv_species_gender_agreement, #sv_species_gender_agreement_not_required, #sv_type_placement, #sv_type_placement1, #sv_validate_coordinated_names_author, #sv_validate_coordinated_names_etymology, #sv_validate_coordinated_names_gender, #sv_validate_coordinated_names_original_form, #sv_validate_coordinated_names_original_genus, #sv_validate_coordinated_names_original_species, #sv_validate_coordinated_names_original_subgenus, #sv_validate_coordinated_names_original_subspecies, #sv_validate_coordinated_names_original_variety, #sv_validate_coordinated_names_page, #sv_validate_coordinated_names_part_of_speech, #sv_validate_coordinated_names_roles, #sv_validate_coordinated_names_source, #sv_validate_coordinated_names_type_genus, #sv_validate_coordinated_names_type_species, #sv_validate_coordinated_names_type_species_type, #sv_validate_coordinated_names_type_specimen, #sv_validate_coordinated_names_year, #sv_validate_name, #sv_validate_parent_rank, #sv_year_is_not_required
Methods inherited from TaxonName
#all_taxon_name_relationships, #ancestor_at_rank, #ancestor_hash, #ancestor_protonyms, #ancestors_through_parents, #author_string, #cached_html_name_and_author_year, #cached_html_original_name_and_author_year, #cached_name_and_author_year, calculated_invalid, calculated_valid, #check_for_children, #check_new_rank_class, #classification_invalid_or_unavailable?, #classification_unavailable?, #classification_valid?, #clear_cached, #combination_list_all, #combination_list_self, #combined_statuses, #create_otu, #descendant_protonyms, #dwc_occurrences, #first_possible_invalid_taxan_name_relationship, #first_possible_valid_taxon_name, #first_possible_valid_taxon_name_relationship, #full_name, #full_name_array, #full_name_hash, #gbif_status_array, #gender_class, #gender_instance, #gender_name, #genderized_name, #get_author, #get_author_and_year, #get_cached_classified_as, #get_cached_misspelling, #get_full_name, #get_full_name_html, #icn_author_and_year, #iczn_author_and_year, #is_ambiguously_invalid?, #is_candidatus?, #is_combination?, #is_fossil?, #is_hybrid?, #is_italicized?, #is_protonym?, #is_valid?, #list_of_invalid_taxon_names, #matrix_row_item, #merge_to, #minimum_invalidating_year, #minimum_years_valid, #name_in_gender, #name_is_misapplied?, #name_with_misspelling, #next_sibling, #nomeclatural_history, #nomenclature_date, #normalized_genus, #not_binominal?, not_leaves, #original_author_year, out_of_scope_combinations, #out_of_scope_combinations, #part_of_speech_class, #part_of_speech_instance, #part_of_speech_name, #previous_sibling, #rank, #rank_string, #reified_id, #related_taxon_names, #relationship_invalid?, #relationships, #safe_self_and_ancestors, select_optimized, #set_cached_author, #set_cached_author_columns, #set_cached_author_year, #set_cached_classified_as, #set_cached_is_valid, #set_cached_nomenclature_date, #set_cached_valid_taxon_name_id, #set_cached_warnings, sort_by_rank, #statuses_from_classifications, #statuses_from_relationships, #sv_combination_duplicates, #sv_conflicting_subordinate_taxa, #sv_fix_cached_names, #sv_fix_parent_is_valid_name, #sv_homotypic_synonyms, #sv_hybrid_name_relationships, #sv_incomplete_combination, #sv_missing_classifications, #sv_missing_confidence_level, #sv_missing_etymology, #sv_missing_original_publication, #sv_missing_relationships, #sv_not_synonym_of_self, #sv_parent_is_valid_name, #sv_parent_priority, #sv_potential_homonyms, #sv_primary_types, #sv_single_sub_taxon, #sv_species_gender_agreement, #sv_two_unresolved_alternative_synonyms, #sv_type_placement, #sv_validate_coordinated_names, #sv_validate_name, #sv_validate_parent_rank, #synonyms, #taxon_name_classification_minimum_invalidating_year, #taxon_name_classifications_for_statuses, #taxon_name_relationship_minimum_invalidating_year, #unavailable_or_invalid?, used_recently, used_recently_in_classifications, used_recently_in_relationships, #validate_parent_from_the_same_project, #validate_root_name_is_root, #validate_source_type, with_taxon_name_relationship, #year_integer
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 TaxonName::MatrixHooks
#coordinate_observation_matrix_row_items, #in_scope_observation_matrix_row_items, #out_of_scope_observation_matrix_row_items
Methods included from Shared::MatrixHooks::Dynamic
#dynamic_add_to_matrix_column_items, #dynamic_add_to_matrix_row_items, #dynamic_cleanup_in_scope_column_items, #dynamic_cleanup_in_scope_row_items, #dynamic_cleanup_out_of_scope_column_items, #dynamic_cleanup_out_of_scope_row_items, #dynamic_column_items_in, #dynamic_column_items_out, #dynamic_inspect_matrices, #dynamic_remove_from_matrix_column_items, #dynamic_remove_from_matrix_row_items, #dynamic_row_items_in, #dynamic_row_items_out, #dynamic_synchronize_matrices, #dynamic_update_matrix_column_items?, #dynamic_update_matrix_row_items?, #in_scope_observation_matrix_column_items, #in_scope_observation_matrix_row_items, #out_of_scope_observation_matrix_column_items, #out_of_scope_observation_matrix_row_items, #prepare_matrix_items
Methods included from Shared::MatrixHooks::Member
#member_add_matrix_columns, #member_add_matrix_rows, #member_add_to_matrix_items, #member_of_new_matrix_column_items, #member_of_new_matrix_row_items, #member_of_old_matrix_column_items, #member_of_old_matrix_row_items, #member_remove_from_matrix_items, #member_remove_matrix_columns, #member_remove_matrix_rows, #member_synchronize_matrices, #member_update_matrix_items?
Methods included from Shared::QueryBatchUpdate
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::Labels
Methods included from Shared::HasPapertrail
#attribute_updated, #attribute_updater, #detect_version
Methods included from Shared::AlternateValues
#all_values_for, #alternate_valued?
Methods included from Shared::Confidences
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 Shared::Depictions
#has_depictions?, #image_array=, #reject_depictions, #reject_images
Methods included from Shared::Notes
#concatenated_notes_string, #reject_notes
Methods included from Shared::Identifiers
#dwc_occurrence_id, #identified?, #next_by_identifier, #previous_by_identifier, #reject_identifiers, #uri, #uuid
Methods included from Shared::Tags
#reject_tags, #tag_with, #tagged?, #tagged_with?
Methods included from Shared::DataAttributes
#import_attributes, #internal_attributes, #keyword_value_hash, #reject_data_attributes
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Instance Attribute Details
#_cached_build_state ⇒ Object (readonly)
Returns Hash !! Use only during building cached values. Idea !! is to store values used downstream in setting cached values.
25 26 27 |
# File 'app/models/protonym.rb', line 25 def _cached_build_state @_cached_build_state end |
#is_available ⇒ Boolean (readonly)
Returns memoize ‘#is_avaiable?`.
20 21 22 |
# File 'app/models/protonym.rb', line 20 def is_available @is_available end |
#original_combination_elements ⇒ Hash
genus: ["", 'Aus' ],
...
form: ['frm', 'aus']
724 725 726 |
# File 'app/models/protonym.rb', line 724 def original_combination_elements @original_combination_elements end |
Class Method Details
.batch_move(params) ⇒ Hash
978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 |
# File 'app/models/protonym.rb', line 978 def self.batch_move(params) return false if params[:parent_id].blank? a = Queries::TaxonName::Filter.new(params[:taxon_name_query]).all.where(type: 'Protonym') return false if a.count == 0 moved = [] unmoved = [] begin a.each do |o| if o.update(parent_id: params[:parent_id] ) moved.push o else unmoved.push o end end end return { moved:, unmoved:} end |
.batch_update(params) ⇒ Object
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 |
# File 'app/models/protonym.rb', line 1006 def self.batch_update(params) request = QueryBatchRequest.new( async_cutoff: params[:async_cutoff] || 50, klass: 'TaxonName', object_filter_params: params[:taxon_name_query], object_params: params[:taxon_name], preview: params[:preview], ) query_batch_update(request) end |
.family_group_base(name_string) ⇒ Object
167 168 169 170 |
# File 'app/models/protonym.rb', line 167 def self.family_group_base(name_string) name_string.match(/(^.*)(ini|ina|inae|idae|oidae|odd|ad|oidea)$/) $1 || name_string end |
.family_group_name_at_rank(name_string, rank_string) ⇒ Object
172 173 174 175 176 177 178 |
# File 'app/models/protonym.rb', line 172 def self.family_group_name_at_rank(name_string, rank_string) if name_string == Protonym.family_group_base(name_string) name_string else Protonym.family_group_base(name_string) + Ranks.lookup(:iczn, rank_string).constantize.try(:valid_name_ending).to_s end end |
.names_at_rank_group_for_collection_objects(rank: nil, collection_object_query: nil) ⇒ Object
!! Ensure collection_object_query is scoped to project
183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'app/models/protonym.rb', line 183 def self.names_at_rank_group_for_collection_objects(rank: nil, collection_object_query: nil) # Find all the names for the objects in question names = ::Queries::TaxonName::Filter.new(collection_object_query:).all s = 'WITH q_co_names AS (' + names.distinct.all.to_sql + ') ' + ::Protonym .joins('JOIN taxon_name_hierarchies tnh on tnh.ancestor_id = taxon_names.id') .joins('JOIN q_co_names as q_co1 on q_co1.id = tnh.descendant_id') .where('taxon_names.rank_class ilike ?', rank) .to_sql ::Protonym.from('(' + s + ') as taxon_names').distinct end |
Instance Method Details
#_initialize_cached_build_state ⇒ Object (protected)
1180 1181 1182 |
# File 'app/models/protonym.rb', line 1180 def _initialize_cached_build_state @_cached_build_state = {} end |
#all_generic_placements ⇒ Array of Strings
Returns genera where the species was placed.
227 228 229 230 231 232 233 |
# File 'app/models/protonym.rb', line 227 def all_generic_placements valid_name = get_valid_taxon_name return nil unless valid_name.rank_string !=~/Species/ descendants_and_self = valid_name.descendants + [self] + self.combinations relationships = TaxonNameRelationship.where_object_in_taxon_names(descendants_and_self).with_two_type_bases('TaxonNameRelationship::OriginalCombination::OriginalGenus', 'TaxonNameRelationship::Combination::Genus') (relationships.collect { |r| r.subject_taxon_name.name } + [self.ancestor_at_rank('genus').try(:name)]).uniq end |
#ancestors_and_descendants ⇒ Array
Returns all descendant and ancestor protonyms for this Protonym.
345 346 347 |
# File 'app/models/protonym.rb', line 345 def ancestors_and_descendants Protonym.ancestors_and_descendants_of(self).not_self(self).to_a end |
#build_original_combination_from_biodiversity(biodiversity_result, relationship_housekeeping = {}) ⇒ Boolean
TODO: likley belongs in lib/vendor/biodiversity.rb
687 688 689 690 691 692 693 |
# File 'app/models/protonym.rb', line 687 def build_original_combination_from_biodiversity(biodiversity_result, relationship_housekeeping = {}) br = biodiversity_result return false if br.nil? c = [br.disambiguated_combination, br.combination].first build_original_combinations(c, relationship_housekeeping) true end |
#build_original_combinations(combination, relationship_housekeeping) ⇒ Boolean
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 |
# File 'app/models/protonym.rb', line 700 def build_original_combinations(combination, relationship_housekeeping) return false if combination.nil? combination.protonyms_by_rank.each do |rank, p| send("original_#{rank}=", p) end unless relationship_housekeeping.blank? combination.protonyms_by_rank.each do |rank, p| r = send("original_#{rank}_relationship") r.write_attributes(relationship_housekeeping) end end true end |
#check_new_parent_class ⇒ Object (protected)
1020 1021 1022 1023 1024 1025 1026 1027 1028 |
# File 'app/models/protonym.rb', line 1020 def check_new_parent_class if is_protonym? && parent_id != parent_id_was && !parent_id_was.nil? && nomenclatural_code == :iczn if old_parent = TaxonName.find_by(id: parent_id_was) if (rank_name == 'subgenus' || rank_name == 'subspecies') && old_parent.name == name errors.add(:parent_id, "The nominotypical #{rank_name} #{name} can not be moved out of the nominal #{old_parent.rank_name}") end end end end |
#genus_suggested_gender ⇒ Object
663 664 665 666 667 668 669 670 671 |
# File 'app/models/protonym.rb', line 663 def genus_suggested_gender return nil unless rank_string =~/Genus/ TAXON_NAME_CLASSIFICATION_GENDER_CLASSES.each do |g| g.possible_genus_endings.each do |e| return g.name.demodulize.underscore.humanize.downcase if self.name =~ /^[a-zA-Z]*#{e}$/ end end nil end |
#get_genus_species(genus_option, self_option) ⇒ nil, ...
This method is currently only used for setting cached_primary_homonym.
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'app/models/protonym.rb', line 303 def get_genus_species(genus_option, self_option) return nil if rank_class.nil? genus = nil name1 = nil if is_species_rank? if genus_option == :original genus = original_genus elsif genus_option == :current genus = ancestor_at_rank('genus') # @taxonomy else return false end genus = genus.name if genus.present? return nil if genus.blank? end if self_option == :self name1 = name elsif self_option == :alternative name1 = name_with_alternative_spelling end return nil if genus.nil? && name1.nil? # <- hitting this because Genus is never set [genus, name1].compact.join(' ') end |
#get_original_combination ⇒ Object
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 |
# File 'app/models/protonym.rb', line 815 def get_original_combination return verbatim_name if !GENUS_AND_SPECIES_RANK_NAMES.include?(rank_string) && !verbatim_name.nil? e = original_combination_elements return nil if e.none? # Weird, why? # DD: in ICVCN the species name is "Potato spindle tuber viroid", the genus name is only used for classification... # # @proceps: then we should exclude or alter elements before we get to this point, not here, so that the renderer still works, exceptions at this point are bad # and this didn't do what you think it did, it's was returning an Array of two things return e[:species][1] if rank_class.to_s =~ /Icvcn/ p = TaxonName::COMBINATION_ELEMENTS.inject([]){|ary, r| ary.push(e[r]) } s = p.flatten.compact.join(' ') @_cached_build_state[:original_combination] = s.presence end |
#get_original_combination_html ⇒ Object
This should never require hitting the database.
834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 |
# File 'app/models/protonym.rb', line 834 def get_original_combination_html return verbatim_name if !GENUS_AND_SPECIES_RANK_NAMES.include?(rank_string) && !verbatim_name.nil? return "\"<i>Candidatus</i> #{get_original_combination}\"" if is_candidatus? # x = get_original_combination # y = cached_original_combination # In a transaction this is not available v = @_cached_build_state[:original_combination] return nil if v.blank? if is_hybrid? w = v.split(' ') w[-1] = ('×' + w[-1]).gsub('×(', '(×').gsub(') [sic]', ' [sic])').gsub(') (sic)', ' (sic))') v = w.join(' ') end v = v.gsub(') [sic]', ' [sic])').gsub(') (sic)', ' (sic))') v = Utilities::Italicize.taxon_name(v) if is_genus_or_species_rank? v = '† ' + v if is_fossil? # This doesn't belong here, it's touching the DB. v end |
#get_primary_type ⇒ TypeMaterial, []
Returns ?!.
350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'app/models/protonym.rb', line 350 def get_primary_type return [] unless self.rank_class.parent.to_s =~ /Species/ s = self.type_materials.syntypes p = self.type_materials.primary if s.empty? && p.count == 1 p elsif p.empty? && !s.empty? s else [] end end |
#get_valid_taxon_name ⇒ Protonym
Returns the accepted “valid” version of this name in the present classification.
286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'app/models/protonym.rb', line 286 def get_valid_taxon_name v = first_possible_valid_taxon_name if v == self self elsif v.cached_valid_taxon_name_id == v.id v elsif !v.cached_valid_taxon_name_id.nil? v.valid_taxon_name else self end end |
#has_alternate_original? ⇒ Boolean
514 515 516 |
# File 'app/models/protonym.rb', line 514 def has_alternate_original? cached_original_combination && (cached != cached_original_combination) ? true : false end |
#has_latinized_classification? ⇒ Boolean
Returns Boolean.
548 549 550 |
# File 'app/models/protonym.rb', line 548 def has_latinized_classification? TaxonNameClassification.where_taxon_name(self).with_type_array(LATINIZED_TAXON_NAME_CLASSIFICATION_NAMES).any? end |
#has_latinized_exceptions? ⇒ Boolean
Returns whether this name has one of the TaxonNameClassifications that except it from being tested as latinized.
480 481 482 483 484 485 486 487 488 489 490 491 492 |
# File 'app/models/protonym.rb', line 480 def has_latinized_exceptions? # The second half of this handles classifications in memory, as required to save a non-latinized name (i.e. don't tune it to .any?) # !((type == 'Protonym') && (taxon_name_classifications.collect{|t| t.type} & EXCEPTED_FORM_TAXON_NAME_CLASSIFICATIONS).empty?) # Is faster than above? # return true if rank_string =~ /Icnp/ && (name.start_with?('Candidatus ') || name.start_with?('Ca. ')) return true if is_family_rank? && !family_group_name_form_relationship.nil? return true if is_family_rank? && !(taxon_name_relationships.collect{|i| i.type} & ::TAXON_NAME_RELATIONSHIP_NAMES_SYNONYM).empty? return true unless (taxon_name_classifications.collect{|i| i.type} & ::EXCEPTED_FORM_TAXON_NAME_CLASSIFICATIONS).empty? return true unless (taxon_name_relationships.collect{|i| i.type} & ::TAXON_NAME_RELATIONSHIP_NAMES_MISSPELLING).empty? false end |
#has_misspelling_or_misapplication_relationship? ⇒ Boolean
510 511 512 |
# File 'app/models/protonym.rb', line 510 def has_misspelling_or_misapplication_relationship? taxon_name_relationships.with_type_array(TAXON_NAME_RELATIONSHIP_NAMES_MISSPELLING_AND_MISAPPLICATION).any? end |
#has_misspelling_relationship? ⇒ Boolean
Returns whether this name has one of the TaxonNameRelationships which justify wrong form of the name.
500 501 502 503 504 505 506 507 |
# File 'app/models/protonym.rb', line 500 def has_misspelling_relationship? # taxon_name_relationships.with_type_array(TAXON_NAME_RELATIONSHIP_NAMES_MISSPELLING).any? if cached_misspelling || cached_original_combination_html.to_s.include?('[sic]') return true else return false end end |
#has_same_primary_type(taxon2) ⇒ Boolean
!! TODO: Should not be possible- fix the incoming data
438 439 440 441 442 443 444 445 446 447 |
# File 'app/models/protonym.rb', line 438 def has_same_primary_type(taxon2) return true unless rank_class.parent.to_s =~ /Species/ taxon1_types = get_primary_type.sort_by{|i| i.id} taxon2_types = taxon2.get_primary_type.sort_by{|i| i.id} return true if taxon1_types.empty? && taxon2_types.empty? # both are empty !! If they are both empty then they don't have the same type, the have no types !! return false if taxon1_types.empty? || taxon2_types.empty? # one is empty taxon1_types.map(&:collection_object_id) == taxon2_types.map(&:collection_object_id) # collect{|i| i.collection_object_id} end |
#is_available?(refresh = false) ⇒ Boolean
275 276 277 278 279 280 281 282 |
# File 'app/models/protonym.rb', line 275 def is_available?(refresh = false) if !refresh @is_available ||= !has_misspelling_or_misapplication_relationship? && !classification_unavailable? else @is_available = !has_misspelling_or_misapplication_relationship? && !classification_unavailable? end @is_available end |
#is_family_or_genus_or_species_rank? ⇒ Boolean
530 531 532 |
# File 'app/models/protonym.rb', line 530 def is_family_or_genus_or_species_rank? FAMILY_AND_GENUS_AND_SPECIES_RANK_NAMES.include?(rank_string) end |
#is_family_rank? ⇒ Boolean
534 535 536 |
# File 'app/models/protonym.rb', line 534 def is_family_rank? FAMILY_RANK_NAMES.include?(rank_string) end |
#is_genus_or_species_rank? ⇒ Boolean
526 527 528 |
# File 'app/models/protonym.rb', line 526 def is_genus_or_species_rank? GENUS_AND_SPECIES_RANK_NAMES.include?(rank_string) end |
#is_genus_rank? ⇒ Boolean
522 523 524 |
# File 'app/models/protonym.rb', line 522 def is_genus_rank? GENUS_RANK_NAMES.include?(rank_string) end |
#is_higher_rank? ⇒ Boolean
538 539 540 |
# File 'app/models/protonym.rb', line 538 def is_higher_rank? HIGHER_RANK_NAMES.include?(rank_string) end |
#is_latin? ⇒ Boolean
494 495 496 |
# File 'app/models/protonym.rb', line 494 def is_latin? !NOT_LATIN.match(name) || has_latinized_exceptions? || rank_string =~ /Icvcn::Species/ end |
#is_original_name? ⇒ Boolean
Returns Boolean.
543 544 545 |
# File 'app/models/protonym.rb', line 543 def is_original_name? =~ /\(/ ? false : true end |
#is_species_rank? ⇒ Boolean
518 519 520 |
# File 'app/models/protonym.rb', line 518 def is_species_rank? SPECIES_RANK_NAMES.include?(rank_string) end |
#list_of_coordinated_names ⇒ Object
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'app/models/protonym.rb', line 235 def list_of_coordinated_names list = [] if self.rank_string r = self.iczn_set_as_incorrect_original_spelling_of_relationship if r.blank? search_rank = NomenclaturalRank::Iczn.group_base(rank_string) if !!search_rank if search_rank =~ /Family/ if self.cached_is_valid z = Protonym.family_group_base(self.name) search_name = z.nil? ? nil : Protonym::FAMILY_GROUP_ENDINGS.collect{|i| z+i} else search_name = nil end else search_name = self.name end else search_name = nil end # r = TaxonNameRelationship.where_subject_is_taxon_name(self).with_type_array(TAXON_NAME_RELATIONSHIP_NAMES_MISSPELLING) # if !search_name.nil? && r.empty? if !search_name.nil? && is_available? list = Protonym .ancestors_and_descendants_of(self) .with_rank_class_including(search_rank) .where(name: search_name) .not_self(self) .that_is_valid else list = [] end else list = [r.object_taxon_name] end end return list end |
#lowest_rank_coordinated_taxon ⇒ Object
TODO, make back half of this raw SQL
333 334 335 336 337 338 339 340 341 |
# File 'app/models/protonym.rb', line 333 def lowest_rank_coordinated_taxon list = [self] + list_of_coordinated_names if list.count == 1 self else parents = list.collect{|i| i.parent.id} list.detect{|t| !parents.include?(t.id)} end end |
#name_is_latinized ⇒ Object (protected)
1030 1031 1032 |
# File 'app/models/protonym.rb', line 1030 def name_is_latinized errors.add(:name, 'Name must be latinized, no digits or spaces allowed') if !is_latin? end |
#name_is_valid_format ⇒ Object (protected)
1045 1046 1047 |
# File 'app/models/protonym.rb', line 1045 def name_is_valid_format rank_class.validate_name_format(self) if name.present? && rank_class && rank_class.respond_to?(:validate_name_format) && !has_latinized_exceptions? end |
#name_with_alternative_spelling ⇒ Object
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 |
# File 'app/models/protonym.rb', line 565 def name_with_alternative_spelling if rank_class.nil? || nomenclatural_code != :iczn # rank_string =~ /::Icn::/ # self.class != Protonym return nil elsif is_species_rank? # rank_string =~ /Species/ n = name.squish # remove extra spaces and line brakes n = n.split(' ').last n = n[0..-4] + 'ae' if n =~ /^[a-z]*iae$/ # -iae > -ae in the end of word n = n[0..-6] + 'orum' if n =~ /^[a-z]*iorum$/ # -iorum > -orum n = n[0..-6] + 'arum' if n =~ /^[a-z]*iarum$/ # -iarum > -arum n = n[0..-3] + 'a' if n =~ /^[a-z]*um$/ # -um > -a n = n[0..-3] + 'a' if n =~ /^[a-z]*us$/ # -us > -a n = n[0..-3] + 'e' if n =~ /^[a-z]*is$/ # -is > -e n = n[0..-3] + 'ra' if n =~ /^[a-z]*er$/ # -er > -ra n = n[0..-7] + 'ensis' if n =~ /^[a-z]*iensis$/ # -iensis > -ensis n = n[0..-5] + 'ana' if n =~ /^[a-z]*iana$/ # -iana > -ana n = n.gsub('ae', 'e') if n =~ /^[a-z]*ae[a-z]+$/ # -ae- n = n.gsub('oe', 'e'). gsub('ai', 'i'). gsub('ei', 'i'). gsub('ej', 'i'). gsub('ii', 'i'). gsub('ij', 'i'). gsub('jj', 'i'). gsub('j', 'i'). gsub('y', 'i'). gsub('v', 'u'). gsub('rh', 'r'). gsub('th', 't'). gsub('k', 'c'). gsub('ch', 'c'). gsub('tt', 't'). gsub('bb', 'b'). gsub('rr', 'r'). gsub('nn', 'n'). gsub('mm', 'm'). gsub('pp', 'p'). gsub('ss', 's'). gsub('ff', 'f'). gsub('ll', 'l'). gsub('ct', 't'). gsub('ph', 'f'). gsub('-', '') n = n[0, 3] + n[3..-4].gsub('o', 'i') + n[-3, 3] if n.length > 6 # connecting vowel in the middle of the word (nigrocinctus vs. nigricinctus) elsif rank_string =~ /Family/ n_base = Protonym.family_group_base(self.name) if n_base.nil? || n_base == self.name n = self.name else n = n_base + 'idae' end else n = self.name.squish end return n end |
#new_parent_taxon_name ⇒ Object (protected)
1049 1050 1051 1052 1053 1054 1055 1056 |
# File 'app/models/protonym.rb', line 1049 def new_parent_taxon_name r = self.iczn_uncertain_placement_relationship if r.present? if self.parent != r.object_taxon_name errors.add(:parent_id, "Taxon has an 'Incertae sedis' relationship, which prevent the parent modifications, change the relationship to 'Source classified as' before updating the parent") end end end |
#nominotypical_sub_of?(protonym) ⇒ boolean
973 974 975 |
# File 'app/models/protonym.rb', line 973 def nominotypical_sub_of?(protonym) is_genus_or_species_rank? && parent == protonym && parent.name == protonym.name end |
#number_of_taxa_by_year ⇒ Object
temporary method to get a number of taxa described by year
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'app/models/protonym.rb', line 407 def number_of_taxa_by_year file_name = '/tmp/taxa_by_year' + '_' + Time.now.to_i.to_s + '.csv' a = {} descendants.find_each do |z| year = z.year_integer year = 0 if year.nil? a[year] = {valid: 0, synonyms: 0} unless a[year] if z.rank_string == 'NomenclaturalRank::Iczn::SpeciesGroup::Species' if z.cached_is_valid a[year][:valid] = a[year][:valid] += 1 elsif TaxonNameRelationship.where_subject_is_taxon_name(z.id).with_type_array(::TAXON_NAME_RELATIONSHIP_NAMES_SYNONYM).any? a[year][:synonyms] = a[year][:synonyms] += 1 end end end for i in 1758..Time.now.year do a[i] = {valid: 0, synonyms: 0} unless a[i] end b = a.sort.to_h CSV.open(file_name, 'w') do |csv| #CSV.generate do |csv| csv << ['year', 'valid species', 'synonyms'] b.keys.each do |i| csv << [i, b[i][:valid], b[i][:synonyms]] end end end |
#original_combination_class_relationships ⇒ Object
return [Array]
TaxonNameRelationship classes that are applicable to this name, as deterimined by Rank
451 452 453 454 455 456 457 |
# File 'app/models/protonym.rb', line 451 def original_combination_class_relationships relations = [] TaxonNameRelationship::OriginalCombination.descendants.each do |r| relations.push(r) if r.valid_object_ranks.include?(self.rank_string) end relations end |
#original_combination_infraspecific_element(elements = nil, remove_sic = false) ⇒ [rank_name, name]?
Returns Used in ColDP export.
795 796 797 798 799 800 801 802 803 804 805 |
# File 'app/models/protonym.rb', line 795 def original_combination_infraspecific_element(elements = nil, remove_sic = false) elements ||= original_combination_elements elements = elements.each { |r, e| e.delete('[sic]') } if remove_sic # TODO: consider plants/other codes? [:form, :variety, :subspecies].each do |r| return [r.to_s, elements[r].last] if elements[r] end nil end |
#original_combination_relationships_and_stubs ⇒ Array
Returns A relationships for each possible original combination relationship.
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
# File 'app/models/protonym.rb', line 461 def original_combination_relationships_and_stubs # TODO: figure out where to really put this, likely in one big sort display_order = [ :original_genus, :original_subgenus, :original_species, :original_subspecies, :original_variety, :original_subvariety, :original_form, :original_subform ] defined_relations = self.original_combination_relationships.all created_already = defined_relations.collect{|a| a.class} new_relations = [] original_combination_class_relationships.each do |r| new_relations.push( r.new(object_taxon_name: self) ) if !created_already.include?(r) end (new_relations + defined_relations).sort{|a,b| display_order.index(a.class.inverse_assignment_method) <=> display_order.index(b.class.inverse_assignment_method) } end |
#original_name ⇒ String?
Returns a monominal, as originally rendered, with parens if subgenus.
809 810 811 812 813 |
# File 'app/models/protonym.rb', line 809 def original_name n = verbatim_name.nil? ? name_with_misspelling(nil) : verbatim_name n = "(#{n})" if n && rank_name == 'subgenus' n end |
#predict_three_forms ⇒ Object
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
# File 'app/models/protonym.rb', line 623 def predict_three_forms exception = LATIN_ADJECTIVES[name] return exception unless exception.nil? m_name, f_name, n_name = nil, nil, nil case name when /(color|coloris)$/ m_name, f_name, n_name = name, name, name when /is$/ m_name, f_name, n_name = name, name, name[0..-3] + 'e' when /e$/ m_name, f_name, n_name = name[0..-2] + 'is', name[0..-2] + 'is', name when /us$/ m_name, f_name, n_name = name, name[0..-3] + 'a', name[0..-3] + 'um' when /(niger|integer)$/ m_name, f_name, n_name = name, name[0..-3] + 'ra', name[0..-3] + 'rum' when /(fer|ger)$/ m_name, f_name, n_name = name, name + 'a', name + 'um' when /er$/ m_name, f_name, n_name = name, name[0..-3] + 'ra', name[0..-3] + 'rum' when /(ferum|gerum)$/ m_name, f_name, n_name = name[0..-3], name[0..-3] + 'a', name when /(gera|fera)$/ m_name, f_name, n_name = name[0..-2], name, name[0..-2] + 'um' when /(brum|frum|grum)$/ m_name, f_name, n_name = name[0..-4] + 'er', name[0..-3] + 'a', name when /(bra|gra|fra)$/ m_name, f_name, n_name = name[0..-3] + 'er', name, name[0..-2] + 'um' when /(um)$/ m_name, f_name, n_name = name[0..-3] + 'us', name[0..-3] + 'a', name when /a$/ m_name, f_name, n_name = name[0..-2] + 'us', name, name[0..-2] + 'um' when /(nor|ior|jor)$/ m_name, f_name, n_name = name, name, name[0..-3] + 'us' else m_name, f_name, n_name = name, name, name end {masculine_name: m_name, feminine_name: f_name, neuter_name: n_name} end |
#predicted_child_rank(child_string) ⇒ Object
taxon_name.predicted_children_rank(‘Cicadellidae’) >> NomenclaturalRank::Iczn::FamilyGroup::Family
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'app/models/protonym.rb', line 364 def predicted_child_rank(child_string) return nil if child_string.blank? parent_rank = rank_class.to_s parent_rank_name = rank_name ncode = nomenclatural_code return nil if ncode.nil? # Happens with some names like "Root" if child_string == child_string.downcase if !is_species_rank? r = Ranks.lookup(ncode, 'species') elsif parent_rank_name == 'species' r = Ranks.lookup(ncode, 'subspecies') elsif parent_rank_name == 'subspecies' r = Ranks.lookup(ncode, 'variety') elsif parent_rank_name == 'variety' r = Ranks.lookup(ncode, 'form') elsif parent_rank_name == 'form' r = Ranks.lookup(ncode, 'subform') else return nil end elsif child_string == child_string.capitalize if rank_name == 'genus' r = Ranks.lookup(ncode, 'subgenus') else Ranks.lookup(ncode, 'family').constantize.valid_parents.each do |r1| r2 = r1.constantize if r2.valid_name_ending.present? && child_string.end_with?(r2.valid_name_ending) && r2.typical_use && RANKS.index(r1) > RANKS.index(parent_rank) r = r1 break end end r = Ranks.lookup(ncode, 'genus') if r.nil? end else return nil end return nil if r.nil? r.constantize end |
#reduce_list_of_synonyms(list) ⇒ Object
552 553 554 555 556 557 558 559 560 561 562 563 |
# File 'app/models/protonym.rb', line 552 def reduce_list_of_synonyms(list) return [] if list.empty? list1 = list.select{|s| s.id == s.lowest_rank_coordinated_taxon.id} list1.reject!{|s| self.cached_valid_taxon_name_id == s.cached_valid_taxon_name_id} unless list1.empty? unless list1.empty? date1 = self.cached_nomenclature_date unless date1.nil? list1.reject!{|s| date1 < (s.cached_nomenclature_date ? s.cached_nomenclature_date : Time.utc(1))} end end list1 end |
#reload ⇒ Object
Reset memomized and utility variable son reload.
154 155 156 157 158 159 |
# File 'app/models/protonym.rb', line 154 def reload(*) super.tap do @_initialize_cached_build_state = {} @original_combination_elements = nil end end |
#set_cached ⇒ Object (protected)
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 |
# File 'app/models/protonym.rb', line 1129 def set_cached return true if destroyed? = .to_s # why to_s? old_cached = cached.to_s # why to_s? super if parent_id || parent # Don't do this for Root!! set_original_combination_cached_fields set_cached_homonymy set_cached_species_homonym if is_species_rank? set_cached_misspelling tn = TaxonName.find(id) # Why not "reload" set_cached_names_for_descendants if tn.cached != old_cached set_cached_names_for_dependants if tn.cached.to_s != old_cached || tn..to_s != end true end |
#set_cached_homonymy ⇒ Object (protected)
1149 1150 1151 1152 1153 1154 |
# File 'app/models/protonym.rb', line 1149 def set_cached_homonymy update_columns( cached_primary_homonym: get_genus_species(:original, :self), cached_primary_homonym_alternative_spelling: get_genus_species(:original, :alternative) ) end |
#set_cached_misspelling ⇒ Object (protected)
The only reason this is needed on this side is because of the verbatim_name checks, otherwise we could drive it from the TaxonNameRelationship creation.
1159 1160 1161 |
# File 'app/models/protonym.rb', line 1159 def set_cached_misspelling update_column(:cached_misspelling, get_cached_misspelling) end |
#set_cached_names_for_dependants ⇒ Object
909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 |
# File 'app/models/protonym.rb', line 909 def set_cached_names_for_dependants = [] combination_relationships = [] all_names = [] # This transaction makes it difficult to re-use cached fields to derive other =cached fields, # thus the existence of some cachine attributes in TaxonName. TaxonName.transaction_with_retry do if is_genus_or_species_rank? = TaxonNameRelationship.where_subject_is_taxon_name(self).with_type_contains('OriginalCombination') combination_relationships = TaxonNameRelationship.where_subject_is_taxon_name(self).with_type_contains('::Combination') end # byebug if name == 'Dus' classified_as_relationships = TaxonNameRelationship.where_object_is_taxon_name(self).with_type_contains('SourceClassifiedAs') .collect{|i| i.object_taxon_name}.uniq.each do |i| all_names.push i i.reload # byebug if name == 'Dus' i.update_cached_original_combinations end # Update values in Combinations combination_relationships.collect{|i| i.object_taxon_name}.uniq.each do |j| all_names.push j n = j.get_full_name j.update_columns( cached: n, cached_html: j.get_full_name_html(n), cached_author_year: j., # !! Only if it changed? cached_nomenclature_date: j.nomenclature_date) ## Only if it changed? end classified_as_relationships.collect{|i| i.subject_taxon_name}.uniq.each do |i| i.update_column(:cached_classified_as, i.get_cached_classified_as) end classified_as_relationships.collect{|i| i.object_taxon_name}.uniq.each do |i| all_names.push i n = i.get_full_name i.update_columns( cached: n, cached_html: i.get_full_name_html(n), cached_author_year: i., cached_nomenclature_date: i.nomenclature_date) end misspelling_relationships = TaxonNameRelationship.where_object_is_taxon_name(self).with_type_array(TAXON_NAME_RELATIONSHIP_NAMES_MISSPELLING_AND_MISAPPLICATION) misspelling_relationships.collect{|i| i.subject_taxon_name}.uniq.each do |i| all_names.push i i.update_columns( cached_author_year: i., cached_nomenclature_date: i.nomenclature_date) end # byebug if all_names.uniq.size != all_names.size || all_names.size > 1 end end |
#set_cached_names_for_descendants ⇒ Object
TODO: Are there are times where names are dependant and descendant?
Original Genus is Genus, for example
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 |
# File 'app/models/protonym.rb', line 881 def set_cached_names_for_descendants dependants = [] TaxonName.transaction_with_retry do if is_genus_or_species_rank? dependants = Protonym.unscoped.descendants_of(self).to_a end dependants.each do |i| n = i.get_full_name columns_to_update = { cached: n, cached_html: i.get_full_name_html(n), cached_author_year: i., cached_nomenclature_date: i.nomenclature_date } if i.is_species_rank? columns_to_update[:cached_secondary_homonym] = i.get_genus_species(:current, :self) columns_to_update[:cached_secondary_homonym_alternative_spelling] = i.get_genus_species(:current, :alternative) end i.update_columns(columns_to_update) end end end |
#set_cached_original_combination ⇒ Object (protected)
1163 1164 1165 1166 |
# File 'app/models/protonym.rb', line 1163 def set_cached_original_combination # byebug if name == 'aus' update_column(:cached_original_combination, get_original_combination) end |
#set_cached_original_combination_html ⇒ Object (protected)
1168 1169 1170 |
# File 'app/models/protonym.rb', line 1168 def set_cached_original_combination_html update_column(:cached_original_combination_html, get_original_combination_html) end |
#set_cached_species_homonym ⇒ Object
871 872 873 874 875 876 |
# File 'app/models/protonym.rb', line 871 def set_cached_species_homonym update_columns( cached_secondary_homonym: get_genus_species(:current, :self), cached_secondary_homonym_alternative_spelling: get_genus_species(:current, :alternative) ) end |
#set_original_combination_cached_fields ⇒ Object (protected)
All cached values that relate to an original combination should be referenced here so that they can be re-referenced indirectly from TaxonNameRelationships In particular those impacted by an OriginalCombination.
1175 1176 1177 1178 |
# File 'app/models/protonym.rb', line 1175 def set_original_combination_cached_fields set_cached_original_combination set_cached_original_combination_html end |
#species_questionable_ending(taxon_name_classification_class, tested_name) ⇒ Object
673 674 675 676 677 678 679 |
# File 'app/models/protonym.rb', line 673 def species_questionable_ending(taxon_name_classification_class, tested_name) return nil unless is_species_rank? taxon_name_classification_class.questionable_species_endings.each do |e| return e if tested_name =~ /^[a-z]*#{e}$/ end nil end |
#sv_cached_names ⇒ Object (protected)
!! This has to go. A single method is meaningless to the user and to developers. Which cached is the problem it the problem? We simply can’t tell what went wrong in this case.
This is a very expensive soft validation, it should be fragemented into individual parts likely. It should also not be necessary by default our code should be good enough to handle these issues in the long run. DD: rules for cached tend to evolve, what was good in the past, may not be true today MJY: If the meaning of cached changes then it should be removed, not changed.
1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 |
# File 'app/models/protonym.rb', line 1099 def sv_cached_names # this cannot be moved to soft_validation_extensions is_cached = true is_cached = false if != is_cached = false if != # Right side values should call methods that calculate from the db if is_cached && ( cached_valid_taxon_name_id != get_valid_taxon_name.id || cached_is_valid != !unavailable_or_invalid? || cached_html != get_full_name_html || cached_misspelling != get_cached_misspelling || cached_original_combination != get_original_combination || cached_original_combination_html != get_original_combination_html || cached_primary_homonym != get_genus_species(:original, :self) || cached_nomenclature_date != nomenclature_date || cached_primary_homonym_alternative_spelling != get_genus_species(:original, :alternative) || rank_string =~ /Species/ && (cached_secondary_homonym != get_genus_species(:current, :self) || cached_secondary_homonym_alternative_spelling != get_genus_species(:current, :alternative))) is_cached = false end soft_validations.add( :base, 'Cached values should be updated', success_message: 'Cached values were updated', failure_message: 'Failed to update cached values') unless is_cached end |
#synonymize_with(protonym) ⇒ Object
A convenience method to make this name a low-level synonym of another. Presently limited in scope to names that share rank (not rank group)
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'app/models/protonym.rb', line 201 def synonymize_with(protonym) return false if protonym.nil? return false if protonym.rank_class.to_s != rank_class.to_s begin case nomenclatural_code when :iczn TaxonNameRelationship::Iczn::Invalidating::Synonym.create!(subject_taxon_name: self, object_taxon_name: protonym) when :icn TaxonNameRelationship::Icn::Unaccepting::Synonym.create!(subject_taxon_name: self, object_taxon_name: protonym) when :icnp TaxonNameRelationship::Icnp::Unaccepting::Synonym.create!(subject_taxon_name: self, object_taxon_name: protonym) when :icvnc TaxonNameRelationship::Icnp::Unaccepting::SupressedSynony.create!(subject_taxon_name: self, object_taxon_name: protonym) else return false end rescue ActiveRecord::RecordInvalid return false end end |
#update_cached_original_combinations ⇒ Object
857 858 859 860 861 862 863 864 865 866 867 868 869 |
# File 'app/models/protonym.rb', line 857 def update_cached_original_combinations # if @pp # @pp += 1 # else # @pp = 1 # end update_columns( cached_original_combination: get_original_combination, cached_original_combination_html: get_original_combination_html, cached_primary_homonym: get_genus_species(:original, :self), cached_primary_homonym_alternative_spelling: get_genus_species(:original, :alternative)) # puts Rainbow(@pp).orange.bold end |
#validate_child_rank_is_equal_or_lower ⇒ Object (protected)
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 |
# File 'app/models/protonym.rb', line 1062 def validate_child_rank_is_equal_or_lower if parent && rank_class.present? && rank_string != 'NomenclaturalRank' if rank_class_changed? a = children.where(type: 'Protonym').pluck(:rank_class) v = RANKS.index(rank_string) a.each do |b| if v >= RANKS.index(b) errors.add(:rank_class, "The rank of this taxon (#{rank_name}) should be higher than the ranks of children") break end end end end end |
#validate_parent_rank_is_higher ⇒ Object (protected)
1077 1078 1079 1080 1081 1082 1083 |
# File 'app/models/protonym.rb', line 1077 def validate_parent_rank_is_higher if parent && rank_class.present? && rank_string != 'NomenclaturalRank' if RANKS.index(rank_string).to_i <= RANKS.index(parent.rank_string).to_i errors.add(:parent_id, "The parent rank (#{parent.rank_class.rank_name}) is not higher than the rank (#{rank_name}) of this taxon") end end end |
#validate_rank_class_class ⇒ Object (protected)
1058 1059 1060 |
# File 'app/models/protonym.rb', line 1058 def validate_rank_class_class errors.add(:rank_class, 'Rank not found') unless RANKS.include?(rank_string) end |
#validate_same_nomenclatural_code ⇒ Object (protected)
1085 1086 1087 1088 1089 |
# File 'app/models/protonym.rb', line 1085 def validate_same_nomenclatural_code if parent&.nomenclatural_code && nomenclatural_code != parent.nomenclatural_code errors.add(:rank_class, "The parent nomenclatural code (#{parent.nomenclatural_code.to_s.upcase}) is not matching to the nomenclatural code (#{nomenclatural_code.to_s.upcase}) of this taxon") end end |
#verbatim_author_with_closed_parens_when_present ⇒ Object (protected)
1038 1039 1040 1041 1042 1043 |
# File 'app/models/protonym.rb', line 1038 def if .present? and nomenclatural_code != :icn # workaround until basyonim field exists # Regex matches two possible, both params, or no params at start/end errors.add(:verbatim_author, 'Verbatim author is missing a parenthesis') unless =~ /\A\([^()]+\)\z|\A[^()]+\z/ end end |
#verbatim_author_without_digits ⇒ Object (protected)
1034 1035 1036 |
# File 'app/models/protonym.rb', line 1034 def errors.add(:verbatim_author, 'Verbatim author may not contain digits, a year may be present') if =~ /\d/ end |