Skip to content

Section VIII – Adding adjectives via ‘modifier’

Saad Mahamood edited this page Mar 9, 2015 · 1 revision

We know for a fact that Mary is an good runner, so we’d like to assign Mary a suitable adjective, like ‘fast’. This can be generated by the simplenlg library using the concept of modifier.

To deem Mary ‘fast’, however, you will no longer want to refer to her simply as the ‘subject’ of the sentence. Instead, let’s also define her name as a noun phrase (which it is). In that way, we can ascribe the adjective ‘fast’ to Mary (which she certainly is) by means of the modifier function.

    NPPhraseSpec subject = nlgFactory.createNounPhrase("Mary");

While we're at it, let's also define the object as a noun phrase and the verb as a verb phrase. This will allow us to do some fancier stuff later on, like adding a modifier to each.

    NPPhraseSpec object = nlgFactory.createNounPhrase("the monkey");  [1]
    VPPhraseSpec verb = nlgFactory.createVerbPhrase("chase");

Now, we can apply the adjective ‘fast’ to Mary by writing:

    subject.addModifier("fast");

Next, we set the subject, object, and verb on the SPhraseSpec p that we defined earlier:

    p.setSubject(subject);
    p.setObject(object);
    p.setVerb(verb);

    String output3 = realiser.realiseSentence(p); // Realiser created earlier.
    System.out.println(output3);

The output will be:

    Fast Mary chases the monkey.

Similarly, we can let the world know that Mary, true to her nature, is chasing the monkey quickly. The adverb ‘quickly’ may also be added using the addModifier function, but this time it's the verb that's being modified:

    verb.addModifier("quickly"); 

The output will be:

    Fast Mary quickly chases the monkey.

→ For more examples on noun phrases, look at testsrc/NounPhraseTest.java.

→ For more examples on modifiers, look at testsrc/AdjectivePhraseTest.java.


[1] Note that we can also construct the noun phrase "the monkey" in the following way:

    NPPhraseSpec object = nlgFactory.createNounPhrase("monkey");
    object.setDeterminer("the"); // currently this is 'deprecated'!