class ExamplesGroup
Public Class Methods
new(args)
click to toggle source
# File lib/NaiveText/ExamplesGroup.rb, line 2 def initialize(args) @examples = args[:examples].to_a || [] @language_model = args[:language_model] || ->(str) { str } load_text split_text_into_words format_words fail 'Empty_Trainingsdata' if @words.length == 0 end
Public Instance Methods
count(word)
click to toggle source
# File lib/NaiveText/ExamplesGroup.rb, line 11 def count(word) @words.count(@language_model.call(word.downcase)) end
word_count()
click to toggle source
# File lib/NaiveText/ExamplesGroup.rb, line 15 def word_count @words.count end
Private Instance Methods
format_words()
click to toggle source
# File lib/NaiveText/ExamplesGroup.rb, line 32 def format_words @words.map!(&:downcase) @words.map! { |word| @language_model.call(word) } @words end
load_text()
click to toggle source
# File lib/NaiveText/ExamplesGroup.rb, line 21 def load_text @text = '' @examples.each do |example| @text += ' ' + example.text end end
split_text_into_words()
click to toggle source
# File lib/NaiveText/ExamplesGroup.rb, line 28 def split_text_into_words @words = @text.split(/\W+/) end