Class: NameSpotter::NetiNetiClient
- Defined in:
- lib/name-spotter/neti_neti_client.rb
Instance Attribute Summary
Attributes inherited from Client
Instance Method Summary collapse
- #find(text) ⇒ Object
-
#initialize(opts = { host: '0.0.0.0', port: 6384 }) ⇒ NetiNetiClient
constructor
A new instance of NetiNetiClient.
Methods inherited from Client
Constructor Details
#initialize(opts = { host: '0.0.0.0', port: 6384 }) ⇒ NetiNetiClient
Returns a new instance of NetiNetiClient.
3 4 5 |
# File 'lib/name-spotter/neti_neti_client.rb', line 3 def initialize(opts = { host: '0.0.0.0', port: 6384 }) super end |
Instance Method Details
#find(text) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/name-spotter/neti_neti_client.rb', line 7 def find(text) # the form does not get sent if text is nil or empty return [] if text.nil? || text.empty? resource = RestClient::Resource.new("http://#{@host}:#{@port}", timeout: 9_000_000, open_timeout: 9_000_000, connection: "Keep-Alive") #TODO: we should figure out a better delimiter in NetiNeti (or use json) so we don't need to susbitute pipe with a letter here response = resource.post(data: text.gsub("|", "l")) #hhhhhhack response.body.split("|").collect do |info| res = info.split(",") name = res[0...-2].join(",") offset_start = res[-2] name.force_encoding('utf-8') normalized_name = NameSpotter::ScientificName.normalize(name) NameSpotter::ScientificName.new(name, :scientific_name => normalized_name, :start_position => offset_start.to_i) end end |