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



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

def best_match_type
  best_result&.match_type
end

#best_resultObject

Verification helpers



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

def best_result
  found.verification.best_result if is_verified?
end

#classification_pathObject



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

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

#classification_rankObject



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

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

#is_in_taxonworks?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/vendor/gnfinder/name.rb', line 76

def is_in_taxonworks?
  matches.any?
end

#is_low_probability?Boolean

Returns:

  • (Boolean)


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

def is_low_probability?
  log_odds < LOW_PROBABILITY
end

#is_new_name?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/vendor/gnfinder/name.rb', line 62

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

#is_verified?Boolean

Returns:

  • (Boolean)


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

def is_verified?
  found.verification && found.verification.best_result.match_type != :NONE
end

#log_oddsObject

Generic helpers



58
59
60
# File 'lib/vendor/gnfinder/name.rb', line 58

def log_odds
  Math.log10(found.odds)
end

#matchesObject

Returns Array of TaxonName.

Returns:

  • Array of TaxonName



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

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

#protonym_nameObject



66
67
68
# File 'lib/vendor/gnfinder/name.rb', line 66

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

#taxonworks_parentObject



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

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

#taxonworks_parent_nameObject



80
81
82
83
84
85
86
87
88
# File 'lib/vendor/gnfinder/name.rb', line 80

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



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

def words_after
  found.words_after || []
end

#words_beforeObject

Name helpers



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

def words_before
  found.words_before || []
end