13.6 Applications in Natural Language

13.6.4 Canned Text Output

There is nothing in the definition of the grammar that requires English input and the parse tree as output. A query of the grammar rules with the meaning of the sentence bound and a free variable representing the sentence can produce a sentence that matches the meaning.

One such use of grammar rules is to provide canned text output from logic terms; the output is a sentence in English that matches the logic term. This is useful for producing English versions of atoms, rules, and questions that a user – who may not know the intended interpretation of the symbols, or even the syntax of the formal language – can more easily understand.

% trans(Term,L0,L1) is true if Term translates into the words contained in the difference list L0-L1.

    H1 is H-12.
Figure 13.9: Grammar for output of canned English
Example 13.37.

Figure 13.9 shows a grammar for producing canned text on schedule information. The query

𝘢𝘴𝘬 trans(scheduled(w21,cs422,clock(15,30),above(csci333)),T,[]).

produces the answer T=[the, winter, 2021, session, of, the, advanced, artificial, intelligence, course, is, scheduled, at, 3, :, 30, pm, in, the, room, above, the, computer, science, department, office]. This list could be rewritten as a sentence to the user.

This code used the Prolog infix predicate “is”, where “V is E” is true when expression E evaluates to number V, and the binary relations > and <.

This grammar would probably not be useful for understanding natural language, because it requires a very stylized form of English; the user would have to use the exact translation of a term to get a legal parse.