Created
May 28, 2016 00:28
-
-
Save merl-dev/cbb2aa948821f2386b6188b0b7784ea4 to your computer and use it in GitHub Desktop.
simple word counter
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
module WordCounters | |
export createWordList, wordCount | |
function createWordList(dictfile, nsamples) | |
dictwords = readdlm(dictfile,'\n',AbstractString) | |
ln = length(dictwords) | |
# vector of random indices | |
rindices = rand(1:ln, nsamples) | |
# vector of random words | |
dictwords[rindices] | |
end | |
function wordCount(words) | |
counts = Dict{AbstractString,Int64}() | |
for i = 1:length(words) | |
w = words[i] | |
counts[w] = get(counts, w, 0) + 1 | |
end | |
counts | |
end | |
end | |
function main(filename, n) | |
wl = createWordList(filename, n) | |
wc = wordCount(wl) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was written in response to article and code from http://preshing.com/files/wordcount.zip