earley parsing in prolog - english linguistics · earley parsing in prolog. self-modifying programs...

63
Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Earley Parsing in Prolog Aleksandar L. Dimitrov Universit¨ at T¨ ubingen December 19, 2007 Aleksandar L. Dimitrov Universit¨ at T¨ ubingen Earley Parsing in Prolog

Upload: others

Post on 04-May-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Earley Parsing in Prolog

Aleksandar L. Dimitrov

Universitat Tubingen

December 19, 2007

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 2: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Outline

1 Self-modifying Programs in PrologModifying PredicatesChart-Parsing

2 Earley’s AlgorithmShort Recap

3 Implementation

4 AppendixAppendix A: Empty Determiner

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 3: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Modifying Predicates

Use of assert

Can Prolog have only store a limited set of predicates?

So far: Predicates from Source filesNew: Predicates dynamically generated from

User inputCreative use of existing predicates

. . . resulting in Self-Modifying Programs

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 4: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Modifying Predicates

Use of assert

Can Prolog have only store a limited set of predicates?

So far: Predicates from Source files

New: Predicates dynamically generated from

User inputCreative use of existing predicates

. . . resulting in Self-Modifying Programs

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 5: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Modifying Predicates

Use of assert

Can Prolog have only store a limited set of predicates?

So far: Predicates from Source filesNew: Predicates dynamically generated from

User inputCreative use of existing predicates

. . . resulting in Self-Modifying Programs

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 6: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Modifying Predicates

Use of assert

Can Prolog have only store a limited set of predicates?

So far: Predicates from Source filesNew: Predicates dynamically generated from

User inputCreative use of existing predicates

. . . resulting in Self-Modifying Programs

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 7: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Modifying Predicates

Use of assert

Can Prolog have only store a limited set of predicates?

So far: Predicates from Source filesNew: Predicates dynamically generated from

User inputCreative use of existing predicates

. . . resulting in Self-Modifying Programs

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 8: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Modifying Predicates

Use of assert, contd.

Are you only allowed to add to existing predicates?

Workaround: use of unknown/2

How flexible is your Database?

→ use of abolish/1, retract/1

Watch out for unification!

Use assertz/1 and asserta/1

. . . also for efficiency reasons

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 9: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Modifying Predicates

Use of assert, contd.

Are you only allowed to add to existing predicates?

Workaround: use of unknown/2

How flexible is your Database?

→ use of abolish/1, retract/1

Watch out for unification!

Use assertz/1 and asserta/1

. . . also for efficiency reasons

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 10: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Modifying Predicates

Use of assert, contd.

Are you only allowed to add to existing predicates?

Workaround: use of unknown/2

How flexible is your Database?

→ use of abolish/1, retract/1

Watch out for unification!

Use assertz/1 and asserta/1

. . . also for efficiency reasons

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 11: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Modifying Predicates

Use of assert, contd.

Are you only allowed to add to existing predicates?

Workaround: use of unknown/2

How flexible is your Database?

→ use of abolish/1, retract/1

Watch out for unification!

Use assertz/1 and asserta/1

. . . also for efficiency reasons

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 12: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Modifying Predicates

Use of assert, contd.

Are you only allowed to add to existing predicates?

Workaround: use of unknown/2

How flexible is your Database?

→ use of abolish/1, retract/1

Watch out for unification!

Use assertz/1 and asserta/1

. . . also for efficiency reasons

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 13: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Modifying Predicates

Use of assert, contd.

Are you only allowed to add to existing predicates?

Workaround: use of unknown/2

How flexible is your Database?

→ use of abolish/1, retract/1

Watch out for unification!

Use assertz/1 and asserta/1

. . . also for efficiency reasons

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 14: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Modifying Predicates

Use of assert, contd.

Are you only allowed to add to existing predicates?

Workaround: use of unknown/2

How flexible is your Database?

→ use of abolish/1, retract/1

Watch out for unification!

Use assertz/1 and asserta/1

. . . also for efficiency reasons

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 15: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Chart-Parsing

Chart Parsing with Prolog

Chart Parsers operate entirely on their chart

