summaryrefslogtreecommitdiff
path: root/lib/nola_plugins/txt_plugin/markov_native.ex
diff options
context:
space:
mode:
authorJordan Bracco <href@random.sh>2022-12-20 00:21:54 +0000
committerJordan Bracco <href@random.sh>2022-12-20 19:29:41 +0100
commit2d83df8b32bff7f0028923bb5b64dc0b55f20d03 (patch)
tree1207e67b5b15f540963db05e7be89f3ca950e724 /lib/nola_plugins/txt_plugin/markov_native.ex
parentNola rename, the end. pt 6. Refs T77. (diff)
Nola rename: The Big Move, Refs T77
Diffstat (limited to 'lib/nola_plugins/txt_plugin/markov_native.ex')
-rw-r--r--lib/nola_plugins/txt_plugin/markov_native.ex33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/nola_plugins/txt_plugin/markov_native.ex b/lib/nola_plugins/txt_plugin/markov_native.ex
new file mode 100644
index 0000000..4c403c2
--- /dev/null
+++ b/lib/nola_plugins/txt_plugin/markov_native.ex
@@ -0,0 +1,33 @@
+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