Class: FamilyReunion::TaxamatchWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/family-reunion/taxamatch_wrapper.rb

Instance Method Summary collapse

Constructor Details

#initializeTaxamatchWrapper

Returns a new instance of TaxamatchWrapper.



4
5
6
7
8
# File 'lib/family-reunion/taxamatch_wrapper.rb', line 4

def initialize
  @tm = Taxamatch::Base.new
  @cache = FamilyReunion::Cache.new
  @tp = FamilyReunion::TaxamatchPreprocessor.new(@cache)
end

Instance Method Details

#binomials_match?(name1, name2) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/family-reunion/taxamatch_wrapper.rb', line 45

def binomials_match?(name1, name2)
  uninomials_match?(name1, name2)
end

#match_canonicals_lists(list1, list2) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/family-reunion/taxamatch_wrapper.rb', line 10

def match_canonicals_lists(list1, list2)
  matches = {}
  match_candidates = @tp.get_match_candidates(list1, list2)
  [:uninomials, :binomials, :trinomials].each do |bucket|
    match_candidates[bucket].each do |name1, possible_matches|
      possible_matches[:candidates].each do |name2|
        if self.send("#{bucket}_match?", name1, name2[0])
          matches.has_key?(name1) ? matches[name1] << name2[0] : matches[name1] = [name2[0]]
        end
      end
    end
  end
  matches 
end

#match_nodes(nodes) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/family-reunion/taxamatch_wrapper.rb', line 25

def match_nodes(nodes)
  res = []
  nodes.each do |primary_node, secondary_nodes|
    secondary_nodes.each do |secondary_node|
      if @tm.taxamatch(primary_node[:name_to_match], secondary_node[:name_to_match])
        if res.last && res.last[0][:id] == primary_node[:id]
          res.last[1] << secondary_node
        else
          res << [primary_node, [secondary_node]]
        end
      end
    end
  end
  res
end

#trinomials_match?(name1, name2) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/family-reunion/taxamatch_wrapper.rb', line 49

def trinomials_match?(name1, name2)
  uninomials_match?(name1, name2)
end

#uninomials_match?(name1, name2) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/family-reunion/taxamatch_wrapper.rb', line 41

def uninomials_match?(name1, name2)
  @tm.taxamatch(name1, name2)      
end