The CYK Parsing Algorithm

Similar documents
The Decreasing-Time Algorithm

The Critical-Path Algorithm

Minimal Spanning Trees

The Traveling Salesman Problem Brute Force Method

LR Parsing - Conflicts

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 27, 2013

Recursive Sequences. Lecture 24 Section 5.6. Robb T. Koether. Hampden-Sydney College. Wed, Feb 26, 2014

Recursive Descent Parsers

Sampling Distribution Examples Sections 15.4, 15.5

Rotations and Translations

The Class Construct Part 1

The Traveling Salesman Problem Nearest-Neighbor Algorithm

Scope and Parameter Passing

Street-Routing Problems

Regular Expressions. Lecture 10 Sections Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2016

while Loops Lecture 13 Sections Robb T. Koether Wed, Sep 26, 2018 Hampden-Sydney College

Scheduling and Digraphs

The string Class. Lecture 21 Sections 2.9, 3.9, Robb T. Koether. Wed, Oct 17, Hampden-Sydney College

The Pairwise-Comparison Method

Stack Applications. Lecture 27 Sections Robb T. Koether. Hampden-Sydney College. Wed, Mar 29, 2017

Decision Properties for Context-free Languages

The Plurality-with-Elimination Method

Scope and Parameter Passing

Solving Recursive Sequences by Iteration

Boxplots. Lecture 17 Section Robb T. Koether. Hampden-Sydney College. Wed, Feb 10, 2010

Magnification and Minification

Density Curves Sections

Normal Forms and Parsing. CS154 Chris Pollett Mar 14, 2007.

Nondeterministic Programming in C++

Boolean Expressions. Lecture 31 Sections 6.6, 6.7. Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

XPath Lecture 34. Robb T. Koether. Hampden-Sydney College. Wed, Apr 11, 2012

Building the Abstract Syntax Trees

Operators. Lecture 12 Section Robb T. Koether. Hampden-Sydney College. Fri, Feb 9, 2018

The CKY Parsing Algorithm and PCFGs. COMP-599 Oct 12, 2016

The Graphics Pipeline

Friends and Unary Operators

The Coefficient of Determination

CYK parsing. I love automata theory I love love automata automata theory I love automata love automata theory I love automata theory

Displaying Distributions - Quantitative Variables

LR Parsing - The Items

The Graphics Pipeline

Programming Languages

Parsing. Cocke Younger Kasami (CYK) Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 35

Mipmaps. Lecture 35. Robb T. Koether. Hampden-Sydney College. Wed, Nov 18, 2015

Relational Databases

Recursion. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 17, 2018

Recursive Linked Lists

Linked Lists. Lecture 16 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 22, 2017

Abstract Data Types. Lecture 23 Section 7.1. Robb T. Koether. Hampden-Sydney College. Wed, Oct 24, 2012

PHP Queries and HTML Forms Lecture 23

The Normal Distribution

Programming Languages

Implementing Linked Lists

XQuery FLOWR Expressions Lecture 35

Function Usage. Lecture 15 Sections 6.3, 6.4. Robb T. Koether. Hampden-Sydney College. Mon, Oct 1, 2018

XML Attributes. Lecture 33. Robb T. Koether. Hampden-Sydney College. Wed, Apr 25, 2018

Total Orders. Lecture 41 Section 8.5. Robb T. Koether. Hampden-Sydney College. Mon, Apr 8, 2013

Pointers. Lecture 1 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 14, 2015

Stack Applications. Lecture 25 Sections Robb T. Koether. Hampden-Sydney College. Mon, Mar 30, 2015

XPath. Lecture 36. Robb T. Koether. Wed, Apr 16, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) XPath Wed, Apr 16, / 28

Introduction to Compiler Design

List Iterator Implementation

Relational Databases Lecture 2

Specular Reflection. Lecture 19. Robb T. Koether. Hampden-Sydney College. Wed, Oct 4, 2017

Function Definition Syntax Tree

Recognition of Tokens

Aggregation. Lecture 7 Section Robb T. Koether. Hampden-Sydney College. Wed, Jan 29, 2014

