Nlp 自然语言文本转换的模板语言

Nlp 自然语言文本转换的模板语言,nlp,semantics,Nlp,Semantics,被困在一个似乎会导致更大问题的相当琐碎的任务上 需要能够生成相同短文本的光变化。有些词形取决于说话人的性别,有些可以用同义词代替 伪代码: I {random:decided|made up my mind} to {random:try|test|give a try to} this {new|fresh} {cool|awesome} {service|web service|online tool}. 我正在寻找一种“行业标准”的模板语言来描述这样的文本和可能的变化。进一步考虑,我可能

被困在一个似乎会导致更大问题的相当琐碎的任务上

需要能够生成相同短文本的光变化。有些词形取决于说话人的性别,有些可以用同义词代替

伪代码:

I {random:decided|made up my mind} to {random:try|test|give a try to}
this {new|fresh} {cool|awesome} {service|web service|online tool}.
我正在寻找一种“行业标准”的模板语言来描述这样的文本和可能的变化。进一步考虑,我可能需要全局变量(比如性别变量),在句子前面选择的依赖项的交叉链接

这看起来很接近正则表达式语法。理想情况下,非程序员更容易读/写


也许这个问题是众所周知的,使用固态解决方案,比如专门用于任务的某种编程语言?

假设您不允许在文本中使用括号或分隔符(或以某种方式逃避它们),您可以在不太头疼的情况下完成此任务,例如在JavaScript中:

function randreplace (txt) {
    var matches = txt.match(/\{([^}]+)\}/g);
    for (var m in matches) {
        m = matches[m];
        var opts = m.substring(1, m.length-1); // rm '{' and '}'
        opts = opts.split('|');
        var rand = opts[Math.floor(Math.random() * opts.length)];
        txt = txt.replace(m, rand);
    }
    return txt;
}
var example = "I {decided|made up my mind} to {try|test|give a try to} this {new|fresh} {cool|awesome} {service|web service|online tool}.";

console.log(randreplace(example));

我找不到像这样的东西,所以我开始创造它。结果被调用。语法相当简单,但也足够强大,可以支持递归短语、同义词、捕获的值和依赖项

%
    $person.name went to the $place to %action

%action
    ~buy a new $item
    ~sell @posessive($person.gender) $item

~buy
    buy
    purchase

$place
    store
    market

...
它将生成的句子与树表示一起输出(主要目的是为ML系统生成训练数据)

如果一年后您仍在寻找,请访问并打开一个问题,让我知道您在梦想NLG语言中寻求什么

> jill went to the store to return her toothbrush

( %
    ( $person.name
        jill )
    ( $place
        store )
    ( %action
        ( $item
            toothbrush ) ) )