summaryrefslogblamecommitdiff
path: root/lib/nola_plugins/txt_plugin/markov_native.ex
blob: 4c403c23722834b68efc1f33812d0b3d92d119cb (plain) (tree)
1
2

                                            






























                                                                         
defmodule Nola.IRC.TxtPlugin.MarkovNative do
  @behaviour Nola.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