4

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?

Jakob
  • 3,570
  • 3
  • 36
  • 49
Karim
  • 133
  • 5

1 Answers1

1

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.

Rodrigo
  • 321
  • 2
  • 11
  • Thank you for your answer. Actually, there is another problem when we add an adjective after adding the quantity. I add an the adjective as preModifier it will give "delicious 5 apples" and not "5 delicious apples". Also, if I add the adjective as addModifier, it will give "5, delicious apples" I wonder if this late one is correct (talking about the comma). – Karim Mar 07 '16 at 10:09
  • 1
    You are crossing the boundaries of what SimpleNLG can do. It would be great if SimpleNLG could understand that "5" (or "five") bares numerical meaning and that "delicious" denotes quality, in which case the system would know how to order things. But reality is different: to SimpleNLG "5" and "delicious" are just strings, completely disjoint from any semantics they could carry. There is a desire to include statistical language models in SimpleNLG -- which could (without guarantees) solve your problem -- but AFAIK these are just plans at the moment. – Rodrigo Jan 20 '17 at 09:08