Created
June 26, 2017 22:41
-
-
Save jadeallenx/186896d4ad837da989915430ca282b30 to your computer and use it in GitHub Desktop.
ngram builder for Erlang
This file contains hidden or 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
-module(ngram). | |
-compile([export_all]). | |
ngram(N, Str) -> | |
make_ngram(N, Str, 1, orddict:new()). | |
make_ngram(_N, Str, Pos, Acc) when Pos >= length(Str) -> Acc; | |
make_ngram(N, Str, Pos, Acc) -> | |
make_ngram(N, Str, Pos+1, orddict:update_counter(lists:sublist(Str, Pos, N), 1, Acc)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment