javalinguisticsnlgsimplenlg

SimpleNLG: how we specify the quantity?


My question is how to specify the quantity in a noun phrase? For example:

NPPhraseSpec np = nlgFactory.createNounPhrase("", "apple");

How to generate "5 apples", for example? A solution is to put a preModifier, the code would be:

    Lexicon lexicon = Lexicon.getDefaultLexicon();
    NLGFactory nlgFactory = new NLGFactory(lexicon);
    Realiser realiser = new Realiser();
    NPPhraseSpec np = nlgFactory.createNounPhrase("", "apple");
    np.addPreModifier("5");
    np.setPlural(true);
    System.out.println(realiser.realiseSentence(np));

But, isn't there another solution which handles the numbers and put the noun to plural automatically?


Solution

  • I'm afraid there is no built-in function to do this.

    However, if you're plugging SimpleNLG into a bigger pipeline, you could automate this by computing quantity prior to SimpleNLG. For example, say you're getting "5" by computing the number n of whatever is the head of NP (apples, bananas, pears, etc): if n is greater than 1, set plurality of the NP to true; else do nothing, since plural=false is default. You can even increment this to something fancier, such as: if n equals 0, add "no" as specifier.