get_all_texts

get_all_texts #

The get_all_texts method should be used the same way as the get_text_details. It gives you all the texts that could be generated from your input if the synonyms were drawn randomly. Be careful when using it as it could take some time depending on the number of synonyms you use in your app.

from CoreNLG.DocumentConstructors import Datas, TextClass, Document

input = {}

class MyDatas(Datas):
    def __init__(self, json_in):
        super().__init__(json_in)

class MyText(TextClass):
    def __init__(self, section):
        super().__init__(section)

        self.text = (
            "Hello",

            self.nlg_syn(
                ("world", "WORLD_USED"),
                "everyone"
            ),

            ".",

            "I can speak to",

            self.post_eval(
                'WORLD_USED',
                'everyone',
                'the world',
            ),

            "!"
        )

my_datas = MyDatas(input)

document = Document(my_datas)

MyText(document.new_section())

# document.write()
texts = document.get_all_texts()
print(texts)

You’ll get:

[['Hello world. I can speak to everyone !', 'Hello everyone. I can speak to the world !']]