summaryrefslogtreecommitdiff
path: root/lib/lsg_irc/txt_plugin/markov_native.ex
blob: 524e860f159f292eb55b8feb1d01adff5ab3d8ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
defmodule LSG.IRC.TxtPlugin.MarkovNative do
  @behaviour LSG.IRC.TxtPlugin.Markov

  def start_link() do
    ExChain.MarkovModel.start_link()
  end

  def reload(data, markov) do
    data = data
    |> Enum.map(fn({_, data}) ->
      for {line, _idx} <- data, do: line
    end)
    |> List.flatten

    ExChain.MarkovModel.populate_model(markov, data)
    :ok
  end

  def sentence(markov) do
    case ExChain.SentenceGenerator.create_filtered_sentence(markov) do
      {:ok, line, _, _} -> {:ok, line}
      error -> error
    end
  end

  def complete_sentence(sentence, markov) do
    case ExChain.SentenceGenerator.complete_sentence(markov, sentence) do
      {line, _} -> {:ok, line}
      error -> error
    end
  end

end