Class: Rlid::NGramModel
Overview
in subclasses generate_model filename, load and save should be implemented
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(string = nil, n = 3, cutoff = 300) ⇒ NGramModel
constructor
A new instance of NGramModel.
Constructor Details
#initialize(string = nil, n = 3, cutoff = 300) ⇒ NGramModel
Returns a new instance of NGramModel.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rlid/models/model.rb', line 16 def initialize(string=nil, n=3, cutoff=300) @n = n @cutoff = cutoff if string == nil then return end # ngrams and count of each ngram_count = Hash.new(0) string.each_ngram(@n) do |ngram| ngram_count[ngram] += 1 end generate_model(ngram_count) end |
Class Method Details
.language_models ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rlid/models/model.rb', line 33 def self.language_models if not defined?(filename) raise "#{self.class} should implement 'filename' accessor!" end res = Hash.new Language.each_file(filename) do |file, lang| model = self.new(nil) model.load(file) res[lang] = model end res end |