我用simpleNLG来查找动词的实际时态。但我似乎做得不对,而不是把动词的时态转换成现在时。
public class TenseWas
{
public static void main(String[] args)
{
String word = "ate";
Lexicon lexicon=Lexicon.getDefaultLexicon();
NLGFactory nlgFactory=new NLGFactory(lexicon);
Realiser realiser=new Realiser(lexicon);
SPhraseSpec p=nlgFactory.createClause();
p.setVerb(word);
if(p.getVerb().getFeature(Feature.TENSE) == (Tense.PAST))
{
System.out.println("past");
}
if(p.getVerb().getFeature(Feature.TENSE) == (Tense.FUTURE))
{
System.out.println("future");
}
if(p.getVerb().getFeature(Feature.TENSE) == (Tense.PRESENT))
{
System.out.println("Present");
}
String output=realiser.realiseSentence(p);
System.out.println(output);
}
}这就是控制台中显示的内容:
吃东西。
发布于 2017-03-25 16:49:24
调用getFeature()并不能告诉您所设置的动词是什么时态,它与您为呈现子句而设置的子句的时态相呼应。你就这样用它:
p.setSubject("Foo");
p.setVerb("eat");
p.setObject("bar");
p.setFeature(Feature.TENSE, Tense.PAST);
String output = realiser.realiseSentence(p);
System.out.println(output); // "Foo ate bar"发布于 2017-03-28 17:31:59
为未来的程序员解答。
正如@Bohemian所指出的,simplenlg不是用来对动词的动词时态进行分类的,而是一个实现引擎,用来将“句子”的抽象表示转换为实际句子。
如果您查看simplenlg使用的词汇表xml 'database‘库,它包括动词和名词的注释版本等,它在https://github.com/simplenlg/simplenlg/blob/master/src/main/resources/default-lexicon.xml中。FYI,您可以使用其他词汇表xml数据库。
<word>
<base>sleep</base>
<category>verb</category>
<id>E0056246</id>
<present3s>sleeps</present3s>
<intransitive/>
<past>slept</past>
<pastParticiple>slept</pastParticiple>
<presentParticiple>sleeping</presentParticiple>
<transitive/>
</word>因此,要回答你的问题,你不应该使用simplenlg来获取动词的时态,而应该使用其他NLP/‘智能’库来进行‘动词’或单词分类,比如CoreNLP或OpenNLP中的词性标记部分,下面是关于它们的信息,OpenNLP vs Stanford CoreNLP
https://stackoverflow.com/questions/43017612
复制相似问题