java - 将复数名词转换为单数

标签 java nlp nlg

这是使用 SimpleNLG Java API 完成的

我想将“elves”转换为elf。下面的代码从单数转换为复数,如何修改才能从复数转换为单数?

final XMLLexicon xmlLexicon = new XMLLexicon();
final WordElement word = xmlLexicon.getWord("elves", LexicalCategory.NOUN);
final InflectedWordElement pluralWord = new InflectedWordElement(word);
pluralWord.setPlural(true);
final Realiser realiser = new Realiser(xmlLexicon);
System.out.println(realiser.realise(pluralWord));

最佳答案

这个 API 中显然没有 setSingular() 方法(我真的很依赖这个方法,而且我觉得很有趣的是没有这样的方法。)从 V4 开始也没有 setPlural() 方法。

[1] Note that in SimpleNLG V4, there are no lexicon methods to directly get inflected variants of a word; in other words, there is no equivalent in V4 of the SimpleNLG V3 getPlural(), getPastParticiple(), etc. methods. It is possible in V4 to compute inflected variants of words, but the process is more complicated: basically we need to create an InflectedWordElement around the base form, add appropriate features to this InflectedWordElement, and then realise it.

我认为这可能会起作用:(我没有测试它,因为我现在没有时间。)

final XMLLexicon xmlLexicon = new XMLLexicon();
final WordElement word = xmlLexicon.getWord("elves", LexicalCategory.NOUN);
final InflectedWordElement singularWord = new InflectedWordElement(word);
WordElement sw = singularWord.getBaseWord();
final Realiser realiser = new Realiser(xmlLexicon);
System.out.println(realiser.realise(sw));

如果这不起作用,欢迎您或其他人查看 here(docs)here(tutorial)来寻找答案。

关于java - 将复数名词转换为单数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40448348/

相关文章:

javascript - Svelte 给我 'Uncaught ReferenceError: require is not defined'

java - Intellij 不询问是否在同一窗口或不同窗口中打开项目

java - Hibernate 查询语言中的 SQL 子查询

JAVA 在每次出现特定符号时在字符串中换行

machine-learning - IBM Watson Natural Language Classifier 是否支持多个类和多个类集?

ruby - 是否有用于编写短语结构规则的开源框架?

java - 如何在 ActionListener 进行时更新 swing UI

nlp - Gensim:word2vec和doc2vec有什么区别?

java - SimpleNLG - 如何获得名词的复数形式?

java - SimpleNLG:我们如何指定数量?