Class: Ai::Nlp::NGram

Inherits:
Object
  • Object
show all
Defined in:
lib/ai/nlp/n_gram/n_gram.rb

Overview

Class for calculating n-grams, storing and exploiting them

Instance Method Summary collapse

Instance Method Details

#calculate(input) ⇒ Object

Calculates the n-gram frequencies for the data set passed as an argument

Parameters:

  • string

    input The dataset

Returns:

  • Frequencies of ngram or sorted array



23
24
25
26
# File 'lib/ai/nlp/n_gram/n_gram.rb', line 23

def calculate(input)
  hash = Hasher.new(input)
  hash.calculate
end

#hash(input) ⇒ Object

Cuts the data set into a grouping of letters

Parameters:

  • string

    input The dataset



15
16
17
# File 'lib/ai/nlp/n_gram/n_gram.rb', line 15

def hash(input)
  calculate(input).map { |letters, _gram| letters }
end