Subject elision
Note
This section of the tutorial is also available as a downloadable project.
In this section, we show you another way to use lex rules for planning multiple sentences. This time, we show you how to combine sentences that have the same subject. For example:
Anna Smith is Head of Marketing. Anna Smith manages a team of twelve.
When these sentences are joined with subject elision, the result is:
Anna Smith is Head of Marketing and manages a team of twelve.
The two sentences have been combined with "and". The subject of the second sentence has been left out (or “elided”). We say the sentences have been joined with subject elision.
We’ll go through an example. The JSON data we’ll use is the same as for the last section:
{ "employees": [ { "name": "Peter Jones", "job": "Head of Innovation", "teamSize": 1, "location": "New York" }, { "name": "George Scott", "job": "Head Janitor", "teamSize": 2, "location": "New York" }, { "name": "Anna Smith", "job": "Head of Marketing", "teamSize": 12, "location": "New York" }, { "name": "Sue Collins", "job": "Chief Software Developer", "teamSize": 15, "location": "London" } ] }
But this time, we’ll use the two lex rules shown below:
<S id="jobId" classes="jobClass"> <Subj word="{{msg.name}}"> <Feature name="elidable" value="true"/> </Subj> <VP word="be"/> <Obj word="{{msg.job}}"/> </S> <S id="teamId" classes="teamClass"> <Subj word="{{msg.name}}"> <Feature name="elidable" value="true"/> </Subj> <VP word="manages"/> <Obj> <NP string="a team"/> <NP preposition="of"> <Number int="{{msg.teamSize}}" isAlpha="true"/> </NP> </Obj> </S>
Important
Lex rules should be inside a lex rules file, as shown here.
Equivalent parse trees for the lex rules are shown below:
The second noun phrase (NP) in the object of the second rule is actually a prepositional phrase (shown as PP in the image); this is because there is preposition="of"
in the opening tag of that NP.
Both lex rules have a new feature: <Feature name="elidable" value="true"/>
. Because the feature is added inside the subject (i.e. inside the Subj
tabs), it enables the subjects of sentences generated by this rule to be elided in certain contexts.
JSON data values are accessed in the lex rules as before with "{{msg.name}}"
, "{{msg.job}}"
, and "{{msg.teamSize}}"
. The JSON data values are accessed through the keys (“name”, “job” and “teamSize”) for the section of the JSON data that is input to the rules.
Let’s generate sentences by calling the realise function twice, each time with a different lex rule and using the entire “employees” array:
ATL in Script | Result |
---|---|
| Peter Jones is Head of Innovation. George Scott is Head Janitor. Anna Smith is Head of Marketing. Sue Collins is Chief Software Developer. |
| Peter Jones manages a team of one. George Scott manages a team of two. Anna Smith manages a team of twelve. Sue Collins manages a team of fifteen. |
Remember that the realise
function’s parameter is a tuple. In this case, the first realise
function contains a tuple with the entire array WholeJSON.employees
and the value of "classes" specified in the opening tag of the first lex rule, jobClass
. The second realise
function’s tuple has the same JSON data but the value of "classes" is teamClass
from the second lex rule.
There is no subject elision because the subjects are all different!
Now we’ve seen that both lex rules work. Let’s call the realise
function with two tuples using the first element in the “employees” array and both lex rules. Now we get subject elision:
ATL in Script | Result |
---|---|
| Peter Jones is Head of Innovation and manages a team of one. |
The sentences from the two lex rules are joined and the subject of the second has been elided.
Next, we’ll call the realise
function with two tuples using each element of the "employees" array in turn and both lex rules. The result is subject elision on all output sentences:
ATL in Script | Result |
---|---|
| Peter Jones is Head of Innovation and manages a team of one. George Scott is Head Janitor and manages a team of two. Anna Smith is Head of Marketing and manages a team of twelve. Sue Collins is Chief Software Developer and manages a team of fifteen. |
The forAll function goes through the "employees" array and calls realise
on each element in the array using both lex rules. The result is four aggregated sentences with subject elision, one for each person’s data.
Finally, we’ll create a user-defined function, describeEmployee
, that uses the employee’s name as a subheading and a call to realise
with two tuples as before:
#define describeEmployee(employee) [[employee.name]] [[ realise((employee,"jobClass"),(employee,"teamClass" )) ]]
We call describeEmployee()
in the Main script with the forAll
function as follows:
[[forAll(WholeJSON.employees, employee -> describeEmployee(employee) )]]
The result is that each element in the array in turn is input to our user-defined function, describeEmployee
:
Peter Jones is Head of Innovation and manages a team of one.
George Scott is Head Janitor and manages a team of two.
Anna Smith is Head of Marketing and manages a team of twelve.
Sue Collins is Chief Software Developer and manages a team of fifteen.
The effect of subject elision in our examples is to join information about each person in a single sentence, as shown in the image below:
Note
Subject elision will only occur if the following conditions are true:
The sentences are adjacent.
The sentence components to be elided have the feature
<Feature name="elidable" value="true"/>.
The components to be elided are identical.
Exercise
For this exercise, you must download and unzip our Subject Elision JSON project for this section of the tutorial. Import the project file into your Project Portal. Open the project, then click Lex Rules (left side menu) to view the XML code for the above lex rules.
If you preview the Main script, you will see the results of generating individual sentences and joined sentences with elided subjects from the rule. Try changing the JSON data and/or the calls to the realise
function and view the effects on the output in Preview.
Your challenge is to do the following:
Add another key-value pair to each element of the JSON array as follows:
Index
Key-Value Pair
0
"area": "intelligent robots"
1
"area": "robot vacuum cleaners"
2
"area": "sales initiatives"
3
"area": "intelligent software design"
Write another lex rule with a subject the same as the other two. The rule should generate sentences such as "Peter Jones specializes in intelligent robots."
Add to the realise function in the user-defined function
describeEmployee
. The new sentence should link to the existing two sentences with subject elision.For example, the output sentences could look something like:
Peter Jones is Head of Innovation, manages a team of one and specializes in intelligent robots.
George Scott is Head Janitor, manages a team of two and specializes in robot vacuum cleaners.
Anna Smith is Head of Marketing, manages a team of twelve and specializes in sales initiatives.
Sue Collins is Chief Software Developer, manages a team of fifteen and specializes in intelligent software design.
Tip
If you get stuck, download our solution JSON project.
Unzip it, upload it, and view the JSON data, lex rules and ATL code as above.
What you learned in this section
How to turn on elision in a lex rule.
How to call the realise function with two tuples using the same data, but different lex rules, to get a single sentence with subject elision.
How subject elision can be used to join information about the same subject in a single sentence.
Congratulations! You’ve completed the Lex Rules Tutorial!