Class: Autoselect::TaxonName::Levels::ColValidName

Inherits:
Level
  • Object
show all
Includes:
Levels::ColRecordLabel, Levels::ColResolvedName
Defined in:
lib/autoselect/taxon_name/levels/col_valid_name.rb

Overview

lib/autoselect/taxon_name/levels/col_valid_name.rb Resolves a term through Catalogue of Life synonymy to its accepted names, then reuses ColMatch for the actual alignment/extension data and existing-TaxonName check — feeding it the accepted nameusage hashes that resolve_accepted_names already returned, so no second CoL search is needed.

Returns one record per accepted name the term resolves to (usually one; homonyms give several, see Vendor::Colrapi.resolve_accepted_names) — a CoL pseudo-record flagged with resolved_from: so the confirmation UI can show it's the accepted name for what was typed, not a literal search match. It's a CoL record even when the name is already a TaxonName in the project, so the confirmation UI can still show (and offer to create) missing ancestors.

Constant Summary

Constants included from Levels::ColSourceMark

Levels::ColSourceMark::COL_ICON, Levels::ColSourceMark::TW_ICON

Constants inherited from Level

Level::DEFAULT_FUSE_MS, Level::EXTERNAL_FUSE_MS, Level::MINIMUM_RESULTS

Instance Method Summary collapse

Methods included from Levels::ColRecordLabel

#col_author_year, #record_label, #record_label_html

Methods included from Levels::ColResolvedName

#col_resolved_badges, #record_info, #record_info_html, #resolved_from, #resolved_synonym

Methods included from Levels::ColSourceMark

#col_existing_record?, #col_source_icon, #col_source_tag

Methods inherited from Level

#fuse_ms, #metadata, #minimum_results, #model_key, #record_info, #record_info_html, #record_label, #record_label_html

Instance Method Details

#call(term:, operator: nil, project_id: nil, user_id: nil, dataset_id: nil, **_kwargs) ⇒ Array<OpenStruct>

Returns a CoL result per resolved valid name (its target_taxonworks_id set when the name already exists).

Parameters:

  • term (String)
  • project_id (Integer, nil) (defaults to: nil)
  • dataset_id (String, nil) (defaults to: nil) —

    CoL dataset ID from user preferences; falls back to default when nil

Returns:

  • (Array<OpenStruct>) —

    a CoL result per resolved valid name (its target_taxonworks_id set when the name already exists)



54
55
56
57
58
59
# File 'lib/autoselect/taxon_name/levels/col_valid_name.rb', line 54

def call(
  term:, operator: nil, project_id: nil, user_id: nil, dataset_id: nil,
  **_kwargs
)
  resolve_targets(term, project_id:, dataset_id:)
end

#description ⇒ Object



27
28
29
30
# File 'lib/autoselect/taxon_name/levels/col_valid_name.rb', line 27

def description
  'Resolve the term through Catalogue of Life synonymy to its ' \
    'accepted name.'
end

#external? ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/autoselect/taxon_name/levels/col_valid_name.rb', line 32

def external?
  true
end

#is_default ⇒ Object

Opt-in only — fast/smart/catalogue_of_life cover the common cases; this stays present-but-unchecked in the preferences modal until a user opts in.



44
45
46
# File 'lib/autoselect/taxon_name/levels/col_valid_name.rb', line 44

def is_default
  false
end

#key ⇒ Object



19
20
21
# File 'lib/autoselect/taxon_name/levels/col_valid_name.rb', line 19

def key
  :col_valid_name
end

#label ⇒ Object



23
24
25
# File 'lib/autoselect/taxon_name/levels/col_valid_name.rb', line 23

def label
  'CoL Valid Name'
end

#options_level ⇒ Object

Searches with the CoL dataset chosen for the catalogue_of_life level.



37
38
39
# File 'lib/autoselect/taxon_name/levels/col_valid_name.rb', line 37

def options_level
  :catalogue_of_life
end

#resolve_targets(term, project_id:, dataset_id: nil) ⇒ Array<OpenStruct>

The resolved pseudo-records — each accepted name's CoL alignment/extension data plus ColMatch's existing-TaxonName check, marked with their code when they span more than one (ColCodeBadge). Empty when CoL resolves nothing usable.

The extension's resolved_from is term; when CoL followed synonymy, resolved_synonym holds the synonym it matched, with its authorship (nil otherwise), and resolved_ambiguous is true when that synonym is an ambiguous one (this is only one of its valid names).

Returns:

  • (Array<OpenStruct>)


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/autoselect/taxon_name/levels/col_valid_name.rb', line 72

def resolve_targets(term, project_id:, dataset_id: nil)
  targets = ::Vendor::Colrapi.resolve_accepted_names(term, dataset_id:)
    .filter_map do |resolved|
      next if resolved[:valid_name].blank? ||
        resolved[:valid_col_result].blank?

      target = ::Autoselect::TaxonName::ColMatch.new(
        resolved[:valid_col_result],
        project_id:,
        dataset_id: resolved[:dataset_id]
      ).call
      next if target.nil?

      followed = resolved[:matched_col_key] != resolved[:valid_col_key]
      resolved_synonym =
        if followed
          [resolved[:matched_name], resolved[:matched_authorship]]
            .compact.join(' ')
        end
      resolved_ambiguous =
        followed && resolved[:matched_status] == 'ambiguous synonym'
      target._col_extension = target._col_extension.merge(
        resolved_from: term, resolved_synonym:, resolved_ambiguous:
      )

      target
    end

  ::Autoselect::Levels::ColCodeBadge.mark(targets)
end