这是使用 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/