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)



94
95
96
97
98
99
100
# File 'lib/vendor/gnfinder/result.rb', line 94

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)


84
85
86
# File 'lib/vendor/gnfinder/result.rb', line 84

def found_all?
  missing_names.empty?
end

#found_namesObject



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

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

#missing_low_probability_namesObject



80
81
82
# File 'lib/vendor/gnfinder/result.rb', line 80

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

#missing_namesObject



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

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

#missing_new_namesObject



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

def missing_new_names
  missing_names.select{|k, v| v.first.is_new_name? && !v.first.is_low_probability? }
end

#missing_other_namesObject



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

def missing_other_names
  missing_names.select{|k, v| !v.first.is_new_name? && !v.first.is_low_probability? }
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



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

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