Class: NameSpotter::TaxonFinderClient
- Defined in:
- lib/name-spotter/taxon_finder_client.rb
Instance Attribute Summary
Attributes inherited from Client
Instance Method Summary collapse
- #find(str, from_web_form = false) ⇒ Object
-
#initialize(opts = { host: "0.0.0.0", port: "1234" }) ⇒ TaxonFinderClient
constructor
A new instance of TaxonFinderClient.
Methods inherited from Client
Constructor Details
#initialize(opts = { host: "0.0.0.0", port: "1234" }) ⇒ TaxonFinderClient
Returns a new instance of TaxonFinderClient.
4 5 6 |
# File 'lib/name-spotter/taxon_finder_client.rb', line 4 def initialize(opts = { host: "0.0.0.0", port: "1234" }) super end |
Instance Method Details
#find(str, from_web_form = false) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/name-spotter/taxon_finder_client.rb', line 8 def find(str, from_web_form=false) @names = [] return [] if str.nil? || str.empty? str << " ." # hack to find last name @document_verbatim = str # These are for the data-send-back that happens in TaxonFinder @current_string = "" @current_string_state = "" @word_list_matches = 0 @cursor = 8.times.inject([]) { |res| res << ["",0, 0] } @current_index = nil words = str.split(/\s/) words.each do |word| if word.empty? @cursor[-1][2] = @cursor[-1][2] + 1 else abbr_no_space = word.match(/^([A-Z][a-z]?\.)([a-z|\p{Latin}]+)/) if abbr_no_space process_word(abbr_no_space[1], 0) process_word(word[abbr_no_space[1].size..-1], 1) else process_word(word, 1) end end end socket.close @socket = nil @names end |