Skip to content

Section 13 Generating a sentence with multiple clauses

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.

Phrases joined by a conjunction

One way of generating a sentence with multiple clauses is to use the SimpleNLG class CoordinatedPhraseElement.

    SPhraseSpec s1 = factory.createClause("mijn kat", "eten", "vis");
    SPhraseSpec s2 = factory.createClause("mijn hond", "eten", "grote botten");
    SPhraseSpec s3 = factory.createClause("mijn paard", "eten", "gras");

    CoordinatedPhraseElement c = nlgFactory.createCoordinatedPhrase();
    c.addCoordinate(s1);
    c.addCoordinate(s2);
    c.addCoordinate(s3);

The CoordinatedPhraseElement c object can then be realised as a sentence:

    String output = realiser.realiseSentence(c);
    System.out.println(output);

If you do not supply a conjunction using the method setConjunction, the conjunction ‘and’ will automatically be used because it is the default. In this case, the resulting sentence would be:

    Mijn kat eet vis, mijn hond eet grote bottem en mijn paard eet gras.

Subordinate clauses

Subordinate clauses can be added to the main clause using the addComplement method, where the kind of complementiser (“because”, “while”, etc.) to be used is set using the setFeature method.

    SPhraseSpec p = nlgFactory.createClause("ik", "zijn", "blij");
    SPhraseSpec q = nlgFactory.createClause("ik", "eet", "vis");
    
    q.setFeature(Feature.COMPLEMENTISER, "omdat");
    q.setFeature(Feature.TENSE, Tense.PAST);
    p.addComplement(q);
            
    String output4 = realiser.realiseSentence(p);  //Realiser created earlier
    System.out.println(output4);

The output is:

    Ik ben blij, omdat ik vis at.

In subordinate clauses (onderschikkende bijzinnen), the default Dutch word order changes from subjec-verb-object to subject-object-verb. The support for this is not complete yet and you may encounter situations that are not handled correctly.