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



68
69
70
# File 'lib/vendor/gnfinder/name.rb', line 68

def best_match_type
  best_result&.match_type
end

#best_resultObject

Verification helpers



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

def best_result
  found.verification.best_result if is_verified?
end

#classification_pathObject



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

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

#classification_rankObject



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

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

#is_in_taxonworks?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/vendor/gnfinder/name.rb', line 92

def is_in_taxonworks?
  matches.any?
end

#is_low_probability?Boolean

Returns:

  • (Boolean)


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

def is_low_probability?
  log_odds < LOW_PROBABILITY
end

#is_new_name?Boolean

Returns:

  • (Boolean)


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

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

#is_verified?Boolean

Returns:

  • (Boolean)


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

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

#log_oddsObject

Generic helpers



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

def log_odds
  found.odds_log10
end

#matchesObject

Returns Array of TaxonName.

Returns:

  • Array of TaxonName



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

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

#nameObject

Name helpers



23
24
25
# File 'lib/vendor/gnfinder/name.rb', line 23

def name
  found.name
end

#protonym_nameObject



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

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

#taxonworks_parentObject



106
107
108
109
110
111
# File 'lib/vendor/gnfinder/name.rb', line 106

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

#taxonworks_parent_nameObject



96
97
98
99
100
101
102
103
104
# File 'lib/vendor/gnfinder/name.rb', line 96

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

#verbatimObject



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

def verbatim
  found.verbatim
end

#words_afterObject



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

def words_after
  found.words_after || []
end

#words_beforeObject



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

def words_before
  found.words_before || []
end

#words_endObject



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

def words_end
  found.end
end

#words_startObject



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

def words_start
  found.start
end