Class: Tagelizer
- Inherits:
-
Object
- Object
- Tagelizer
- Defined in:
- lib/tagelizer.rb
Instance Attribute Summary collapse
-
#dictionary ⇒ Object
Returns the value of attribute dictionary.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #actual_options ⇒ Object
- #build_speller ⇒ Object
- #build_stemmer ⇒ Object
- #corrected_word(word) ⇒ Object
- #dictionaries ⇒ Object
-
#initialize(locale = 'en') ⇒ Tagelizer
constructor
A new instance of Tagelizer.
- #parse(text) ⇒ Object
- #speller ⇒ Object
- #stemmer ⇒ Object
Constructor Details
#initialize(locale = 'en') ⇒ Tagelizer
Returns a new instance of Tagelizer.
8 9 10 11 12 |
# File 'lib/tagelizer.rb', line 8 def initialize(locale = 'en') @dictionary= (dictionaries.include?(locale) ? locale : "en") @minwordsize = 2 @options = {'ignore-case' => true} end |
Instance Attribute Details
#dictionary ⇒ Object
Returns the value of attribute dictionary.
40 41 42 |
# File 'lib/tagelizer.rb', line 40 def dictionary @dictionary end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
7 8 9 |
# File 'lib/tagelizer.rb', line 7 def locale @locale end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/tagelizer.rb', line 7 def @options end |
Instance Method Details
#actual_options ⇒ Object
57 58 59 60 61 62 |
# File 'lib/tagelizer.rb', line 57 def .keys.inject({}) do |hash, key| hash[key] = [key].to_s hash end end |
#build_speller ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/tagelizer.rb', line 22 def build_speller speller = Aspell.new(dictionary) speller.suggestion_mode = 'normal' .each do |key, value| speller.set_option key, value end speller end |
#build_stemmer ⇒ Object
36 37 38 |
# File 'lib/tagelizer.rb', line 36 def build_stemmer Lingua::Stemmer.new(:language => dictionary) end |
#corrected_word(word) ⇒ Object
53 54 55 |
# File 'lib/tagelizer.rb', line 53 def corrected_word(word) speller.check(word) ? word : speller.suggest(word).first end |
#dictionaries ⇒ Object
49 50 51 |
# File 'lib/tagelizer.rb', line 49 def dictionaries @dictionaries ||= Aspell.list_dicts.collect { |dict| dict.code } end |
#parse(text) ⇒ Object
14 15 16 |
# File 'lib/tagelizer.rb', line 14 def parse( text ) text.split(" ").collect {|i| /(\w*)/.match(i)[1]}.select {|i| i.size > @minwordsize}.collect {|w| stemmer.stem corrected_word(w)} end |
#speller ⇒ Object
18 19 20 |
# File 'lib/tagelizer.rb', line 18 def speller @speller ||= build_speller end |
#stemmer ⇒ Object
32 33 34 |
# File 'lib/tagelizer.rb', line 32 def stemmer @stemmer ||= build_stemmer end |