Class: Classyfier::Classifiers::English
- Inherits:
-
Object
- Object
- Classyfier::Classifiers::English
- Defined in:
- lib/classyfier/english.rb
Instance Attribute Summary collapse
-
#english_dict ⇒ Object
Returns the value of attribute english_dict.
Instance Method Summary collapse
- #classify(text, opts = {:word_count => 1}) ⇒ Object
-
#initialize(opts = {:dictionary_size => 50000}) ⇒ English
constructor
A new instance of English.
Constructor Details
#initialize(opts = {:dictionary_size => 50000}) ⇒ English
Returns a new instance of English.
6 7 8 9 |
# File 'lib/classyfier/english.rb', line 6 def initialize(opts = {:dictionary_size => 50000}) @dictionary_size = opts[:dictionary_size] @english_dict = load_dictionary() end |
Instance Attribute Details
#english_dict ⇒ Object
Returns the value of attribute english_dict.
4 5 6 |
# File 'lib/classyfier/english.rb', line 4 def english_dict @english_dict end |
Instance Method Details
#classify(text, opts = {:word_count => 1}) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/classyfier/english.rb', line 11 def classify(text, opts = {:word_count => 1}) words = text.split(" ") count = 0 for word in words count += 1 if @english_dict[clean_word(word)] break if count >= opts[:word_count] end return count >= opts[:word_count] end |