Class: CoCoGe::WordsSymbolGenerator
- Inherits:
-
Object
- Object
- CoCoGe::WordsSymbolGenerator
- Defined in:
- lib/co_co_ge/words_symbol_generator.rb
Instance Method Summary collapse
- #compute ⇒ Object
-
#initialize(corpus:, filter: -> word { true }, post_process: -> word { word.upcase }) ⇒ WordsSymbolGenerator
constructor
A new instance of WordsSymbolGenerator.
Constructor Details
#initialize(corpus:, filter: -> word { true }, post_process: -> word { word.upcase }) ⇒ WordsSymbolGenerator
Returns a new instance of WordsSymbolGenerator.
2 3 4 5 6 |
# File 'lib/co_co_ge/words_symbol_generator.rb', line 2 def initialize(corpus:, filter: -> word { true }, post_process: -> word { word.upcase }) @corpus = corpus @filter = filter @post_process = post_process end |
Instance Method Details
#compute ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/co_co_ge/words_symbol_generator.rb', line 8 def compute words = @corpus.split(/\s+/).map(&@post_process).select(&@filter) count = Hash.new(0) words.each do |word| count[word] += 1 end count.sort_by { |c| -c.last }.first(255).map(&:first) end |