Why Chart Parsing?

Imagine a grammar:A -> BC(D)

Input: BCD

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 16: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Chart-Parsing

Chart Parsing with Prolog

Chart Parsers operate entirely on their chart

Why Chart Parsing?

Imagine a grammar:A -> BC(D)

Input: BCD

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 17: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Chart-Parsing

Chart Parsing with Prolog

Chart Parsers operate entirely on their chart

Why Chart Parsing?

Imagine a grammar:A -> BC(D)

Input: BCD

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 18: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Chart-Parsing

Chart Parsing with Prolog

Chart Parsers operate entirely on their chart

Why Chart Parsing?

Imagine a grammar:A -> BC(D)

Input: BCD

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 19: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Chart-Parsing

Chart Parsing with Prolog

Chart Parsers operate entirely on their chart

Why Chart Parsing?

Imagine a grammar:A -> BC(D)

Input: BCD

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 20: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Chart-Parsing

Minimalistic Example

Grammar:A -> BCA -> BCDInput: BCD A

B C

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 21: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Chart-Parsing

Minimalistic Example

Grammar:A -> BCA -> BCDInput: BCD A

B C D

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 22: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Chart-Parsing

Minimalistic Example

Grammar:A -> BCA -> BCDInput: BCD A

B C D→ Solution: Dynamic Programming

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 23: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Chart-Parsing

Use of assert in this context

Our original TD parser:parse(C,[Word|S],S) :-word(C,Word).

parse(C,S1,S) :-rule(C,Cs),parselist(Cs,S1,S).

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 24: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Chart-Parsing

Use of assert in this context

Our new TD chart parser:parse(C,[Word|S],S) :-word(C,Word).

parse(C,S1,S) :- chart(C,S1,S).

parse(C,S1,S) :-rule(C,Cs),parselist(Cs,S1,S),asserta(chart(C,S1,S)).

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 25: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Earley’s Algorithm

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 26: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

Short Recap

Earley is a Chart Parser

The chart is consulted and modified by three maincomponents:

The Predictor (Top-Down element)The ScannerThe Completer (Bottum-Up elment)

Let’s see an example...

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 27: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

Short Recap

Earley is a Chart Parser

The chart is consulted and modified by three maincomponents:

The Predictor (Top-Down element)

The ScannerThe Completer (Bottum-Up elment)

Let’s see an example...

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 28: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

Short Recap

Earley is a Chart Parser

The chart is consulted and modified by three maincomponents:

The Predictor (Top-Down element)The Scanner

The Completer (Bottum-Up elment)

Let’s see an example...

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 29: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

Short Recap

Earley is a Chart Parser

The chart is consulted and modified by three maincomponents:

The Predictor (Top-Down element)The ScannerThe Completer (Bottum-Up elment)

Let’s see an example...

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 30: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

Short Recap

Earley is a Chart Parser

The chart is consulted and modified by three maincomponents:

The Predictor (Top-Down element)The ScannerThe Completer (Bottum-Up elment)

Let’s see an example...

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 31: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict:

S → NP VP

Predict: NP → D N

Scan: Accept the

Complete: Nothing. Why?

Predict: Nothing. Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 32: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan: Accept the

Complete: Nothing. Why?

Predict: Nothing. Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 33: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict:

NP → D N

Scan: Accept the

Complete: Nothing. Why?

Predict: Nothing. Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 34: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan: Accept the

Complete: Nothing. Why?

Predict: Nothing. Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 35: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan:

Accept the

Complete: Nothing. Why?

Predict: Nothing. Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 36: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan: Accept the

Complete: Nothing. Why?

Predict: Nothing. Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 37: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan: Accept the

Complete:

Nothing. Why?

Predict: Nothing. Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 38: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan: Accept the

Complete: Nothing.

Why?

Predict: Nothing. Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 39: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan: Accept the

Complete: Nothing. Why?

Predict: Nothing. Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 40: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan: Accept the

Complete: Nothing. Why?

Predict:

Nothing. Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 41: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan: Accept the

Complete: Nothing. Why?

Predict: Nothing.

Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 42: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan: Accept the

