<< Prev | - Up - | Next >> |
Let's look at an example, to see if we've got it right. If you ask Prolog
Let's look at an example, to see if we've got it right. If you ask Prolog
recognize_bottomup([vincent,shot,marsellus])
it will answer yes
, as it should. Try some other examples and check whether Prolog answers the way it should. A trace will give you more information about how Prolog is arriving at these answers. Here is an abbreviated trace for the query recognize_bottomup([vincent,shot,marsellus])
. You can see how Prolog splits up the string that is to be recognized into three parts, which rules it applies for replacing the middle part with a category symbol, and you can see the recursive calls of recognize_bottomup
that it makes.
?- recognize_bottomup([vincent,shot,marsellus]).
Call: (7) recognize_bottomup([vincent, shot, marsellus]) ?
Call: (8) split([vincent, shot, marsellus], _G647, _G648, _G649) ?
Exit: (8) split([vincent, shot, marsellus], [], [vincent], [shot, marsellus]) ?
Call: (8) lex(vincent, _G653) ?
Exit: (8) lex(vincent, pn) ?
Call: (8) recognize_bottomup([pn, shot, marsellus]) ?
Call: (9) split([pn, shot, marsellus], _G656, _G657, _G658) ?
Exit: (9) split([pn, shot, marsellus], [], [pn], [shot, marsellus]) ?
Call: (9) _G658--->[pn] ?
Exit: (9) np--->[pn] ?
Call: (9) recognize_bottomup([np, shot, marsellus]) ?
Call: (10) split([np, shot, marsellus], _G662, _G663, _G664) ?
Exit: (10) split([np, shot, marsellus], [np], [shot], [marsellus]) ?
Call: (10) lex(shot, _G671) ?
Exit: (10) lex(shot, tv) ?
Call: (10) recognize_bottomup([np, tv, marsellus]) ?
Call: (11) split([np, tv, marsellus], _G677, _G678, _G679) ?
Exit: (11) split([np, tv, marsellus], [np, tv], [marsellus], []) ?
Call: (11) lex(marsellus, _G689) ?
Exit: (11) lex(marsellus, pn) ?
Call: (11) recognize_bottomup([np, tv, pn]) ?
Call: (12) split([np, tv, pn], _G698, _G699, _G700) ?
Exit: (12) split([np, tv, pn], [np, tv], [pn], []) ?
Call: (12) _G706--->[pn] ?
Exit: (12) np--->[pn] ?
Call: (12) recognize_bottomup([np, tv, np]) ?
Call: (13) split([np, tv, np], _G716, _G717, _G718) ?
Exit: (13) split([np, tv, np], [np], [tv, np], []) ?
Call: (13) _G724--->[tv, np] ?
Exit: (13) vp--->[tv, np] ?
Call: (13) recognize_bottomup([np, vp]) ?
Call: (14) split([np, vp], _G731, _G732, _G733) ?
Exit: (14) split([np, vp], [], [np, vp], []) ?
Call: (14) _G736--->[np, vp] ?
Exit: (14) s--->[np, vp] ?
Call: (14) recognize_bottomup([s]) ?
Exit: (14) recognize_bottomup([s]) ?
Exit: (13) recognize_bottomup([np, vp]) ?
Exit: (12) recognize_bottomup([np, tv, np]) ?
Exit: (11) recognize_bottomup([np, tv, pn]) ?
Exit: (10) recognize_bottomup([np, tv, marsellus]) ?
Exit: (9) recognize_bottomup([np, shot, marsellus]) ?
Exit: (8) recognize_bottomup([pn, shot, marsellus]) ?
Exit: (7) recognize_bottomup([vincent, shot, marsellus]) ?
Yes
This trace only shows the essence of how the recognizer arrives at its answer. We cut out all the rest. Try it yourself and you will see that the recognizer spends a LOT of time trying out different ways of splitting up the string.
<< Prev | - Up - | Next >> |