From 37dec1dd0bf21644525d9c23bc9babce5d85e2af Mon Sep 17 00:00:00 2001 From: ChUrl Date: Tue, 8 Nov 2022 20:45:34 +0100 Subject: [PATCH] add textgen interface --- textgen.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 textgen.py diff --git a/textgen.py b/textgen.py new file mode 100644 index 0000000..d6b4e68 --- /dev/null +++ b/textgen.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +from rich.traceback import install +install() + +from abc import ABC, abstractmethod + +# In Python it is generally not needed to use abstract classes, but I wanted to do it safely + +class textgen(ABC): + @abstractmethod + def init(self, filename): + """ + filename - The file (same directory as textgen.py) that contains the training text + """ + raise NotImplementedError("Can't use abstract class") + + @abstractmethod + def load(self): + """ + Load the trained markov chain from a precomputed file + """ + raise NotImplementedError("Can't use abstract class") + + @abstractmethod + def train(self): + """ + Generate the markov chain, uses prefix length defined in init() + """ + raise NotImplementedError("Can't use abstract class") + + @abstractmethod + def generate_sentence(self): + """ + Generate a series of words/characters until a . is generated + """ + raise NotImplementedError("Can't use abstract class") + + @abstractmethod + def complete_sentence(self, prefix): + """ + Generate the rest of a sentence for a given beginning + """ + raise NotImplementedError("Can't use abstract class")