summaryrefslogblamecommitdiff
path: root/lib/lsg_irc/txt_plugin/markov_native.ex
blob: 524e860f159f292eb55b8feb1d01adff5ab3d8ee (plain) (tree)
































                                                                         
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