chart.lisp
.
At the top of the file, include a statement which loads the given code
(see the module instructions for the specific statement).
bottom-up-chart(input searchmode quitmode)
input | A quoted list of symbols to be parsed |
searchmode | Either 'bfs or 'dfs |
quitmode | Either T or NIL |
For example,
(bottom-up-chart '(the large can) 'dfs t)The value returned by
bottom-up-chart
is the final
version of the chart (list of entry structs). Your code should implement the chart algorithm as described by Allen, with the following modifications:
dfs
, then new agenda
entries are added at the top of the agenda; when bfs
, new
agenda entries are added at the bottom of the agenda. When
searchmode is dfs
, then new active arcs are added
at the top of the active arc list; when bfs
, new active
arcs are added at the bottom of the active arc list.
T
, then the parser should
check to see if the latest entry on the chart covers the entire input
before it processes another item on the agenda. Since new items are
always added at the top of the chart, this has the affect of
terminating the algorithm as soon as a possible answer is found. When
quitmode is NIL
, then the parser should continue
processing until the agenda and the input are empty.
*chart-trace*
is non-NIL, your
code should print a trace message for each of the
operations. Each trace message is prefixed by the current entry from the agenda
(or EMPTY) if the agenda is empty):
EMPTY Reading from input (THE MAN HOLDS THE WATER)
EMPTY Entering ART (THE from 1 to 2) [agenda bottom]
(5 6 N WATER 7) Entering NP from 5 to 6 [agenda bottom]
(2 3 N MAN 2) Completes rule NP -> (N *) from 2 to 3
(1 2 ART THE 1) Starts rule NP -> (ART * ADJ N) from 1 to 2
(2 3 ADJ LARGE 2) Continues arc NP -> (ART ADJ * N) from 1 to 2
(2 3 N MAN 2) Completes arc NP -> (ART * N) from 1 to 2
(1 6 S (4 10) 12) ** Covers the input, continuing...[37 operations]
(1 6 S (4 10) 12) ** Covers the input, quitting [37 operations]
(1 6 S (4 10) 12) No input, quitting [38 operations]
chart-trace
, which you should use to print out messages
during operation:
(chart-trace format_string &rest args)
For example:
(chart-trace "~% ~10a Continues arc ~a -> ~a from ~a to ~a" item (arc-lhs arc) (insert-index (1+ (arc-index arc)) (arc-rhs arc)) (arc-start arc) end)
Here's a full-blown example of how a fully-traced example should look.
*parse-value*
is set to a list of these trees. When
global variable *print-parse-tree*
is non-NIL, your code
should print the parse trees that it produced before it returns the
chart, e.g.,> (bottom-up-chart '(the man holds the water in the can) 'dfs nil) Parse[1]: (S (NP (ART THE) (N MAN)) (VP (VP (V HOLDS) (NP (ART THE) (N WATER))) (PP (P IN) (NP (ART THE) (N CAN))))) Parse[2]: (S (NP (ART THE) (N MAN)) (VP (V HOLDS) (NP (NP (ART THE) (N WATER)) (PP (P IN) (NP (ART THE) (N CAN))))))
(Hint: The Lisp parse trees should be structured exactly like the ones
shown above, then you can use the built-in function
pprint
to print them.)
Here's a full-blown example of how a fully-traced example should look.
lookup-word
(input_symbol)(lookup-word 'large) --> (ADJ)
rules-started-by
(constituent)(rules-started-by 'art) --> (#S(RULE LHS NP RHS (ART ADJ N)) #S(RULE LHS NP RHS (ART N)))
rules-completed-by
(constituent)(rules-completed-by 'N) --> (#S(RULE LHS NP RHS (N)))
arcs-continued-by
(end constituent arcs)
arcs-completed-by
(end constituent arcs)