-
Notifications
You must be signed in to change notification settings - Fork 1
09 – Generating a sentence with multiple clauses
Like in SimpleNLG English, several options of creating a more complex sentence containing more than one clause exist. You can either create a so-called CoordinatedPhraseElement
, as below, or simply add one sentence as a complement to another sentence.
SPhraseSpec s1 = nlgFactory.createClause("meine Katze", "mögen", "Fisch");
SPhraseSpec s2 = nlgFactory.createClause("mein Hund", "mögen", "Knochen");
SPhraseSpec s3 = nlgFactory.createClause("mein Pferd", "mögen", "Gras");
CoordinatedPhraseElement c = nlgFactory.createCoordinatedPhrase();
c.addCoordinate(s1);
c.addCoordinate(s2);
c.addCoordinate(s3);
String output = realiser.realiseSentence(c);
System.out.println(output);
Per default, elements of the CoordinatedPhraseElement
are separated by comma, and the last element is separated by "und":
Meine Katze mag Fisch, mein Hund mag Knochen und mein Pferd mag Gras.
If you want to use another conjunction than "und", for instance "oder", you can specify this with:
c.setConjunction("oder");
In order to add a subordinate clause to a main clause, simply add the subordinate clause as a complement. By default, a clause set as a complement to another clause is added with a preceding comma. Optional, you can specify a complementiser, such as "während" in the following example:
SPhraseSpec p = nlgFactory.createClause("die Sonne", "scheinen");
SPhraseSpec q = nlgFactory.createClause("es", "regnen");
q.setFeature(Feature.COMPLEMENTISER, "während");
p.addComplement(q);
String output = realiser.realiseSentence(p);
System.out.println(output);
The output is:
Die Sonne scheint, während es regnet.
If "und" is set as complementiser, no comma is added:
SPhraseSpec p = nlgFactory.createClause("die Hund", "bellen");
SPhraseSpec q = nlgFactory.createClause("die Katze", "miauen");
q.setFeature(Feature.COMPLEMENTISER, "und");
p.addComplement(q);
String output = realiser.realiseSentence(p);
System.out.println(output);
The output here is:
Der Hund bellt und die Katze miaut.