Ejemplo n.º 1
0
def main():
    """Execute examples."""
    text = functions.read_json("./common/text.json")

    markov_chain = MarkovChain()
    markov_chain.init(text["text"]["simple"])
    markov_chain.create()

    file.json.save(markov_chain.chain, "./common/simple_example.json")
    file.pickle.save(markov_chain.chain, "./common/simple_example.pickle")
    file.sqlite.save(markov_chain.chain, "./common/simple_example.sqlite")

    markov_chain.chain = file.json.read("./common/simple_example.json")
    markov_chain.chain = file.pickle.read("./common/simple_example.pickle")
    # markov_chain.generate()
    markov_chain_sqlite = file.SQLiteFile(path=".common/simple_example.sqlite")
Ejemplo n.º 2
0
class InitializationTest(object):
    """Test for init() method."""
    @classmethod
    def setUpClass(self):
        with open("./common/_data.json", 'r', encoding="utf-8") as file:
            self._DATA = json.load(file)

        # get a data from the json file.
        self._text = self._DATA[self.text_name]["text"]
        self._correct_data = self._DATA[self.text_name]["data"]

        # create a MarkovChain instance for testing.
        self.chain = MarkovChain()
        self.chain.init(self._text)

    def test_init_method(self):
        self.assertEqual(list(self.chain._data), self._correct_data,
                         "_data is not correct")
Ejemplo n.º 3
0
class CreationTest(object):
    """Test for create() method."""
    @classmethod
    def setUpClass(self):
        with open("./common/_data.json", 'r', encoding="utf-8") as file:
            self._DATA = json.load(file)

        # get a data from the json file.
        self._text = self._DATA[self.text_name]["text"]
        self._correct_chain = self._DATA[self.text_name]["chain"][
            self.chain_window]

        # create a MarkovChain instance for testing.
        self.chain = MarkovChain(window=self.window)
        self.chain.init(self._text)
        self.chain.create()

    def test_create_method(self):
        self.assertEqual(self.chain._chain, self._correct_chain,
                         "_chain is not correct")
Ejemplo n.º 4
0
def generation_arguments(text):
    """Generation arguments example."""
    chain = MarkovChain("Insane test MarkovChain instance")
    chain.init(text)
    chain.create()
    return chain.generate(start="You", max_words=10, max_length=20)
Ejemplo n.º 5
0
def instance_arguments(text):
    """Instance arguments example."""
    chain = MarkovChain("Hard test MarkovChain instance", window=2)
    chain.init(text)
    chain.create()
    print(chain.generate())
Ejemplo n.º 6
0
def basic_usage(text):
    """Basic usage example."""
    chain = MarkovChain("Simple test MarkovChain instance")
    chain.init(text)
    chain.create()
    print(chain.generate())