Class: NameSpotter

Inherits:
Object show all
Defined in:
lib/name-spotter.rb,
lib/name-spotter/client.rb,
lib/name-spotter/scientific_name.rb,
lib/name-spotter/neti_neti_client.rb,
lib/name-spotter/taxon_finder_client.rb

Defined Under Namespace

Classes: Client, NetiNetiClient, ScientificName, TaxonFinderClient

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ NameSpotter

Returns a new instance of NameSpotter.



31
32
33
# File 'lib/name-spotter.rb', line 31

def initialize(client)
  @client = client
end

Class Method Details

.english?(text) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/name-spotter.rb', line 15

def self.english?(text)
  tweets = text.split(/\s+/).inject([]) do |res, w|
    if w.match(/[A-Za-z]/)
      if res.empty? || res[-1].size >=15
        res << [w]
      else
        res[-1] << w
      end
    end
    res
  end
  eng, not_eng = tweets.shuffle[0...50].partition {|a| UnsupervisedLanguageDetection.is_english_tweet?(a.join(" "))}
  percentage = eng.size.to_f/(not_eng.size + eng.size) 
  percentage > 0.5
end

Instance Method Details

#find(input, format = nil) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/name-spotter.rb', line 35

def find(input, format = nil)
  text = to_text(input)
  names = @client.find(text)
  names = names.map{ |n| n.to_hash }
  return { names: names } unless format
  format == "json" ? to_json(names) : to_xml(names)
end