Class: NameSpotter
- Defined in:
- lib/name-spotter.rb,
lib/name-spotter/client.rb,
lib/name-spotter/version.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
Constant Summary collapse
- VERSION =
"0.3.4"
Class Method Summary collapse
Instance Method Summary collapse
- #find(input, format = nil) ⇒ Object
-
#initialize(client) ⇒ NameSpotter
constructor
A new instance of NameSpotter.
Constructor Details
#initialize(client) ⇒ NameSpotter
Returns a new instance of NameSpotter.
32 33 34 |
# File 'lib/name-spotter.rb', line 32 def initialize(client) @client = client end |
Class Method Details
.english?(text) ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/name-spotter.rb', line 14 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 do |a| UnsupervisedLanguageDetection.is_english_tweet?(a.join(" ")) end percentage = eng.size.to_f/(not_eng.size + eng.size) percentage > 0.5 end |
Instance Method Details
#find(input, format = nil) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/name-spotter.rb', line 36 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 |