SDQM4ROF7EPX5G7Z4V37ZNWKWNC7ZHZQQ4ZVKLDZTLJSERCSC4CQC
defp collect_sentences(stream) do
stream |> Stream.transform(
[],
fn
{:line, line}, acc ->
splitted = line
|> String.split(".")
case splitted do
[p] -> {[], [p|acc]}
_ ->
last = List.last(splitted)
first_sentence = [List.first(splitted) | acc]
|> Enum.reverse
|> Enum.join(" ")
other_sentences = splitted
|> Enum.drop(1)
|> Enum.drop(-1)
|> Enum.map(fn s -> {:sentence, s} end)
new_acc = if last == "" do
[]
else
[last]
end
{[{:sentence, first_sentence}] ++ other_sentences, new_acc}
end
a, acc -> {[a], acc}
end
)
end