Class: NameSpotter
- Inherits:
-
Object
show all
- 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
Constructor Details
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)
= 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 = .shuffle[0...50].partition do |a|
UnsupervisedLanguageDetection.(a.join(" "))
end
percentage = eng.size.to_f/(not_eng.size + eng.size)
percentage > 0.5
end
|
4
5
6
|
# File 'lib/name-spotter/version.rb', line 4
def self.version
VERSION
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
|