get_text_details

get_text_details #

The get_text_details method is the recommended way for non-regression testing.

You should call get_text_details from your NlgTools object instead of the write_text method (or from your Document object instead of the write method).

This method returns a python dict containing all the data on the possible generated texts from your input.

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()
details = document.get_text_details()
print(details)

This will give you the following output:

[
  {
    "text": {
      "raw": "Hello b7e736edc59bb0c73afed33daa185fa2e8d5e8b34127c0562543e05e017aa644 . I can speak to 45b8643250f5b9e1756f079f9d93c89dee74abea83d275a4be59e03da4ce8ed2 !",
      "beautiful": "Hello b7e736edc59bb0c73afed33daa185fa2e8d5e8b34127c0562543e05e017aa644. I can speak to 45b8643250f5b9e1756f079f9d93c89dee74abea83d275a4be59e03da4ce8ed2 !"
    },
    "synonyms": [
      {
        "id": "b7e736edc59bb0c73afed33daa185fa2e8d5e8b34127c0562543e05e017aa644",
        "choices": [
          { "raw": "world", "beautiful": "World", "keys": ["WORLD_USED"] },
          { "raw": "everyone", "beautiful": "Everyone", "keys": [] }
        ]
      }
    ],
    "post_evals": [
      {
        "id": "45b8643250f5b9e1756f079f9d93c89dee74abea83d275a4be59e03da4ce8ed2",
        "infos": {
          "key": "WORLD_USED",
          "if_active": { "raw": "everyone", "beautiful": "Everyone" },
          "if_inactive": { "raw": "the world", "beautiful": "The world" },
          "deactivate": False
        }
      }
    ]
  }
]

You obtain all the data you need for non regression testing such as the text (raw and beautified) and the different branches (synonyms and post evals).

The id is the hash of the object data. If you want to make sure the hash won’t change you can specify an id when using the nlg_syn method:

self.nlg_syn(
    ("world", "WORLD_USED"),
    "everyone",
    non_reg_id="synonym_world_or_everyone"
)


self.post_eval(
    'WORLD_USED',
    'everyone',
    'the world',
    non_reg_id="post_eval_everyone_or_the_world"
)

You’ll get:

[
  {
    "text": {
      "raw": "Hello synonym_world_or_everyone . I can speak to post_eval_everyone_or_the_world !",
      "beautiful": "Hello synonym_world_or_everyone. I can speak to post_eval_everyone_or_the_world !"
    },
    "synonyms": [
      {
        "id": "synonym_world_or_everyone",
        "choices": [
          { "raw": "world", "beautiful": "World", "keys": ["WORLD_USED"] },
          { "raw": "everyone", "beautiful": "Everyone", "keys": [] }
        ]
      }
    ],
    "post_evals": [
      {
        "id": "post_eval_everyone_or_the_world",
        "infos": {
          "key": "WORLD_USED",
          "if_active": { "raw": "everyone", "beautiful": "Everyone" },
          "if_inactive": { "raw": "the world", "beautiful": "The world" },
          "deactivate": False
        }
      }
    ]
  }
]

You can now save a json file for each of your inputs and track any changes on any branches of your text.