Random sentence from book: Difference between revisions
m
simplify Dictionary creation
(Added Algol 68) |
m (simplify Dictionary creation) |
||
Line 348:
""" Keep account of what words follow words and how many times it is seen.
(Treat sentence terminators as words too). Keep account of what words follow two words
and how many times it is seen, (again treating sentence terminators as words too).
"""
Line 354:
afterstop, wlen = Dict{String, Int}(), length(words)
for (i, w) in enumerate(@view words[1:end-1])
get!(d,
if w in
d = get!(afterstop,
end
(i > wlen - 2) && continue
w2 = w * " " * words[i + 1]
get!(d,
end
followsums = Dict(key => sum(values(follows[key])) for key in keys(follows))
Line 403 ⟶ 388:
end
sentencewords[1] = uppercase(firstword[1]) * (length(firstword) > 1 ? firstword[2:end] : "")
println
end
Line 422 ⟶ 407:
(RUN:)
It was this cylinder.
|