nlp - SimpleNLG - 使用 "placeholders"创建一个由 2 部分组成的句子

标签 nlp text-analysis

有谁知道如何(使用 SimpleNLG)创建一个正确的“两部分”句子,如下所示(我不是语言学家,所以我不太确定每个单词/短语的语法类别:

"I bought a new widget engine, which created product A, product B, and product C."

粗体文本将在运行时由语法解析器或其他东西动态插入。我浏览了 SimpleNLG 教程(似乎没有其他更深入的内容),然后尝试将 PPPhraseSpec 对象(代表上面句子的第二部分)附加到 SPhraseSpec(它有一个名词短语和动词短语) ),但结果难以理解并且语法错误。

最佳答案

以下是您的问题的解决方案:粗体的第一部分是语法对象(名词短语),粗体的第二部分是动词“create”(并列从句)的对象。

import simplenlg.realiser.english.Realiser;
import simplenlg.lexicon.Lexicon;
import simplenlg.phrasespec.*;
import simplenlg.framework.*;
import simplenlg.features.*;


public class Test {

    // Target:
    // I bought a new widget engine, 
    //   which created product A, product B, and product C.

    public static void main(String[] args) {
        System.out.println("Starting...");
        Lexicon lexicon = Lexicon.getDefaultLexicon();
        NLGFactory nlgFactory = new NLGFactory(lexicon);
        Realiser realiser = new Realiser(lexicon);

        SPhraseSpec s1 = nlgFactory.createClause("I",
            "bought", "a new widget engine");
        s1.setFeature(Feature.TENSE, Tense.PAST);

        SPhraseSpec s2 = nlgFactory.createClause("", "created");
        NPPhraseSpec object1 = nlgFactory.createNounPhrase("product A");
        NPPhraseSpec object2 = nlgFactory.createNounPhrase("product B");
        NPPhraseSpec object3 = nlgFactory.createNounPhrase("product C");

        CoordinatedPhraseElement cc = nlgFactory.createCoordinatedPhrase();
        cc.addCoordinate(object1);
        cc.addCoordinate(object2);
        cc.addCoordinate(object3);

        s2.setObject(cc);
        s2.setFeature(Feature.TENSE, Tense.PAST);

        s2.setFeature(Feature.COMPLEMENTISER, ", which"); // non-restrictive?
        s1.addComplement(s2);

        String output = realiser.realiseSentence(s1);
        System.out.println(output);
    }

}

我不是以英语为母语的人,并且经常弄错这部分,但我认为您需要一个限制性关系子句而不是非限制性关系子句:“我购买了一个新的小部件引擎,它创建了...”而不是“我购买了一个新的小部件引擎,它创建了......”如果是这种情况,只需注释设置补充器的行即可。

关于nlp - SimpleNLG - 使用 "placeholders"创建一个由 2 部分组成的句子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25372720/

相关文章:

python - NLTK包,未定义标签

text-processing - 将相似的单词分组(坏的、更糟糕的)

nlp - 斯坦福依存解析中的acl标签是什么?

python - gensim Doc2Vec vs tensorflow Doc2Vec

parsing - 斯坦福解析树表示中的标签 SBAR 意味着什么?

python-3.x - Tfidf 变压器(sklearn)结果为 : "no supported conversion for types: (dtype(' O'), )”

Python 命名实体识别 (NER) : Replace named entities with labels

python - 检测英语单词和nltk的单词语料库

python - 在 python : "No features in text" 中使用 langdetect 时出错

r - Lime:glmnet(x[, c(features, j) 中的错误,x 应该是具有 2 列或更多列的矩阵