100 likes | 212 Views
02/27/98 Natural Language Processing. Administrative New version of PS4 on the Web different interface to the Truckworld more extra credit options PS4 due Friday 3/13 (last day of class) special end-of-quarter offer: turn in at the final costs 2 late days! Last time building the lexicon
E N D
02/27/98 Natural Language Processing • Administrative • New version of PS4 on the Web • different interface to the Truckworld • more extra credit options • PS4 due Friday 3/13 (last day of class) • special end-of-quarter offer: turn in at the final costs 2 late days! • Last time • building the lexicon • This time • parsing (building the grammar)
The Lexicon from Last Time (setf *lexicon* '( (lift (verb (root lift))) (pick-up (verb (root lift))) (drop (verb (root drop))) (put-down (verb (root drop))) (move (verb (root move))) (pick (verb-h (root pick))) (put (verb-h (root put))) (on (prep (root on))) (above (prep (root above))) (below (prep (root below))) (next-to (prep (root next-to))) (at (prep (root at))) (up (prep-h (root up))) (down (prep-h (root down))) (next (prep-h (root next))) (to (prep-h (root to))) (of (prep-h (root of))) (left (dir (root left))) (right (dir (root right))) ;; Omitted green, blue, purple (red (adj (root red))) (orange (adj (root orange))) (yellow (adj (root yellow))) (block (noun (root block))) (sphere (noun (root sphere))) (cube (noun (root cube))) (pyramid (noun (root pyramid))) (position (noun (root position))) ;; Omitted three through five (one (number (root 1))) (two (number (root 2))) (1 (number (root 1))) (2 (number (root 2))) (the (art (count one) (root the))) (a (art (count any) (root a))) (an (art (count any) (root an))) ))
Parsing • The task: • take as input a sentence (list of symbols/words) and a grammar • produce as output • whether or not the sentence is grammatical? • a parse tree? • Grammar as rewrite rules: Actually these are lexicon entries like on the previous slide S NP VP NP NP ADJS Noun NP Det ADJS Noun ADJS ADJS Adj ADJS VP Verb VP Adverb Verb Det a Det an Det the Noun rock Noun glass Noun glasses Noun Fred Adjheavy Adjbroken Adjred Verbbreaks Verbrecycles Verb“Picks up” Advquickly Advcarefully
Top-down and bottom-up rewrites S NP VP NP ADJS Noun VP NP Noun VP NP Fred VP NP Fred Adverb Verb NP Fred carefully Verb NP Fred carefullyrecyclesNP Fred carefullyrecyclesDet ADJS Noun Fred carefullyrecyclesthe ADJS Noun Fred carefullyrecyclesthe Adj ADJS Noun Fred carefullyrecyclestheheavy ADJS Noun Fred carefullyrecyclestheheavy Adj ADJS Noun Fred carefullyrecyclestheheavyred ADJS Noun Fred carefullyrecyclestheheavyred Noun Fred carefullyrecyclestheheavyredrock Fred carefullyrecyclestheheavyredrock Noun Adv Verb Det Adj Adj Noun ADJS Noun Adv Verb Det Adj Adj Noun NP Adv Verb Det Adj Adj Noun NP VP Det Adj Adj ADJS Noun NP VP Det Adj ADJS Noun NP VP Det ADJS Noun NP VP NP S S NP VP NP NP ADJS Noun NP Det ADJS Noun ADJS ADJS Adj ADJS VP Verb VP Adv Verb To parse: Fred carefullyrecyclestheheavyredrock
The Parse Tree • Fred carefully recycles the heavy red rock. S NP VP NP ADJS Noun Adverb Verb Det ADJS Noun the Fred carefully recycles rock Adj ADJS heavy Adj ADJS red
Using the Supplied Parser (defvar *lexicon*) (setf *lexicon* '( (rock (noun (root rock))) (rocks (noun (root rock))) (glass (noun (root glass))) (glasses (noun (root glass))) (fred (noun (root fred))) (a (det (root a))) (an (det (root an))) (the (det (root the))) (heavy (adj (root heavy))) (broken (adj (root broken))) (red (adj (root red))) (breaks (verb (root break))) (recycles (verb (root recycle))) (lifts (verb (root lift))) (quickly (adv (root quick))) (carefully (adv (root care)))))
Parser Code Continued: The Grammar (defvar *grammar*) (setf *grammar* '( ((s) -> (np) (vp) (np)) ((np) -> (det) (opt-adjs) (noun)) ((np) -> (noun)) ((opt-adjs) -> (adj) (opt-adjs)) ((opt-adjs) ->) ((vp) -> (verb)) ((vp) -> (adv) (verb)) ))
Parser Code Continued: IO (defun do-parse (sentence &key (start-symbol 's) (verbose T)) (parse :start-symbol start-symbol :sentence sentence :verbose verbose :print verbose)) (do-parse '(fred carefully recycles the heavy red rock)) (S (1 (NP (1 (NOUN (ROOT FRED))))) (2 (VP (1 (ADV (ROOT CARE))) (2 (VERB (ROOT RECYCLE))))) (3 (NP (1 (DET (ROOT THE))) (2 (OPT-ADJS (1 (ADJ (ROOT HEAVY))) (2 (OPT-ADJS (1 (ADJ (ROOT RED))) (2 (OPT-ADJS)))))) (3 (NOUN (ROOT ROCK))))))