Complete: Nothing. Why?

Predict: Nothing. Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 43: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan: Accept the

Complete: Nothing. Why?

Predict: Nothing. Why?

Scan:

Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 44: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan: Accept the

Complete: Nothing. Why?

Predict: Nothing. Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 45: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan: Accept the

Complete: Nothing. Why?

Predict: Nothing. Why?

Scan: Accept dog

Complete:

Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 46: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan: Accept the

Complete: Nothing. Why?

Predict: Nothing. Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 47: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan: Accept the

Complete: Nothing. Why?

Predict: Nothing. Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 48: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Short Recap

A Short Example

The dog chases the cat

Predict: S → NP VP

Predict: NP → D N

Scan: Accept the

Complete: Nothing. Why?

Predict: Nothing. Why?

Scan: Accept dog

Complete: Complete NP

etc. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 49: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

The Outer Predicates

We only need to modify parse sligthly

. . . and introduce process which is just a wrapper aroundthe three magicians. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 50: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

The Outer Predicates

We only need to modify parse sligthly

. . . and introduce process which is just a wrapper aroundthe three magicians. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 51: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

The Outer Predicates

We only need to modify parse sligthly

. . . and introduce process which is just a wrapper aroundthe three magicians. . .

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 52: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

The three Magicians

. . . make an exhaustive search on their current domain

. . . store everything they find on the main chart

. . . but first operate on what they found themselves(asserta)

All of them rely on store/3

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 53: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

The three Magicians

. . . make an exhaustive search on their current domain

. . . store everything they find on the main chart

. . . but first operate on what they found themselves(asserta)

All of them rely on store/3

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 54: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

The three Magicians

. . . make an exhaustive search on their current domain

. . . store everything they find on the main chart

. . . but first operate on what they found themselves

(asserta)

All of them rely on store/3

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 55: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

The three Magicians

. . . make an exhaustive search on their current domain

. . . store everything they find on the main chart

. . . but first operate on what they found themselves(asserta)

All of them rely on store/3

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 56: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

The store predicate

Consider NP → NP Conj NP

How does Earley avoid left recursion?

store doesn’t store anything that’s already there!

But how do we parse recursive structures such as The dog andthe cat and the elephant?

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 57: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

The store predicate

Consider NP → NP Conj NP

How does Earley avoid left recursion?

store doesn’t store anything that’s already there!

But how do we parse recursive structures such as The dog andthe cat and the elephant?

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 58: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

The store predicate

Consider NP → NP Conj NP

How does Earley avoid left recursion?

store doesn’t store anything that’s already there!

But how do we parse recursive structures such as The dog andthe cat and the elephant?

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 59: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Appendix A: Empty Determiner

What do we do about empty determiners?

What about them?

We could: modify the predictor

Or recast D → ∅ as word and modify the scanner

Method 1: modifying the predictor. . .

What about Method 2?

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 60: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Appendix A: Empty Determiner

What do we do about empty determiners?

What about them?

We could: modify the predictor

Or recast D → ∅ as word and modify the scanner

Method 1: modifying the predictor. . .

What about Method 2?

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 61: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Appendix A: Empty Determiner

What do we do about empty determiners?

What about them?

We could: modify the predictor

Or recast D → ∅ as word and modify the scanner

Method 1: modifying the predictor. . .

What about Method 2?

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 62: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Appendix A: Empty Determiner

What do we do about empty determiners?

What about them?

We could: modify the predictor

Or recast D → ∅ as word and modify the scanner

Method 1: modifying the predictor. . .

What about Method 2?

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog

Page 63: Earley Parsing in Prolog - English Linguistics · Earley Parsing in Prolog. Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix Modifying Predicates Use

Self-modifying Programs in Prolog Earley’s Algorithm Implementation Appendix

Appendix A: Empty Determiner

What do we do about empty determiners?

What about them?

We could: modify the predictor

Or recast D → ∅ as word and modify the scanner

Method 1: modifying the predictor. . .

What about Method 2?

Aleksandar L. Dimitrov Universitat Tubingen

Earley Parsing in Prolog