Ambient and Diffuse Light

Binary Tree Applications

The Projection Matrix

Pointers. Lecture 2 Sections Robb T. Koether. Hampden-Sydney College. Fri, Jan 18, 2013

Natural Language Processing

Triggers. Lecture 14. Robb T. Koether. Hampden-Sydney College. Wed, Feb 14, 2018

Recursion. Lecture 26 Sections , Robb T. Koether. Hampden-Sydney College. Mon, Apr 6, 2015

Webpage Navigation. Lecture 27. Robb T. Koether. Hampden-Sydney College. Mon, Apr 2, 2018

Stacks and their Applications

CUP. Lecture 18 CUP User s Manual (online) Robb T. Koether. Hampden-Sydney College. Fri, Feb 27, 2015

Pointer Arithmetic. Lecture 4 Chapter 10. Robb T. Koether. Hampden-Sydney College. Wed, Jan 25, 2017

The Traveling Salesman Problem Cheapest-Link Algorithm

Form Validation. Lecture 25. Robb T. Koether. Hampden-Sydney College. Wed, Mar 23, 2018

Array Lists. Lecture 15. Robb T. Koether. Hampden-Sydney College. Fri, Feb 16, 2018

Dynamic Allocation of Memory

The x86 Architecture

Introduction to Databases

The x86 Instruction Set

Yet More CFLs; Turing Machines. CS154 Chris Pollett Mar 8, 2006.

The Mesh Class. Lecture 26. Robb T. Koether. Wed, Oct 28, Hampden-Sydney College

Inheritance: The Fundamental Functions

Insertions, Deletions, and Updates

List Iterators. Lecture 27 Section Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015

Integer Overflow. Lecture 8 Section 2.5. Robb T. Koether. Hampden-Sydney College. Mon, Jan 27, 2014

Shading Triangles. Lecture 37. Robb T. Koether. Hampden-Sydney College. Mon, Nov 30, 2015

The CYK Algorithm. We present now an algorithm to decide if w L(G), assuming G to be in Chomsky Normal Form.

The Class Construct Part 2

Basic PHP Lecture 17

Compiler Construction

jquery Lecture 34 Robb T. Koether Wed, Apr 10, 2013 Hampden-Sydney College Robb T. Koether (Hampden-Sydney College) jquery Wed, Apr 10, / 29

The Constructors. Lecture 7 Sections Robb T. Koether. Hampden-Sydney College. Wed, Feb 1, 2017

Basic CSS Lecture 17

AJAX. Lecture 26. Robb T. Koether. Fri, Mar 21, Hampden-Sydney College. Robb T. Koether (Hampden-Sydney College) AJAX Fri, Mar 21, / 16

Transcription:

The CYK Parsing Algorithm Lecture 19 Section 6.3 Robb T. Koether Hampden-Sydney College Fri, Oct 7, 2016 Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 1 / 21

1 The Membership Problem for CFGs 2 The CYK Parsing Algorithm 3 Assignment Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 2 / 21

Outline 1 The Membership Problem for CFGs 2 The CYK Parsing Algorithm 3 Assignment Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 3 / 21

The Membership Problem for CFGs Definition (The Membership Problem for CFGs) Given a context-free language L and a word w, is w in L(G)? We may assume that G is in Chomsky Normal Form. Let n be the length of the word w. Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 4 / 21

The Membership Problem for CFGs An unsophisticated, brute-force algorithm will examine every possible derivation of length 2n 1 (actually n 1). If none of these produces w, then w / L(G). There problem is, the number of such derivations may grow exponentially in n. (Why?) We need a better algorithm. Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 5 / 21

Parsing Definition (To parse) Given a grammar G and a string W, to parse w is to find a derivation of w in G. There are many different parsing algorithms for context-free grammars. As usual, the more powerful parsing algorithms are more complex. We will examine a relatively simple algorithm developed by Cocke, Younger, and Kasami, known as the CYK algorithm, which runs in polynomial time. Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 6 / 21

