Random sentence from book: Difference between revisions
m
minor cleanup
m (simplify Dictionary creation) |
m (minor cleanup) |
||
Line 320:
function weightedrandompick(dict, total)
n = rand(1:total)
for (key, value) in
n -=
if n <= 0
return key
Line 347:
end
""" Keep account of what words follow words and how many times it is seen. Treat sentence terminators
"""
follows, follows2 = Dict{String, Dict{String, Int}}(), Dict{String, Dict{String, Int}}()
Line 371 ⟶ 370:
afterstopsum = sum(values(afterstop))
""" Assume that a sentence starts with a not to be shown full-stop character then use a weighted
"""
function makesentence()
Line 390 ⟶ 387:
println(join(sentencewords[1:end-1], " ") * sentencewords[end] * "\n")
end
# Print 3 weighted random pick sentences
makesentence(); makesentence(); makesentence()
end
|