refactor73 / autotextgen
A simple document driven text generation written in PHP
0.0.1
2020-09-22 08:20 UTC
Requires
- php: ^7.4
Requires (Dev)
- phpunit/phpunit: ^9.3
- squizlabs/php_codesniffer: ^3.5
This package is auto-updated.
Last update: 2025-08-25 23:50:20 UTC
README
A simple document driven text composer.
Description
Writing natural language text blocks based on context and decisions parsed from a JSON document. The context contains the properties of the JSON document itself and can be added to the text as ${variables}, while the decision table contains bool values based on pre executed custom conditions and are used in [IF $decision] control structures.
Example
$context = Context::fromArray([ 'trend' => 10, 'total' => 90, ]); $decisionTable = DecisionTable::fromArray([ 'isNegative' => false, ]); $textComposer = new TextComposer($decisionTable, $context); $result = $textComposer->compose( '{In dieser Woche|Aktuell} ist der Wert um ${trend} auf ${total} Punkte ' . '[IF $isNegative] gefallen [ELSE] gestiegen [ENDIF].' );
Possible result are:
In dieser Woche ist der Wert um 10 auf 90 Punkte gestiegen.
or
Aktuell ist der Wert um 10 auf 90 Punkte gestiegen.
Manipulators
Syntax | Description |
---|---|
{synonym1|synonym2|synonym3} | Random choose a synonym out of list |
${var} | Variable name from context |
[IF $decision] ... [ENDIF] | if control structure |
[IF $decision] ... [ELSE] ... [ENDIF] | if else control structure |
Use case
Generating varied text for a customer metric report based on a JSON document.