class Taxamatch::Atomizer
Public Class Methods
new()
click to toggle source
# File lib/taxamatch_rb/atomizer.rb, line 7 def initialize @parser = ScientificNameParser.new @parsed_raw = nil @res = {} end
Public Instance Methods
organize_results(parsed_raw)
click to toggle source
# File lib/taxamatch_rb/atomizer.rb, line 22 def organize_results(parsed_raw) pr = parsed_raw return nil unless pr[:parsed] @res = {:all_authors => [], :all_years => []} d = pr[:details][0] @res[:canonical_form] = pr[:canonical] process_node(:uninomial, d[:uninomial]) process_node(:genus, d[:genus]) process_node(:species, d[:species], true) process_infraspecies(d[:infraspecies]) @res[:all_authors] = @res[:all_authors].uniq.map do |a| Taxamatch::Normalizer.normalize(a) end @res[:all_years].uniq! @res.keys.size > 2 ? @res : nil end
parse(name)
click to toggle source
# File lib/taxamatch_rb/atomizer.rb, line 13 def parse(name) @parsed_raw = @parser.parse(name)[:scientificName] organize_results(@parsed_raw) end
parsed_raw()
click to toggle source
# File lib/taxamatch_rb/atomizer.rb, line 18 def parsed_raw return @parsed_raw end
Private Instance Methods
process_infraspecies(node)
click to toggle source
# File lib/taxamatch_rb/atomizer.rb, line 51 def process_infraspecies(node) return unless node @res[:infraspecies] = [] node.each do |infr| next unless infr[:string] hsh = {} hsh[:string] = infr[:string] hsh[:normalized] = Taxamatch::Normalizer.normalize(infr[:string]) hsh[:phonetized] = Taxamatch::Phonetizer.near_match(infr[:string], true) get_authors_years(infr,hsh) @res[:infraspecies] << hsh end end
process_node(name, node, is_species = false)
click to toggle source
# File lib/taxamatch_rb/atomizer.rb, line 41 def process_node(name, node, is_species = false) return unless node && node[:string] @res[name] = {} @res[name][:string] = node[:string] @res[name][:normalized] = Taxamatch::Normalizer.normalize(node[:string]) @res[name][:phonetized] = Taxamatch::Phonetizer.near_match(node[:string], is_species) get_authors_years(node, @res[name]) end