Module: Export::Coldp::Files::Synonym
- Defined in:
- lib/export/coldp/files/synonym.rb
Overview
The synonym table is a list of all the Names (valid and invalid) that have been used for valid OTUs (Taxa) in the current classification.
Only TaxonIds for valid OTUs valid taxon names should be here, though the CoL parser format will apparently handle taxon ids that are not in the taxon table.
Bigger picture: understand how this maps to core name usage table in CoL
We assume that the names exporting in Names are those that must be tied to Taxa, so we re-use that scoping.
!! TODO: While the scoping of names to be considered is likely correct, invalid names are not likely pointing to valid OTUs, but rather invalid OTUs.
!? To resolve this create a single lookup of all possibile name_ids to their valid otu_id !! TODO: If a lookup is in place, then we can do this all in parallel with Name.tsv, i.e. completely removing a redundant pass
Class Method Summary collapse
-
.add_combinations(otu, csv, project_members, otu_lookup) ⇒ Object
TODO: This has no autonym detection now, is it an issue?.
- .add_invalid_core_names(otu, csv, project_members, otu_lookup) ⇒ Object
- .add_invalid_family_and_higher_names(otu, csv, project_members, otu_lookup) ⇒ Object
-
.add_invalid_original_combinations(otu, csv, project_members, otu_lookup) ⇒ Object
Add synonyms for invalid names with different original combinations (reified IDs).
- .add_original_combinations(otu, csv, project_members, otu_lookup) ⇒ Object
- .autonym_synonym?(name) ⇒ Boolean
- .generate(otu, otus, project_members, reference_csv = nil) ⇒ Object
-
.status(o, t) ⇒ Object
Last 3 of api.checklistbank.org/vocab/taxonomicstatus.
Class Method Details
.add_combinations(otu, csv, project_members, otu_lookup) ⇒ Object
TODO: This has no autonym detection now, is it an issue?
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/export/coldp/files/synonym.rb', line 79 def self.add_combinations(otu, csv, project_members, otu_lookup) names = ::Export::Coldp::Files::Name.combination_names(otu).unscope(:select).select('taxon_names.*') names.length # !! Required - without this the result is truncated (see name.rb comment) # Iterate directly over names to avoid CTE truncation issues names.find_each do |t| next if ::Export::Coldp.skipped_combinations.include?(t.id) csv << [ otu_lookup[t.cached_valid_taxon_name_id], # taxonID attached to the current valid concept t.id, # nameID nil, # status TODO: def status(taxon_name_id) nil, # remarks nil, # referenceID Unclear what this means in TW Export::Coldp.modified(t.updated_at), # modified Export::Coldp.modified_by(t.updated_by_id, project_members) # modifiedBy ] end end |
.add_invalid_core_names(otu, csv, project_members, otu_lookup) ⇒ Object
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 |
# File 'lib/export/coldp/files/synonym.rb', line 51 def self.add_invalid_core_names(otu, csv, project_members, otu_lookup) names = ::Export::Coldp::Files::Name.invalid_core_names(otu) names.length # !! Required - without this the result is truncated (see name.rb comment) # Iterate directly over names (like name.rb does) to avoid CTE truncation issues names.find_each do |t| # Names like missaplications do not point to a valid name, i.e. their id == cached_valid_taxon_. # - Add a synonym relationships to have them appear here. # - Names skipped here are treated as bare names in CoL taxon_id = otu_lookup[t.cached_valid_taxon_name_id] next unless taxon_id next if autonym_synonym?(t) csv << [ taxon_id, # taxonID attached to the current valid concept t.id, # nameID nil, # status TODO: def status(taxon_name_id) nil, # remarks nil, # referenceID Unclear what this means in TW Export::Coldp.modified(t.updated_at), # modified Export::Coldp.modified_by(t.updated_by_id, project_members) # modifiedBy ] end end |
.add_invalid_family_and_higher_names(otu, csv, project_members, otu_lookup) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/export/coldp/files/synonym.rb', line 101 def self.add_invalid_family_and_higher_names(otu, csv, project_members, otu_lookup) names = ::Export::Coldp::Files::Name.invalid_family_and_higher_names(otu) names.length # !! Required - without this the result is truncated (see name.rb comment) # Iterate directly over names to avoid CTE truncation issues names.find_each do |t| csv << [ otu_lookup[t.cached_valid_taxon_name_id], # taxonID attached to the current valid concept t.id, # nameID nil, # status TODO: def status(taxon_name_id) nil, # remarks nil, # referenceID Unclear what this means in TW Export::Coldp.modified(t.updated_at), # modified Export::Coldp.modified_by(t.updated_by_id, project_members) # modifiedBy ] end end |
.add_invalid_original_combinations(otu, csv, project_members, otu_lookup) ⇒ Object
Add synonyms for invalid names with different original combinations (reified IDs)
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/export/coldp/files/synonym.rb', line 146 def self.add_invalid_original_combinations(otu, csv, project_members, otu_lookup) names = ::Export::Coldp::Files::Name.invalid_original_combination_names(otu) names.length # !! Required - without this the result is truncated (see name.rb comment) # Iterate directly over names to avoid CTE truncation issues names.find_each do |t| next if autonym_synonym?(t) # By `invalid_original_combination_names(otu) these are all reified reified_id = ::Utilities::Nomenclature.reified_id( t.id, ::Utilities::Nomenclature.unmisspell_name(t.cached_original_combination) ) csv << [ otu_lookup[t.cached_valid_taxon_name_id], # taxonID attached to the current valid concept reified_id, # nameID nil, # status TODO: def status(taxon_name_id) nil, # remarks nil, # referenceID Unclear what this means in TW Export::Coldp.modified(t.updated_at), # modified Export::Coldp.modified_by(t.updated_by_id, project_members) # modifiedBy ] end end |
.add_original_combinations(otu, csv, project_members, otu_lookup) ⇒ Object
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 |
# File 'lib/export/coldp/files/synonym.rb', line 119 def self.add_original_combinations(otu, csv, project_members, otu_lookup) names = ::Export::Coldp::Files::Name.original_combination_names(otu) names.length # !! Required - without this the result is truncated (see name.rb comment) # Iterate directly over names to avoid CTE truncation issues names.find_each do |t| next if autonym_synonym?(t) # By `original_combination_names(otu) these are all reified reified_id = ::Utilities::Nomenclature.reified_id( t.id, ::Utilities::Nomenclature.unmisspell_name(t.cached_original_combination) ) csv << [ otu_lookup[t.cached_valid_taxon_name_id], # taxonID attached to the current valid concept reified_id, # nameID nil, # status TODO: def status(taxon_name_id) nil, # remarks nil, # referenceID Unclear what this means in TW Export::Coldp.modified(t.updated_at), # modified Export::Coldp.modified_by(t.updated_by_id, project_members) # modifiedBy ] end end |
.autonym_synonym?(name) ⇒ Boolean
172 173 174 175 |
# File 'lib/export/coldp/files/synonym.rb', line 172 def self.autonym_synonym?(name) return true if name.parent_name == name.name return name.cached.scan(name.name).count == 2 end |
.generate(otu, otus, project_members, reference_csv = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/export/coldp/files/synonym.rb', line 34 def self.generate(otu, otus, project_members, reference_csv = nil) # Build OTU lookup hash once to avoid N+1 queries # Maps taxon_name_id -> otu.id for all OTUs in scope otu_lookup = otus.pluck(:taxon_name_id, :id).to_h ::CSV.generate(col_sep: "\t") do |csv| csv << %w{taxonID nameID status remarks referenceID modified modifiedBy} add_invalid_family_and_higher_names(otu, csv, project_members, otu_lookup) add_invalid_core_names(otu, csv, project_members, otu_lookup) add_original_combinations(otu, csv, project_members, otu_lookup) # Handles reified IDs add_invalid_original_combinations(otu, csv, project_members, otu_lookup) # Handles reified IDs add_combinations(otu, csv, project_members, otu_lookup) end end |
.status(o, t) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/export/coldp/files/synonym.rb', line 23 def self.status(o, t) #'accepted' #'provisionally accepted' #'synonym' #'ambiguous synonym' #'missaplied' 'synonym' end |