CH9 - Dynamic Programming and The Earley Parser
CH9 - Dynamic Programming and The Earley Parser
Parser
125
126 Part II: Programming in Prolog
·
Noun Verb Noun Verb ·
Noun Verb
mary · runs ·
mary runs
Each state in the list of states S0 has now been processed, so the algorithm
moves to S1 and considers the state (Noun → mary •). Since this is a
completed state, the completer procedure is applied. For each state
expecting a Noun, that is, has the • Noun pattern, the completer
Chapter 9 The Earley Parser 129
Processing the new state S2, the completer advances the dot in
(S → Noun • Verb) to produce (S → Noun Verb •), from
which the completer generates the state ($ → S •) signifying a
successful parse of a sentence. The final chart for mary runs, with
three state lists, is:
($ → @ S, [0,0])) ==>
(S → @ NP VP, [0,0])
(S → @ NP VP, [0,0]) ==>
(NP → @ NP PP, [0,0])
(S → @ NP VP, [0,0]) ==>
(NP → @ Noun, [0,0])
3. Verifying that the next word word[i + 1] =
word[1] or “john” is a Noun:
The scanner procedure initializes chart[1] by
producing
(NP → @ Noun, [0,0]) ==>
(Noun → john @, [0,1])
chart[0]:
[($ → @ S, [0,0]) start state
(S → @ NP VP, [0,0]) predictor
(NP → @ NP PP, [0,0]) * predictor
(NP → @ Noun, [0,0])] predictor
chart[1]:
[(Noun → john @, [0,1]) scanner
(NP → Noun @, [0,1]) completer
(S → NP @ VP, [0,1]) completer
(NP → NP @ PP, [0,1]) * completer
(VP → @ Verb NP, [1,1])** predictor
(VP → @ VP PP, [1,1]) ** predictor
(PP → @ Prep NP, [1,1])*] predictor
chart[2]:
[(Verb → called @, [1,2]) scanner
(VP → Verb @ NP, [1,2]) completer
(NP → @ NP PP, [2,2]) predictor
(NP → @ Noun, [2,2])[ predictor
chart[3]:
[(Noun → mary @, [2,3]) scanner
(NP → Noun @, [2,3]) completer
(VP → Verb NP @, [1,3]) completer
(NP → NP @ PP, [2,3]) completer
(S → NP VP @, [0,3])* completer
(VP → VP @ PP, [1,3]) completer
(PP → @ Prep NP, [3,3]) predictor
($ → S @, [0,3])*] completer
chart[4]:
[(Prep → from @, [3,4]) scanner
(PP → Prep @ NP, [3,4]) completer
(NP → @ NP PP, [4,4])* predictor
(NP → @ Noun, [4,4])] predictor
chart[5]:
[(Noun → denver @, [4,5]) scanner
(NP → Noun @, [4,5]) completer
(PP → Prep NP @, [3,5]) completer
(NP → NP @ PP, [4,5])* completer
(NP → NP PP @, [2,5]) completer
(VP → VP PP @, [1,5]) completer
(PP → @ Prep NP, [5,5])* predictor
(VP → Verb NP @, [1,5]) completer
(NP → NP @ PP, [2,5])* completer
(S → NP VP @, [0,5]) completer
(VP → VP @ PP, [1,5])* completer
($ → S @, [0,5])] completer
134 Part II: Programming in Prolog
S
(a)
VP
NP
PP
NP NP NP
VP
VP PP
NP NP NP
lists, and Chart is the current chart. Thus, Si and SNext are always
subsets of the current Chart. Notice that the “assignment” that creates
the next state-list is done with unification (=).
The PS utilities perform initial and final state checks, determine if the
current state list is complete, extract components of the current state and
get the next input value. Parsing is finished when the Word list and the
current state list Si, the first and third arguments of PS, are both empty. If
Si is empty but the Word list is not, then the next state list becomes the
new current state list and the parser moves to the next index as is seen in
the current_state_set_done predicate:
initial_parser_state(Words, StartState, InitPS) :-
InitPS = ps(Words, 0, [StartState], [],
[StartState]).
final_state_set_done( ps([], _, [], _, FinalChart),
FinalChart).
current_state_set_done( ps([_|Words], I, [], SNext,
Chart), ps( Words, J, SNext, [],
Chart)) :-
J is I+1.
parsing. What order are these procedures called in when parsing a sentence,
and why is that ordering important? Explain your answers to the order of
procedure invocation in detail.
4. Augment the Earley Prolog parser to consider the sentence “John saw
the burglar with the telescope”. Create two different possible pare trees
from interpreting this string and comment on how the different possible
parses are retrieved them from the chart.
5. Create an 8 – 10 word sentence of your own and send it to the Earley
parser. Produce the chart as it changes with each additional word of the
sentence that is scanned.
6. Create a grammar that includes adjectives and adverbs in its list of rules.
What changes are needed for the Earley parser to handle these new rules?
Test the Early parser with sentences that contain adjectives and adverbs.
7. In the case of “John called Mary from Denver” the parser produced two
parse trees. Analyze Figure 9.4 and show which components of the full
parse are shared between both trees and where the critical differences are.
8. Analyze the complexity of the Earley algorithm. What was the cost of
the two parses that we considered in detail in this chapter? What are the
worst- and best-case complexity limits? What type sentences force the
worst case? Alternatively, what types of sentences are optimal?