Outline 1 The Membership Problem for CFGs 2 The CYK Parsing Algorithm 3 Assignment Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 7 / 21

The CYK Parsing Algorithm The strategy of the CYK algorithm is to begin with all one-symbol substrings of w that are derivable from G. These come directly from the rules of the form A a. Then proceed inductively. Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 8 / 21

The CYK Parsing Algorithm Let w = a 1 a 2 a 3 a n. Let w ij = a i a j, for all 1 i j n. Define sets For example, V 11 = {A V A a 1 }. V 35 = {A V A a 3 a 4 a 5 }. V 1n = {A V A w}. V ij = {A V A w ij }. Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 9 / 21

The CYK Parsing Algorithm The asic Step Initialize each V ii to the set of all variables A for which there is a rule A a i. Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 10 / 21

The CYK Parsing Algorithm The Inductive Step For i < j, compute V ij = {A V A C and V ik and C V k+1,j }. i k<j That is, a i a k and C a k+1 a j, so A C a i a j. Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 11 / 21

Example (The CYK Parsing Algorithm) Let the grammer G be S SAS baa A as Sb ab λ Let w = ababaa. Is w L(G)? Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 12 / 21

Example (The CYK Parsing Algorithm) The grammar converted to CNF is S SD CE SS C A S SC C a C b D AS E A Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 13 / 21

The CYK Parsing Algorithm Example (The CYK Parsing Algorithm) The CYK algorithm is much easier to perform if we use an n n table. The entry in row i, column j is the set V ij. We begin by initializing the diagonal elements (i, i) and then proceed inductively to the right. Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 14 / 21

Example (The CYK Parsing Algorithm) C C Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 15 / 21

Example (The CYK Parsing Algorithm) A C S A C S Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 15 / 21

Example (The CYK Parsing Algorithm) A A, E C S A A A, E C S Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 15 / 21

Example (The CYK Parsing Algorithm) A A, E C S A S, E A A, E E C S Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 15 / 21

Example (The CYK Parsing Algorithm) A A, E A, D C S A S, E S A A, E E C S Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 15 / 21

Example (The CYK Parsing Algorithm) A A, E A, D A, E C S A S, E S A A, E E C S Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 15 / 21

Example (The CYK Parsing Algorithm) ecause S / V 1,6, ababaa / L(G) Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 16 / 21

Example (The CYK Parsing Algorithm) ecause S / V 1,6, ababaa / L(G) Now perform the algorithm for w = babaaba Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 16 / 21

Example (The CYK Algorithm) C C C Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 17 / 21

Example (The CYK Algorithm) C S A C S A C S Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 17 / 21

Example (The CYK Algorithm) C S A A A, E C S A A, E C S Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 17 / 21

Example (The CYK Algorithm) C S A S, E A A, E E C S A A, E C S Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 17 / 21

Example (The CYK Algorithm) C S A S, E S A A, E E C S A A, E C S Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 17 / 21

Example (The CYK Algorithm) C S A S, E S A A A, E E C S A A, E C S Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 17 / 21

Example (The CYK Algorithm) C S A S, E S A S, E A A, E E C S A A, E C S Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 17 / 21

Example (The CYK Parsing Algorithm) ecause S V 1,7, babaaba L(G) Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 18 / 21

Example (The CYK Parsing Algorithm) Let the grammer G be E E + E E E (E) a b Use the CYK algorithm to show that a(+b c) / L(G). Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 19 / 21

Outline 1 The Membership Problem for CFGs 2 The CYK Parsing Algorithm 3 Assignment Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 20 / 21

Collected To be collected on Wed, Oct 12: Section 4.2 Exercises 14, 18. Section 4.3 Exercise 2, 5c. Section 5.1 Exercise 12b, 23. Section 6.1 Exercise 10. Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 21 / 21

Outline 1 The Membership Problem for CFGs 2 The CYK Parsing Algorithm 3 Assignment Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 22 / 21

Assignment Assignment Section 6.3 Exercises 1, 4. Robb T. Koether (Hampden-Sydney College) The CYK Parsing Algorithm Fri, Oct 7, 2016 23 / 21