Class: Vendor::Gnfinder::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/vendor/gnfinder/name.rb

Overview

Constant Summary collapse

LOW_PROBABILITY =

A hack at present, balance versus language and ongoing. For now, anything negative probability seems unlikely.

3.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(found_name, project_id = []) ⇒ Name

params found_name [Gnfinder name]



17
18
19
20
# File 'lib/vendor/gnfinder/name.rb', line 17

def initialize(found_name, project_id = [])
  @project_id = project_id
  @found = found_name
end

Instance Attribute Details

#foundObject

Alias for Name



14
15
16
# File 'lib/vendor/gnfinder/name.rb', line 14

def found
  @found
end

#project_idObject

Returns the value of attribute project_id.



11
12
13
# File 'lib/vendor/gnfinder/name.rb', line 11

def project_id
  @project_id
end

Instance Method Details

#best_match_typeObject



64
65
66
# File 'lib/vendor/gnfinder/name.rb', line 64

def best_match_type
  best_result&.match_type
end

#best_resultObject

Verification helpers



52
53
54
# File 'lib/vendor/gnfinder/name.rb', line 52

def best_result
  found.verification.best_result if is_verified?
end

#classification_pathObject



43
44
45
# File 'lib/vendor/gnfinder/name.rb', line 43

def classification_path
  found&.verification&.best_result&.classification_path&.split('|') || []
end

#classification_rankObject



47
48
49
# File 'lib/vendor/gnfinder/name.rb', line 47

def classification_rank
  found&.verification&.best_result&.classification_ranks&.split('|') || []
end

#is_in_taxonworks?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/vendor/gnfinder/name.rb', line 88

def is_in_taxonworks?
  matches.any?
end

#is_low_probability?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/vendor/gnfinder/name.rb', line 60

def is_low_probability?
  log_odds < LOW_PROBABILITY
end

#is_new_name?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/vendor/gnfinder/name.rb', line 74

def is_new_name?
  %w{SP_NOV COMB_NOV SUBSP_NOV}.include?(found.annotation_nomen_type)
end

#is_verified?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/vendor/gnfinder/name.rb', line 56

def is_verified?
  [nil, 'NoMatch'].exclude?(found.verification.best_result&.match_type)
end

#log_oddsObject

Generic helpers



70
71
72
# File 'lib/vendor/gnfinder/name.rb', line 70

def log_odds
  found.odds_log10
end

#matchesObject

Returns Array of TaxonName.

Returns:

  • Array of TaxonName



83
84
85
86
# File 'lib/vendor/gnfinder/name.rb', line 83

def matches
  TaxonName.where(project_id:, cached: found.name)
    .or( TaxonName.where(project_id:, cached_original_combination: found.name))
end

#protonym_nameObject



78
79
80
# File 'lib/vendor/gnfinder/name.rb', line 78

def protonym_name
  found.name.split(' ').last
end

#taxonworks_parentObject



102
103
104
105
106
107
# File 'lib/vendor/gnfinder/name.rb', line 102

def taxonworks_parent
  return nil unless taxonworks_parent_name
  TaxonName.find_by(
    name: taxonworks_parent_name,
    project_id:)
end

#taxonworks_parent_nameObject



92
93
94
95
96
97
98
99
100
# File 'lib/vendor/gnfinder/name.rb', line 92

def taxonworks_parent_name
  case found.cardinality
  when 0
    nil
  else
    # TODO: likely not right with sp. nov.
    found.name.split(' ')[-2]
  end
end

#words_afterObject



39
40
41
# File 'lib/vendor/gnfinder/name.rb', line 39

def words_after
  found.words_after || []
end

#words_beforeObject



35
36
37
# File 'lib/vendor/gnfinder/name.rb', line 35

def words_before
  found.words_before || []
end

#words_endObject



31
32
33
# File 'lib/vendor/gnfinder/name.rb', line 31

def words_end
  found.end
end

#words_startObject



27
28
29
# File 'lib/vendor/gnfinder/name.rb', line 27

def words_start
  found.start
end