Skip to content

Section 11 Prepositional phrases

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.

Our sentence is getting rather crowded with people and objects. So let’s return to the pristine simplicity of Marie throwing the ball. But let’s give the action a setting: "Mary throws the ball in the park".

The phrase "in the park" (in het park) is a prepositional phrase and there are a number of ways we can create it using SimpleNLG. The simplest way would be to pass the string "in the park" to the addComplement method:

    SPhraseSpec p = nlgFactory.createClause("Marie", "gooien", "de bal");
    p.addComplement("in het park");

A more sophisticated way of creating this prepositional phrase, however, would be to specify the parts of the prepositional phrase – the preposition, determiner, noun phrase – and combine them:

    NPPhraseSpec place = nlgFactory.createNounPhrase("park");
    place.setDeterminer("het");
    PPPhraseSpec pp = nlgFactory.createPrepositionPhrase();
    pp.setObject(place);
    pp.setPreposition("in");

We then add the prepositional phrase as a complement to the ‘Marie gooit de bal’ sentence.

    p.addComplement(pp);

Note: adding the place to the prepositional phrase can be done using pp.setObject() or pp.addCopmlement().

Multiple ways

The table below shows three different ways of creating the prepositional phrase "in the park". As you can start to see, there are often several ways to realise sentences using simplenlg. The best way to do it depends on the needs of your system.

The third, sophisticated method requires much more code than the other two ways. So why then would we ever choose the third method?

The main reason is that the third method allows you to add pieces to a phrase or sentence with much greater ease. We have to remind ourselves that SimpleNLG will normally be used in a larger program which chooses the content of a sentence – and that content will likely be determined in a piecemeal fashion. It’s much easier to have SimpleNLG add a word or clause to a phrase which has been defined in a modular way (i.e., parts of the sentence are divided into chunks and labeled) rather than having to add new information to a monolithic string whose parts are not differentiated. For example, if we wanted to describe the park as groen ‘green’, and we had used the 3rd method to define our sentence, all we would need to do is write the following code:

    place.addPreModifier("groen");

Had we chosen the first or second methods, however, adding the adjective ‘groen’ to the string ‘park’ would be a major hassle. Among other things, you would have to write code which could:

  • Find where to insert the new word in the string. In most cases this would require parsing the string, which is no simple task!
  • Break that string into pieces to allow the insertion.
  • Insert the word.
  • Determine whether that insertion requires changing the other bits of string.
  • Put the pieces of string back together in a grammatical way.

In other words, you would have to write a realiser like SimpleNLG!

So why, given the major drawback stated above, would we ever choose to define a sentence using methods #1 and #2? Because sometimes we simply want to generate canned text, i.e., text that we know won’t need to be enlarged or changed and which we simply want output as-is. If we know that we won’t be changing a phrase (such as ‘in het park’), then it makes sense to treat it as a uniform entity the way the first two methods do.

→ For more examples of prepositional phrases, look at testsrc/PrepositionalPhraseTest.java.