Created
April 30, 2014 11:14
-
-
Save miwarin/c940a5bfbb2c83502b0f to your computer and use it in GitHub Desktop.
N-gram
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby -Ku | |
require 'pp' | |
def ngram(gram = 2, text) | |
len = text.length - 1 | |
0.upto(len) {|i| | |
if i + gram > text.length | |
return | |
end | |
puts text[i, gram] | |
} | |
end | |
def main(argv) | |
gram = 2 | |
text = "hoge" | |
ngram(gram, text) | |
gram = 3 | |
text = "日本語です" | |
ngram(gram, text) | |
end | |
main(ARGV) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment