refactor73/autotextgen
Composer 安装命令:
composer require refactor73/autotextgen
包简介
A simple document driven text generation written in PHP
README 文档
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.
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-09-21