Class: Vendor::Gnfinder::Result

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_client, _project_id = []) ⇒ Result

Returns a new instance of Result.



10
11
12
13
14
# File 'lib/vendor/gnfinder/result.rb', line 10

def initialize(_client, _project_id = [])
  @project_id = _project_id
  @client = _client
  @names = build_names
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



6
7
8
# File 'lib/vendor/gnfinder/result.rb', line 6

def client
  @client
end

#namesObject

Returns the value of attribute names.



8
9
10
# File 'lib/vendor/gnfinder/result.rb', line 8

def names
  @names
end

#new_namesHash

Returns:

  • (Hash)


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

def new_names
  @new_names
end

#project_idObject

Returns the value of attribute project_id.



5
6
7
# File 'lib/vendor/gnfinder/result.rb', line 5

def project_id
  @project_id
end

#unique_namesHash

Returns:

  • (Hash)


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

def unique_names
  @unique_names
end

Instance Method Details

#build_namesObject (private)



138
139
140
141
142
143
144
# File 'lib/vendor/gnfinder/result.rb', line 138

def build_names
  n = client.names.map{|n|
    Vendor::Gnfinder::Name.new(n, project_id)
  }.sort{|a,b| a.found.name <=> b.found.name}
  n ||= []
  @names = n
end

#found_all?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/vendor/gnfinder/result.rb', line 128

def found_all?
  missing_names.empty?
end

#found_namesObject



73
74
75
# File 'lib/vendor/gnfinder/result.rb', line 73

def found_names
  unique_names.select{|k, v| v.first.is_in_taxonworks? }
end

#low_probability_missing_new_namesObject



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

def low_probability_missing_new_names
  n = {}
  missing_names.each do |k,v|
    v.each do |i|
      if i.is_new_name? && i.is_low_probability?
        n[k] = [i]
        break
      end
    end
  end
  n
end

#missing_low_probability_namesObject



124
125
126
# File 'lib/vendor/gnfinder/result.rb', line 124

def missing_low_probability_names
  missing_names.select{|k, v| v.first.is_low_probability? }
end

#missing_namesObject



77
78
79
# File 'lib/vendor/gnfinder/result.rb', line 77

def missing_names
  unique_names.select{|k, v| !v.first.is_in_taxonworks? }
end

#missing_new_namesObject



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/vendor/gnfinder/result.rb', line 81

def missing_new_names
  n = {}
  missing_names.each do |k,v|
    v.each do |i|
      if i.is_new_name? && !i.is_low_probability?
        n[k] = [i]
        break
      end
    end
  end
  n
end

#missing_other_namesObject



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/vendor/gnfinder/result.rb', line 107

def missing_other_names
  a = missing_new_names.keys + low_probability_missing_new_names.keys

  n = {}
  missing_names.each do |k,v|
    v.each do |i|
      if !i.is_low_probability?
        if !a.include?(i.found.name)
          n[k] = [i]
          break
        end
      end
    end
  end
  n
end

#ocr_failureObject



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

def ocr_failure
  client.names.length == 0
end

#probable_source_of_textObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/vendor/gnfinder/result.rb', line 22

def probable_source_of_text
  case score
  when 3..23
    if client.language == 'eng'
      'original text'
    else
      'uncertain (language)'
    end
  else
    if client.language == 'eng'
      'secondary OCR'
    else
      'uncertain (language)'
    end
  end
end

#scoreObject



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

def score
  t = unique_names.keys.count.to_f
  sum_odds = unique_names.values.inject(0){|sum, names| sum += names.first.log_odds}
  sum_odds / t
end

#verified_namesObject



132
133
134
# File 'lib/vendor/gnfinder/result.rb', line 132

def verified_names
  unique_names.select{|k, v| v.first.is_verified? }
end