Class: Ai::Nlp::Hasher
- Inherits:
-
Object
- Object
- Ai::Nlp::Hasher
- Defined in:
- lib/ai/nlp/n_gram/hasher.rb
Overview
Class managing an n-gram hash
Instance Method Summary collapse
-
#calculate ⇒ Object
Calculates n-gram frequencies for the dataset.
-
#initialize(input) ⇒ Hasher
constructor
Initialisation.
Constructor Details
#initialize(input) ⇒ Hasher
Initialisation
18 19 20 21 22 |
# File 'lib/ai/nlp/n_gram/hasher.rb', line 18 def initialize(input) @input = input @hash = {} clean end |
Instance Method Details
#calculate ⇒ Object
Calculates n-gram frequencies for the dataset
27 28 29 30 31 32 33 |
# File 'lib/ai/nlp/n_gram/hasher.rb', line 27 def calculate @input.split(/[\d\s\[\]]/).each do |word| calculate_word_gram("_#{word}_") end drop_unwanted_keys @hash.sort { |one, other| other[1] <=> one[1] } end |