Skip to content

Section 10 Adding multiple subjects, objects and complements

Ruud de Jong edited this page Oct 24, 2018 · 1 revision

This page is based on a page of the wiki for the original SimpleNLG.

An SPhraseSpec can have multiple subjects, objects and complements but not multiple verbs (although a future version of SimpleNLG might include this functionality). This is done with the CoordinatedPhraseElement class. Let's add a second subject:

    NPPhraseSpec subject1 = nlgFactory.createNounPhrase("Marie");
    NPPhraseSpec subject2 = nlgFactory.createNounPhrase("Pieter");

    CoordinatedPhraseElement subj = nlgFactory.createCoordinatedPhrase(subject1, subject2); 

    p.setSubject(subj);
    p.setVerb("rennen");

The resulting output is:

    Marie en Pieter rennen.

SimpleNLG has automatically added the conjunction en ‘and’ and has changed the ending of the verb so that it agrees with the multiple subjects of the sentence.

Similarly, you can have multiple objects and complements in an SPhraseSpec. Let's add multiple objects. Instead of p.setObject(“de bal”), you would write:

    NPPhraseSpec object1 = nlgFactory.createNounPhrase("een bal");
    NPPhraseSpec object2 = nlgFactory.createNounPhrase("een doel");

    CoordinatedPhraseElement obj = nlgFactory.createCoordinatedPhrase(object1, object2); 
    obj.addCoordinate("een scheidsrechter");
    
    p.setObject(obj);
    p.setVerb("zien");

The resulting output will be:

    Marie en Pieter zien een bal, een doel en een scheidsrechter.

'Mary and Peter see a ball, a goal and a referee.'

You can change the conjunction on the coordinated elements:

    obj.setFeature(Feature.CONJUNCTION, "of");

The resulting output will be:

    Marie en Pieter zien een bal, een doel of een scheidsrechter.

As with many methods in SimpleNLG, the createCoordinatedPhrase method can take all kinds of arguments – NPPhraseSpec, PPPhraseSpec, or even simple strings.

→ For more examples on coordination, look at testsrc/ClauseAggregationTest.java.