Jeremy Hunts Jeremy Hunts - 29 days ago 20
Java Question

Convert a plural noun to singular

This is done using SimpleNLG Java API

I want to convert "elves" to elf. The code below converts from singular to plural, how can it be modified to convert from plural to singular ?

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));

Answer

There apparently is no setSingular() method in this API (I was really banking on that one, and I think it's kind of funny there isn't one for something like this.) Also there is no setPlural() method either as of V4.

[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.

I think this might do the trick: (I did not test it because I do not have time right now.)

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));

If that does not work you or anyone else is welcome to look here(docs) and here(tutorial) for the answer.

Comments