Sha256: 1e60cf44a042ac14755ef310976a7c33822377931ca8e16c465babaa1e06b8f0
Contents?: true
Size: 764 Bytes
Versions: 5
Compression:
Stored size: 764 Bytes
Contents
require 'sastrawi/stemmer/filter/text_normalizer' module Sastrawi module Stemmer class CachedStemmer attr_reader :cache, :delegated_stemmer def initialize(cache, delegated_stemmer) @cache = cache @delegated_stemmer = delegated_stemmer end 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 end end end
Version data entries
5 entries across 5 versions & 1 rubygems