CHR as grammar formalism A first report Henning Christiansen Roskilde University, D ENMARK Idea: Propagation rules of CHR:

Slides:



Advertisements
Similar presentations
Application: Yacc A parser generator A context-free grammar An LR parser Yacc Yacc input file:... definitions... %... production rules... %... user-defined.
Advertisements

Computer Science CPSC 322 Lecture 25 Top Down Proof Procedure (Ch 5.2.2)
CPSC Compiler Tutorial 4 Midterm Review. Deterministic Finite Automata (DFA) Q: finite set of states Σ: finite set of “letters” (input alphabet)
CHAPTER 13 Inference Techniques. Reasoning in Artificial Intelligence n Knowledge must be processed (reasoned with) n Computer program accesses knowledge.
Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
Methods of Proof Chapter 7, second half.. Proof methods Proof methods divide into (roughly) two kinds: Application of inference rules: Legitimate (sound)
Methods of Proof Chapter 7, Part II. Proof methods Proof methods divide into (roughly) two kinds: Application of inference rules: Legitimate (sound) generation.
Propositional Logic Reading: C , C Logic: Outline Propositional Logic Inference in Propositional Logic First-order logic.
Grammars, Languages and Parse Trees. Language Let V be an alphabet or vocabulary V* is set of all strings over V A language L is a subset of V*, i.e.,
For Monday Read Chapter 23, sections 3-4 Homework –Chapter 23, exercises 1, 6, 14, 19 –Do them in order. Do NOT read ahead.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
Context-Free Grammars Lecture 7
Methods of Proof Chapter 7, second half.
ISBN Chapter 4 Lexical and Syntax Analysis The Parsing Problem Recursive-Descent Parsing.
Search in the semantic domain. Some definitions atomic formula: smallest formula possible (no sub- formulas) literal: atomic formula or negation of an.
Last time Proof-system search ( ` ) Interpretation search ( ² ) Quantifiers Equality Decision procedures Induction Cross-cutting aspectsMain search strategy.
Parsing — Part II (Ambiguity, Top-down parsing, Left-recursion Removal)
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
CPSC Compiler Tutorial 3 Parser. Parsing The syntax of most programming languages can be specified by a Context-free Grammar (CGF) Parsing: Given.
CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Context-Free Grammars and Parsing 1.
8/19/2015© Hal Perkins & UW CSEC-1 CSE P 501 – Compilers Parsing & Context-Free Grammars Hal Perkins Winter 2008.
Grammars and Parsing. Sentence  Noun Verb Noun Noun  boys Noun  girls Noun  dogs Verb  like Verb  see Grammars Grammar: set of rules for generating.
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
For Friday Finish chapter 23 Homework: –Chapter 22, exercise 9.
1 Chapter 5 LL (1) Grammars and Parsers. 2 Naming of parsing techniques The way to parse token sequence L: Leftmost R: Righmost Top-down  LL Bottom-up.
Scientific writing style Exact  Word choice: make certain that every word means exactly what you want to express. Choose synonyms with care. Be not.
10/13/2015IT 3271 Tow kinds of predictive parsers: Bottom-Up: The syntax tree is built up from the leaves Example: LR(1) parser Top-Down The syntax tree.
Syntax Analysis The recognition problem: given a grammar G and a string w, is w  L(G)? The parsing problem: if G is a grammar and w  L(G), how can w.
Introduction to Parsing Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
CS Describing Syntax CS 3360 Spring 2012 Sec Adapted from Addison Wesley’s lecture notes (Copyright © 2004 Pearson Addison Wesley)
PART I: overview material
Profs. Necula CS 164 Lecture Top-Down Parsing ICOM 4036 Lecture 5.
Lesson 3 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
May 2006CLINT-LN Parsing1 Computational Linguistics Introduction Parsing with Context Free Grammars.
ISBN Chapter 3 Describing Syntax and Semantics.
Lexical and Syntax Analysis
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
Formal Semantics Chapter Twenty-ThreeModern Programming Languages, 2nd ed.1.
Slide 1 Propositional Definite Clause Logic: Syntax, Semantics and Bottom-up Proofs Jim Little UBC CS 322 – CSP October 20, 2014.
Top Down Parsing - Part I Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
Rules, Movement, Ambiguity
Basic Parsing Algorithms: Earley Parser and Left Corner Parsing
Top-down Parsing. 2 Parsing Techniques Top-down parsers (LL(1), recursive descent) Start at the root of the parse tree and grow toward leaves Pick a production.
CMSC 330: Organization of Programming Languages Operational Semantics a.k.a. “WTF is Project 4, Part 3?”
Top-Down Parsing.
Types and Programming Languages
1 Introduction to Parsing. 2 Outline l Regular languages revisited l Parser overview Context-free grammars (CFG ’ s) l Derivations.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
CMSC 330: Organization of Programming Languages Operational Semantics.
COMP 3438 – Part II-Lecture 5 Syntax Analysis II Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
UMBC  CSEE   1 Chapter 4 Chapter 4 (b) parsing.
Formal grammars A formal grammar is a system for defining the syntax of a language by specifying sequences of symbols or sentences that are considered.
CMSC 330: Organization of Programming Languages Pushdown Automata Parsing.
Introduction to Parsing
Comp 411 Principles of Programming Languages Lecture 3 Parsing
Grammars and Parsing.
Parsing & Context-Free Grammars
Introduction to Parsing (adapted from CS 164 at Berkeley)
Knowledge Representation
Parsing & Context-Free Grammars Hal Perkins Autumn 2011
Lexical and Syntax Analysis
(Slides copied liberally from Ruth Anderson, Hal Perkins and others)
Lecture 7: Introduction to Parsing (Syntax Analysis)
Introduction to Parsing
Parsing & Context-Free Grammars Hal Perkins Summer 2004
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Parsing & Context-Free Grammars Hal Perkins Autumn 2005
Presentation transcript:

CHR as grammar formalism A first report Henning Christiansen Roskilde University, D ENMARK Idea: Propagation rules of CHR: a natural bottom evaluator A bottom-up analogy to Definite Clause Grammars... and see what else CHR can offer to language processing

Example: ”Peter likes Mary” np(N0,N1), verb(N1,N2), np(N2,N3) ==> sentence(N0,N3). token(peter,N0,N1) ==> np(N0,N1). token(mary, N0,N1) ==> np(N0,N1). token(likes,N0,N1) ==> verb(N0,N1). token(peter,0,1) token(likes,1,2) token(mary,2,3) sentence(0,3) / | \ np(0,1) verb(1,2) np(2,3) / | \

Example: ”Peter likes Mary” np(N0,N1), verb(N1,N2), np(N2,N3) ==> sentence(N0,N3). token(peter,N0,N1) ==> np(N0,N1). token(mary, N0,N1) ==> np(N0,N1). token(likes,N0,N1) ==> verb(N0,N1). Principle obviously correct for grammars without empty productions and loops Robust of errors Attributes can be added as in DCG (of course) Ambiguity not a problem Naive, elegant, but is it useful??

A few facts about CHR Declarative language for writing constraint solvers [Frühwirth, 1995] Propagation rules adds:... ==>... Simplification rules replaces: variations and misc. tools Recognized as general purpose logic programming language, e.g.: [Abdennadher, Schütz, 1998]: Combine bottom-up & top-down [Abdennadher, Christiansen, 2000]: ”Natural embedding” of abduction and integrity constraints This talk: Exercises using CHR for language processing

Time complexity of prop. rule parsers No backtrack => no combinat. explosion in case of errors n 3 for Chomsky Normal Form grammars [McAllester, 2000; Cocke-Younger-Kasami...] ; in general worse Special problem: local ambiguity => large amount of (perhaps) useless constraints (e.g. A::= a | A A) Several ways to get rid of n 3....

Improving time complexity Example: (grammar for arithmetic expressions) exp(N0,N1),token(+,N1,N2),exp(N2,N3) ==> exp(N0,N3).

Improving time complexity Make all but rightmost symbol passive exp(N0,N1)#Id1, token(+,N1,N2)#Id2, exp(N2,N3) ==> exp(N0,N3), pragma passive(Id1), passive(Id2).

Improving time complexity Make all but rightmost symbol passive Use look-ahead exp(N0,N1)#Id1,token(+,N1,N2)#Id2,exp(N2,N3)#Id3, token(R,N3,N4) ==> member(R,[+,')',eof]) | exp(N0,N3), pragma passive(Id1), passive(Id2), passive(Id3).

Improving time complexity Make all but rightmost symbol passive Use look-ahead Use simplification/simpagation rules instead token(R,N3,N4) \ exp(N0,N1)#Id1,token(+,N1,N2)#Id2,exp(N2,N3)#Id3 member(R,[+,')',eof]) | exp(N0,N3), pragma passive(Id1), passive(Id2), passive(Id3).

Improving time complexity Make all but rightmost symbol passive Use look-ahead Use simplification/simpagation rules instead

Improving time complexity Make all but rightmost symbol passive –does not change grammar; can be added even without grammar-writer’s attention Use look-ahead –as above Use simplification/simpagation rules instead –does not change unambigous grammars –a feature to enforce unambiguity Time complexity not a problem! ”Reasonable” grammars run almost linearly A variety of tools available for the competent CHR grammar writer

Fact: CHR perfect tool for passing round hypothesis Example: produce:... ==>... h(X)... apply:... h(X)... ==>... X... Let’s try Assumption Grammars [Dahl, Tarau, Li, 1997] anaphora, coordination, etc.

Assumption Grammars +h(a)assert linear hypothesis h(a) for subsequent text *h(a)assert ”intuitionistic” hypothesis for subsequent text -h(X)consume/apply hypothesis =+h(a), =*h(X), =-h(X) as above but free-order (NB: syntax changed slightly compared with [Dahl, Tarau, Li, 1997])

Assumption Grammars in CHR Represent=+h(a) as =+(h,[a]), etc. +h(a) as +(h,[a], position ), etc. Implement by following CHR rules: =+(P,A), =-(P,B) true & A=B | true. =*(P,A) \ =-(P,B) true & A=B | true. +(P,A,Z1), -(P,B,Z2) Z1 < Z2 & A=B | true. *(P,A,Z1)\ -(P,B,Z2) Z1 < Z2 & A=B | true. Problem with commit- ment and ambiguity So assume no ambiguity for the moment

Example: Anaphora, ”Peter... he...” token(he,N0,N1) pronoun(masc,N0,N1). pronoun(Gender,N0,N1) -(active_individual,[X,Gender],N0), np(X,Gender,N0,N1). token(peter,N0,N1) proper_name(peter,masc,N0,N1). proper_name(X,Gender,N0,N1) *(active_individual,[X,Gender],N0), np(X,Gender,N0,N1).

Example: Coordination (adapted from[Dahl, Tarau, Li, 1997]) ”Mary likes and Martha hates Peter” Rule for sentence asking around for a subject token(and,N3,N4) \ np(Sub,N1,N2), verb(V,N2,N3) =-(ref_object,[Obj]), sent(V*(Sub,Obj),N1,N3). The following rule instance applied for sample sentence =+( ref_object,[peter]), =-( ref_object,[ Obj] ) true & [peter]= [Obj] | true. Rule sentence offering its objects to context sent(S1,N1,N2), token(and,N2,N3), sent(V2*(Sub2,Obj2),N3,N4) =+(ref_object,[Obj2]), sent(S1+V2*(Sub2,Obj2),N1,N4).

Problems with Assumption Grammars Better control of scope of hypotheses needed, e.g. ”offered subjects” only in single period Priority of hypothesis, pruning... heuristics, weights, fuzzy? Claim: Can be approached in CHR suggestions for new mechanisms can be implemented in CHR... or simply program add hoc!

Abduction with integrity constraints (sketch) Consider DCG rule: A --> B 1, B 2, B 3, { P } Under suitable conditions equivalent with B 1 (N0,N1), B 2 (N1,N2), B 3 (N1,N3) P, A (N0,N3). Notice: Our implementation of Assumption Gram’s example of abduction with integrity constraints Integrity constraints reject inconsistent hyp. sets, e.g. *(active_individual,[X,masc]), *(active_individual,[X,fem]) fail. fact(likes,X,Y), fact(hates,X,Y) fail.

Problems with abduction + int. constr’s Only one out of several hypotheses chosen Inconsistent choices leads to total failure Attempt to handle ambiguity by propagation rules (==>) will mix up different interpretations of the text Under development: Indexing techniques: Maintain different but shared hypotheses sets in same constraint store Replace ”... fail ” by ”... vanish( index ) ” Our point here: These problems can be approached in CHR!!

Problems shared with ”logical” approaches: n m different choices in: Peter 1, Peter 2,..., Peter n... he 1,..., he m Lack of heuristics, scoping, weights... ( as mentioned) Our point: such problems can be approached in general CHR programming framework

Conclusion Current work: Indexing and sharing techniques Recognition of NPs for ontology-based search in text DBs; in parallel with ”trad’l approach” in the OntoQuery project Adapt grammar for large subset of Danish; with CST, Copenhagen, also in OntoQuery... and fun to play with too! Simple, naive and neat approach Efficient and robust b.u. parsers Potentiality for powerful and flexible natural language processing methods Suggestive application of declarative constraint programming