summaryrefslogtreecommitdiff
path: root/lib/lsg_irc/txt_plugin/markov_native.ex
diff options
context:
space:
mode:
authorhref <href@random.sh>2020-03-11 21:18:34 +0100
committerhref <href@random.sh>2020-03-11 21:18:34 +0100
commita28d24470ddeca6196219a1333c1ccac1319efef (patch)
tree4f29e3c8fb6afbb1f99d6b8737f844c95fca54df /lib/lsg_irc/txt_plugin/markov_native.ex
parentup to 420*100 (diff)
welp
Diffstat (limited to 'lib/lsg_irc/txt_plugin/markov_native.ex')
-rw-r--r--lib/lsg_irc/txt_plugin/markov_native.ex33
1 files changed, 33 insertions, 0 deletions
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