From a28d24470ddeca6196219a1333c1ccac1319efef Mon Sep 17 00:00:00 2001 From: href Date: Wed, 11 Mar 2020 21:18:34 +0100 Subject: welp --- lib/lsg_irc/txt_plugin/markov_native.ex | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/lsg_irc/txt_plugin/markov_native.ex (limited to 'lib/lsg_irc/txt_plugin/markov_native.ex') diff --git a/lib/lsg_irc/txt_plugin/markov_native.ex b/lib/lsg_irc/txt_plugin/markov_native.ex new file mode 100644 index 0000000..524e860 --- /dev/null +++ b/lib/lsg_irc/txt_plugin/markov_native.ex @@ -0,0 +1,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 -- cgit v1.2.3