7.3.8 Reusing predicates
Often it will pay to write predicates in a general way, so that they can be reused by other predicates.
// Finds the Agent (A), Undergoer (U), the // relation of the undergoer to the action (R), // and Act-type (T) in graph G act(G, T, A, U, R) :- subsume([Act]- -AGNT->[Entity], -R->[Entity], G), // Make sure that G has an Act-template branchOfCG([Act : T]-AGNT->[X : A], G), // Get the agent, A, and the type, T branchOfCG([Act : T]-R->[Y : U], G). // Get the undergoer U, and make sure it is the same act T.
This could be reused in other predicates:
// Find killer (A) and killed (U) kills(G, A, U) :- act(G, Kill, A, U, PTNT). // Find speaker and hearer talks(G, S, H) :- act(G, Talk, S, H, RCPT). // Find speaker, hearer and thematic content. talks_about(G, S, H, P) :- act(G, Talk, S, H, RCPT), act(G, Talk, S, P, THME).
Part II has come to an end. In part III, we look at Prolog in more detail.
PrevLite: 7.3.7 Conflict-act
NextLite: Part III: Programming
Prev: 7.3.7 Conflict-act
Up: 7.3 Examples
Next: Part III: Programming