13.6 Applications in Natural Language

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

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.

trans(scheduled(S,C,L,R),L1,L8)
    trans(session(S),L1,[ofL3])
    trans(course(C),L3,[is,scheduled,atL5])
    trans(time(L),L5,[inL7])
    trans(room(R),L7,L8).
trans(session(w21),[the,winter,2021,sessionT],T).
trans(course(cs422),[the,advanced,artificial,intelligence,courseT],T).
trans(time(clock(0,M)),[12,:,M,amT],T).
trans(time(clock(H,M)),[H,:,M,amT],T)
    H>0H<12.
trans(time(clock(12,M)),[12,:,M,pmT],T).
trans(time(clock(H,M)),[H1,:,M,pmT],T)
    H>12
    H1 is H-12.
trans(room(above(R)),[the,room,aboveL1],L2)
    trans(room(R),L1,L2).
trans(room(csci333),[the,computer,science,department,officeT],T).
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.