Third edition of Artificial Intelligence: foundations of computational agents, Cambridge University Press, 2023 is now available (including the full text).

12.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 grammar rule 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 easily understand.


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

trans(scheduled(S,C,L,R),T1,T8)←
     trans(session(S),T1,[of | T3])∧
     trans(course(C),T3,[is,scheduled,at | T5])∧
     trans(time(L),T5,[in | T7])∧
     trans(room(R),T7,T8).
trans(session(w11),[the,winter,2011,session | T],T).
trans(course(cs422),[the,advanced,artificial,intelligence,course | T],T).
trans(time(clock(0,M)),[12,:,M,am | T],T).
trans(time(clock(H,M)),[H,:,M,am | T],T)←
     H>0∧H<12.
trans(time(clock(12,M)),[12,:,M,pm | T],T).
trans(time(clock(H,M)),[H1,:,M,pm | T],T)←
     H>12∧
     H1 is H-12.
trans(room(above(R)),[the,room,above | T1],T2)←
     trans(room(R),T1,T2).
trans(room(csci333),[the,computer,science,department,office | T],T).
Figure 12.8: Grammar for output of canned English

Example 12.36: Figure 12.8 shows a grammar for producing canned text on schedule information. For example, the query
ask trans(scheduled(w11,cs422,clock(15,30),above(csci333)),T,[]).

produces the answer T=[the, winter, 2011, 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 written as a sentence to the user.

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.