Module: Export::Coldp::Files::Name

Defined in:
lib/export/coldp/files/name.rb

Class Method Summary collapse

Class Method Details

.add_original_combination(t, csv) ⇒ Object

Invalid Protonyms are rendered only as their original Combination

Parameters:

  • t (Protonym)

    only place that var./frm can be handled.



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
# File 'lib/export/coldp/files/name.rb', line 46

def self.add_original_combination(t, csv)
  e = t.original_combination_elements

  infraspecific_element = t.original_combination_infraspecific_element(e)
  rank = infraspecific_element ? infraspecific_element.first : t.rank

  id = t.reified_id

  csv << [
    id,                                                                                     # ID
    id,                                                                                     # basionymID, always nil, this is the original
    t.cached_original_combination,                                                          # scientificName
    authorship_field(t, true),                                                              # authorship
    rank,                                                                                   # rank
    nil,                                                                                    # uninomial
    (e[:genus]&.last =~ /NOT SPECIFIED/) ? nil : e[:genus]&.last,                           # genus
    (e[:subgenus]&.last =~ /NOT SPECIFIED/) ? nil : e[:subgenus]&.last&.gsub(/[\)\(]/, ''), # subgenus (no parens) # TODO - optimize to not have to strip these
    (e[:species]&.last =~ /NOT SPECIFIED/) ? nil : e[:species]&.last,                       # species
    infraspecific_element ? infraspecific_element.last : nil,                           # infraspecificEpithet
    nil,                                                                                # publishedInID   |
    nil,                                                                                # publishedInPage |-- Decisions is that these add to Synonym table
    nil,                                                                                # publishedInYear |
    true,                                                                               # original
    code_field(t),                                                                      # code
    nil,                                                                                # status https://api.catalogue.life/vocab/nomStatus
    nil,                                                                                # link (probably TW public or API)
    remarks_field(t),                                                                   # remarks
  ]
end

.authorship_field(taxon_name, original) ⇒ Object

Returns String.

Returns:

  • String



21
22
23
# File 'lib/export/coldp/files/name.rb', line 21

def self.authorship_field(taxon_name, original)
  original ? taxon_name.original_author_year : taxon_name.cached_author_year
end

.code_field(taxon_name) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/export/coldp/files/name.rb', line 3

def self.code_field(taxon_name)
  case taxon_name.nomenclatural_code
  when :iczn
    'ICZN'
  when :icn
    'ICN'
  when :icnp
    'ICNP'
  when :icvcn
    'ICVCN'
  end
end

.generate(otu, reference_csv = nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/export/coldp/files/name.rb', line 78

def self.generate(otu, reference_csv = nil)
  CSV.generate(col_sep: "\t") do |csv|
    csv << %w{
      ID
      basionymID
      scientificName
      authorship
      rank
      uninomial
      genus
      infragenericEpithet
      specificEpithet
      infraspecificEpithet
      publishedInID
      publishedInPage
      publishedInYear
      original
      code
      status
      link
      remarks
    }

    # why we getting double
    unique = {}

    otu.taxon_name.self_and_descendants.each do |name|

      # TODO: handle > quadranomial names (e.g. super species like `Bus (Dus aus aus) aus eus var. fus`
      # Proposal is to exclude names of a specific ranks see taxon.rb
      #
      # Need the next highest valid parent not in this list!!
      # %w{
      #   NomenclaturalRank::Iczn::SpeciesGroup::Supersuperspecies
      #   NomenclaturalRank::Iczn::SpeciesGroup::Superspecies
      # }
      #
      # infragenericEpithet needs to handle subsection (NomenclaturalRank::Icn::GenusGroup::Subsection)

      if name.is_valid?
        data = ::Catalog::Nomenclature::Entry.new(name)

        data.names.each do |t|
          source = t.source

          original = Export::Coldp.original_field(t) # Protonym, no parens
          higher = !t.is_combination? && !t.is_species_rank?

          elements = t.full_name_hash if !higher

          basionym_id = t.reified_id

          # higher, valid, combination and not added
          if higher || t.is_valid? || t.is_combination? # && unique[basionym_id].nil?
            # unique[basionym_id] = true
            csv << [
              t.id,                                               # ID
              basionym_id,                                        # basionymID
              t.cached,                                           # scientificName
              t.cached_author_year,                               # authorship
              t.rank,                                             # rank
              (higher ? t.cached : nil),                          # uninomial
              (higher ? nil : elements['genus']&.last),           # genus and below - IIF species or lower
              (higher ? nil : elements['subgenus']&.last),        # infragenericEpithet
              (higher ? nil : elements['species']&.last),         # specificEpithet
              (higher ? nil : elements['subspecies']&.last),      # infraspecificEpithet
              source&.id,                                         # publishedInID
              source&.pages,                                      # publishedInPage
              t.year_of_publication,                              # publishedInYear
              original,                                           # original
              code_field(t),                                      # code
              nom_status_field(t),                                # nomStatus
              nil,                                                # link (probably TW public or API)
              remarks_field(t),                                   # remarks
            ]
          end

          if (!higher && !t.is_combination? && (!t.is_valid? || t.has_alternate_original?)) && unique[basionym_id].nil?
            unique[basionym_id] = true
            add_original_combination(t, csv)
          end

          Export::Coldp::Files::Reference.add_reference_rows([source].compact, reference_csv) if reference_csv && source
        end
      end
    end
  end
end

.nom_status_field(taxon_name) ⇒ String?

Returns:

  • (String, nil)


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/export/coldp/files/name.rb', line 29

def self.nom_status_field(taxon_name)
  case taxon_name.type
  when 'Combination'
    'chresonym' # TODO: remove this for updated semantics
  else
    if taxon_name.is_valid?
      ::TaxonName::NOMEN_VALID[taxon_name.nomenclatural_code]
    else
      c = taxon_name.taxon_name_classifications_for_statuses.order_by_youngest_source_first.first
      c ? c.class::NOMEN_URI : nil # We should also infer status from TaxonNameRelationship see
    end
  end
end

.remarks_field(taxon_name) ⇒ Object



16
17
18
# File 'lib/export/coldp/files/name.rb', line 16

def self.remarks_field(taxon_name)
  Utilities::Strings.nil_squish_strip(taxon_name.notes.collect{|n| n.text}.join('; ')) # remarks - !! check for tabs
end