Class: Sastrawi::Stemmer::CachedStemmer
- Inherits:
-
Object
- Object
- Sastrawi::Stemmer::CachedStemmer
- Defined in:
- lib/sastrawi/stemmer/cached_stemmer.rb
Instance Attribute Summary collapse
-
#cache ⇒ Object
readonly
Returns the value of attribute cache.
-
#delegated_stemmer ⇒ Object
readonly
Returns the value of attribute delegated_stemmer.
Instance Method Summary collapse
-
#initialize(cache, delegated_stemmer) ⇒ CachedStemmer
constructor
A new instance of CachedStemmer.
- #stem(text) ⇒ Object
Constructor Details
#initialize(cache, delegated_stemmer) ⇒ CachedStemmer
Returns a new instance of CachedStemmer.
8 9 10 11 |
# File 'lib/sastrawi/stemmer/cached_stemmer.rb', line 8 def initialize(cache, delegated_stemmer) @cache = cache @delegated_stemmer = delegated_stemmer end |
Instance Attribute Details
#cache ⇒ Object (readonly)
Returns the value of attribute cache.
6 7 8 |
# File 'lib/sastrawi/stemmer/cached_stemmer.rb', line 6 def cache @cache end |
#delegated_stemmer ⇒ Object (readonly)
Returns the value of attribute delegated_stemmer.
6 7 8 |
# File 'lib/sastrawi/stemmer/cached_stemmer.rb', line 6 def delegated_stemmer @delegated_stemmer end |
Instance Method Details
#stem(text) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/sastrawi/stemmer/cached_stemmer.rb', line 13 def stem(text) normalized_text = Sastrawi::Stemmer::Filter::TextNormalizer.normalize_text(text) words = normalized_text.split(' ') stems = [] words.each do |word| if @cache.has?(word) stems.push(@cache.get(word)) else stem = @delegated_stemmer.stem(word) @cache.set(word, stem) stems.push(stem) end end stems.join(' ') end |