Module: Export::Coldp::Files::Synonym

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

Overview

Bigger picture: understand how this maps to core name usage table in CoL

Class Method Summary collapse

Class Method Details

.generate(otus, reference_csv = nil) ⇒ Object

This is currently factored to use no ActiveRecord instances



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

def self.generate(otus, reference_csv = nil)
  CSV.generate(col_sep: "\t") do |csv|

    csv << %w{taxonID nameID status remarks referenceID}

    # Only valid otus with taxon names, see lib/export/coldp.rb#otus
    otus.select('otus.id id, taxon_names.cached cached, otus.taxon_name_id taxon_name_id')
      .pluck(:id, :cached, :taxon_name_id)
      .each do |o|

        # TODO: Confirm resolved: original combinations of invalid names are not being handled correclty in reified

        # Here we grab the hierarchy again, and filter it by
        #   1) allow only invalid names OR names with differing original combinations
        #   2) of 1) eliminate Combinations with identical names to current placement
        #
        a = TaxonName.that_is_invalid
          .where(cached_valid_taxon_name_id: o[2])
          .where.not("(taxon_names.type = 'Combination' AND taxon_names.cached = ?)", o[1])

        b = TaxonName.where(cached_valid_taxon_name_id: o[2])
          .where("(taxon_names.cached_original_combination != taxon_names.cached)")
          .where.not("(taxon_names.type = 'Combination' AND taxon_names.cached = ?)", o[1])

        c = TaxonName.from("((#{a.to_sql}) UNION (#{b.to_sql})) as taxon_names")

        # HernĂ¡n notes:
        # TaxonName.where(cached_valid_taxon_name_id: 42).merge(TaxonName.where.not(type: 'Combination').or(TaxonName.where.not(cached: 'Forty two'))).to_sql

        # Original concept
        # TaxonName
        #   .where(cached_valid_taxon_name_id: o[2]) # == .historical_taxon_names
        #   .where("( ((taxon_names.id != taxon_names.cached_valid_taxon_name_id) OR ((taxon_names.cached_original_combination != taxon_names.cached))) AND NOT (taxon_names.type = 'Combination' AND taxon_names.cached = ?))", o[1]) # see name.rb

        c.pluck(:id, :cached, :cached_original_combination, :type)
          .each do |t|
            reified_id = ::Export::Coldp.reified_id(t[0], t[1], t[2])

            csv << [
              o[0],           # taxonID attached to the current valid concept
              reified_id,     # nameID
              nil,            # Status TODO def status(taxon_name_id)
              remarks_field,
              nil,            # Unclear what this means in TW
            ]
          end
      end
  end
end

.reference_id_field(otu) ⇒ Object



24
25
26
# File 'lib/export/coldp/files/synonym.rb', line 24

def self.reference_id_field(otu)
  nil
end

.remarks_fieldObject



20
21
22
# File 'lib/export/coldp/files/synonym.rb', line 20

def self.remarks_field
  nil
end

.status(o, t) ⇒ Object

Returns:

  • String



11
12
13
14
15
16
17
18
# File 'lib/export/coldp/files/synonym.rb', line 11

def self.status(o, t)
  #'accepted'
  #'provisionally accepted'
  #'synonym'
  #'ambiguous synonym'
  #'missaplied'
  'synonym'
end