Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@merl-dev merl-dev commented May 28, 2016

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