nlg_syn #
Use nlg_syn to create synonyms and add variability to your text. From one render to another, you won’t have the same result.
nlg = NlgTools(lang='en')
text = TextVar(
'I was',
nlg.nlg_syn('hungry', 'starving'),
'so I decided to eat',
nlg.nlg_syn('one apple', 'three apples'),
'.'
)
nlg.write_text(text)
Parameters #
Parameter | Type | Default Value |
---|---|---|
The different options | A list containing the options nlg_syn([option_1, option_2]) or destructured options as several parameters nlg_syn(option_1, option_2) | |
mode (the mode of drawing) | “smart” or “random” | “smart” |
non_reg_id (the id of the synonym for non regression testing) | string (must be unique for non identical synonyms) | None |
An option can be:
- a
String
- a Tuple
(String, String)
or(String, [String])
.
nlg = NlgTools()
option_1 = "synonym_1"
option_2 = ("synonym_2", "KEY_A")
option_3 = ("synonym_3", ["KEY_B", "KEY_C"])
nlg.nlg_syn(option_1, option_2, option_3)
If the chosen synonym is associated with one or multiple keys, these will be activated (see next chapter for usage).
The nlg_syn methods returns a String containing a token where the synonym should appear. This string should be evaluated by the write_text method of the NlgTools object to obtain the result of the draw based on the mode:
- random mode: the synonym will be drawn randomly among the provided options
- smart mode: the drawn synonym will be the one avoiding repetitions considering previous synonyms drawn in smart mode.