Skip to content

Instantly share code, notes, and snippets.

@merl-dev
Created May 28, 2016 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merl-dev/cbb2aa948821f2386b6188b0b7784ea4 to your computer and use it in GitHub Desktop.
Save merl-dev/cbb2aa948821f2386b6188b0b7784ea4 to your computer and use it in GitHub Desktop.
simple word counter
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
@merl-dev
Copy link
Author

This was written in response to article and code from http://preshing.com/files/wordcount.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment