SimpleNLG - Is it possible to have SimpleNLG automatically detect if a noun is singular or plural?

1.2k Views Asked by At

The following SimpleNLG code which specifies the subject, verb and object using "monkeys", "eat", "bananas", respectively produces the sentence "monkey eats bananas". Thus, you see that it converted the plural nouns into singular ones (and ensured the verb agrees accordingly). Is there a way to ensure that SimpleNLG detects they're plurals and keeps them as such? I've seen documentation mention that certain Lexicon files may do this, but I tried the NIH Lexicon and that didn't help. Is this simply not supported by SimpleNLG? Or is there a way to do it using SimpleNLG or otherwise?

    Lexicon = new Lexicon.getDefaultLexicon()
    nlgFactory = new NLGFactory(lexicon);
    Realiser realiser = new Realiser(lexicon);

    NPPhraseSpec subject = nlgFactory.createNounPhrase("monkeys");
    VPPhraseSpec verb = nlgFactory.createVerbPhrase("eat");
    NPPhraseSpec object = nlgFactory.createNounPhrase("bananas");

    SPhraseSpec clause  = nlgFactory.createClause();
    clause.setSubject(subject);
    clause.setVerbPhrase(verb);
    clause.setObject(object);

    System.out.print(realiser.realiseSentence(clause));
2

There are 2 best solutions below

1
On

The issue with SimpleNLG is it's not meant to be smart. Anything you need, you have to declare it. If you need a plural noun, you need to declare it instead of just passing "monkeys" as argument.

subject.setPlural(true);

By default SimpleNLG will convert words to base form (for nouns -> singular). It won't work if the noun isn't in the lexicon and it's irregular.

Underlying SimpleNLG does POS tagging. But you won't be able to access it unless you hack the code. What I did before is I combined SimpleNLG with external preprocessing pipeline (I needed other tasks like dependency parsing (using Stanford CoreNLP) anyway, which SimpleNLG doesn't provide). The code looks something like:

if (subjectHeadNode.getPos().equals("NNS") || subjectHeadNode.getPos().equals("NNPS")){
    if(!subjectHeadNode.getLemma().equalsIgnoreCase(subjectHeadNode.getWord())){
        tempSpec.setPlural(true);
    }
}
0
On

With the latest changes in SimpleNLG, you can take the Noun Phrase and then manually assign it to be Plural. You can do this by using the setFeature method as:

subject.setFeature(Feature.NUMBER, NumberAgreement.PLURAL);

where NumberAgreement in an enum of Singular/Plural/Both(which are same for both singular and plural) values.

However, i just checked, that the output:

Monkeys eat banana.

only gets generated if we put the subject as 'monkey' and not 'monkeys, in which case the o/p becomes "Monkeyses eat banana."

As commented earlier, SimpleNLG does not use much intelligence in terms of form, manner, etc outside simple Subject-Verb-Object morphology.