# File lib/language_detector.rb, line 207 def count_ngram(token, n, counts) token = "_#{token}#{'_' * (n-1)}" if n > 1 && token.length >= n n.upto(token.length).with_index do |t, i| s = '' 0.upto(n-1) { |j| s << token[i+j] } counts[s] = counts.has_key?(s) ? counts[s]+=1 : 1 end counts end