DEFINITE CLAUSE GRAMMARS Ivan Bratko University of Ljubljana Faculty of Computer and Information Sc.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

Simply Logical – Chapter 7© Peter Flach, 2000 Context-free grammar sentence--> noun_phrase,verb_phrase. noun_phrase--> proper_noun. noun_phrase--> article,adjective,noun.
Prolog programming....Dr.Yasser Nada. Chapter 8 Parsing in Prolog Taif University Fall 2010 Dr. Yasser Ahmed nada prolog programming....Dr.Yasser Nada.
October 2004CSA4050: Semantics III1 CSA4050: Advanced Topics in NLP Semantics III Quantified Sentences.
Natural Language Processing Lecture 2: Semantics.
November 2008NLP1 Natural Language Processing Definite Clause Grammars.
CSA2050: DCG I1 CSA2050 Introduction to Computational Linguistics Lecture 8 Definite Clause Grammars.
Logic Programming – Part 2 Lists Backtracking Optimization (via the cut operator) Meta-Circular Interpreters.
Cs7120 (Prasad)L21-DCG1 Definite Clause Grammars
07/05/2005CSA2050: DCG31 CSA2050 Introduction to Computational Linguistics Lecture DCG3 Handling Subcategorisation Handling Relative Clauses.
CSA4050: Advanced Topics in NLP Semantics IV Partial Execution Proper Noun Adjective.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Prolog COMP 112 #
Syntax. Definition: a set of rules that govern how words are combined to form longer strings of meaning meaning like sentences.
CSA2050: DCG IV1 CSA2050: Definite Clause Grammars IV Handling Gaps II Semantic Issues.
1 Grammars and Parsing Allen ’ s Chapters 3, Jurafski & Martin ’ s Chapters 8-9.
Statistical NLP: Lecture 3
01/11/04 AIPP Lecture 11: Parsing and Semantics in DCGs1 Parsing and Semantics in DCGs Artificial Intelligence Programming in Prolog Lecturer: Tim Smith.
1 CS 385 Fall 2006 Chapter 14 Understanding Natural Language Problems.
Grammars.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.
Parsing: Features & ATN & Prolog By
LING 364: Introduction to Formal Semantics Lecture 4 January 24th.
 Christel Kemke 2007/08 COMP 4060 Natural Language Processing Feature Structures and Unification.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 7: Definite Clause Grammars Theory –Introduce context free grammars and some related concepts.
A modern approach input sentence syntax analysis (parsing) semantic analysis pragmatic analysis target representation grammar lexicon semantic rules contextual.
1 Understanding Natural Language The Natural Language Understanding Problem 14.1Deconstructing Language: A Symbolic Analysis 14.2Syntax 14.3Syntax.
Chapter 3: Formal Translation Models
Natural Language Processing AI - Weeks 19 Natural Language Processing PART 2 Lee McCluskey, room 2/07
EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 2 Tutorials Revision of formalisation Interpreting logical statements in NL Form and Content of an Argument.
LING 364: Introduction to Formal Semantics Lecture 5 January 26th.
LING 388: Language and Computers Sandiway Fong Lecture 13: 10/10.
LING 388 Language and Computers Lecture 12 10/9/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong 10/4 Lecture 12.
11 CS 388: Natural Language Processing: Syntactic Parsing Raymond J. Mooney University of Texas at Austin.
October 2004csa4050: Semantics II1 CSA4050: Advanced Topics in NLP Semantics II The Lambda Calculus Semantic Representation Encoding in Prolog.
Computing Science, University of Aberdeen1 CS4025: Grammars l Grammars for English l Features l Definite Clause Grammars See J&M Chapter 9 in 1 st ed,
Prolog and grammars Prolog’s execution strategy is useful for writing parsers for natural language (eg. English) and programming languages (interpreters.
Grammars.
ICS611 Introduction to Compilers Set 1. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
1 CS 385 Fall 2006 Chapter 14 Understanding Natural Language (omit 14.4)
For Friday Finish chapter 23 Homework: –Chapter 22, exercise 9.
LING 388: Language and Computers Sandiway Fong Lecture 7.
October 2004CSA4050: Semantics III1 CSA4050: Advanced Topics in NLP Semantics III Quantified Sentences.
Parsing. Language A set of strings from an alphabet which may be empty, finite or infinite. A language is defined by a grammar and we may also say that.
Syntax Why is the structure of language (syntax) important? How do we represent syntax? What does an example grammar for English look like? What strategies.
Artificial Intelligence: Natural Language
Linguistic Essentials
Semantically Processing The Semantic Web Presented by: Kunal Patel Dr. Gopal Gupta UNIVERSITY OF TEXAS AT DALLAS.
Semantic Construction lecture 2. Semantic Construction Is there a systematic way of constructing semantic representation from a sentence of English? This.
1 Definite Clause Grammars for Language Analysis – A Survey of the Formalism and a Comparison with Augmented Transition Networks 인공지능 연구실 Hee keun Heo.
Artificial Intelligence: Natural Language
The man bites the dog man bites the dog bites the dog the dog dog Parse Tree NP A N the man bites the dog V N NP S VP A 1. Sentence  noun-phrase verb-phrase.
Section 11.3 Features structures in the Grammar ─ Jin Wang.
Computing Science, University of Aberdeen1 CS4025: Grammars l Grammars for English l Features l Definite Clause Grammars See J&M Chapter 9 in 1 st ed,
Parsing and Code Generation Set 24. Parser Construction Most of the work involved in constructing a parser is carried out automatically by a program,
GRAMMARS & PARSING. Parser Construction Most of the work involved in constructing a parser is carried out automatically by a program, referred to as a.
Natural Language Processing (NLP)
NATURAL LANGUAGE PROCESSING
Natural Language Processing (NLP)
Statistical NLP: Lecture 3
Natural Language Processing
LING/C SC/PSYC 438/538 Lecture 21 Sandiway Fong.
CKY Parser 0Book 1 the 2 flight 3 through 4 Houston5 11/16/2018
CS 388: Natural Language Processing: Syntactic Parsing
Linguistic Essentials
A User study on Conversational Software
CSA4050: Advanced Topics in NLP
Natural Language Processing (NLP)
Lecture 7: Definite Clause Grammars
Artificial Intelligence 2004 Speech & Natural Language Processing
Presentation transcript:

DEFINITE CLAUSE GRAMMARS Ivan Bratko University of Ljubljana Faculty of Computer and Information Sc.

DCG = Definite Clause Grammar DCG notation in Prolog Context-free grammars in DCG Introducing context-dependence through arguments Prolog goals in grammars rules Defining semantics with DCG Natural language syntax in DCG Defining meaning of natural language

A BNF grammar ::= a b | a b Grammar generates / recognises s a s b Generation Recognition a s b a b Sentence = a a a b b b

COMMAND SEQUENCES FOR A ROBOT up up up down up down CORRESPONDING BNF GRAMMAR ::= | ::= up | down

CORRESPONDING DCG move --> step. move --> step, move. step --> [up]. step --> [down].

SENTENCES IN DCG DCG expects a sentence to be represented as difference list aabb ~ [a,a,b,b], [] ~ [a,a,b,b,c], [c] ~ [a,a,b,b,x,y,z], [x,y,z] ~...

QUESTIONS TO DCG ?- move( [up,down,up], []). yes ?- move( [up, X, up], []). X = up; X = down; no ?- move( [ up, down, up, a, b, c], [ a, b, c]). yes

PROLOG CONVERTS DCG INTO A RECOGNITION PROGRAM move( List, Rest) :- step( List, Rest). move( List1, Rest) :- step( List1, List2), move( List2, Rest). step( [up | Rest], Rest). step( [down | Rest], Rest).

FROM DCG TO STANDARD PROLOG DCG rule: move --> step, move. Corresponding Prolog rule: move( List1, Rest) :- step( List1, List2), move( List2, Rest).

move( List1, Rest) :- step( List1, List2), move( List2, Rest). move step move Rest List2 List1 FROM DCG TO STANDARD PROLOG

A SIMPLE NATURAL LANGUAGE DCG The cat scares the mouse. det noun verb det noun noun_phrase verb_phrase sentence

A SIMPLE NATURAL LANGUAGE DCG sentence --> noun_phrase, verb_phrase. verb_phrase --> verb, noun_phrase. noun_phrase --> determiner, noun. determiner --> [ the]. noun --> [ cat]. noun --> [ cats]. noun --> [ mouse]. verb --> [ scares]. verb --> [ scare].

THIS GRAMMAR GENERATES [ the, cat, scares, the, mouse] [ the, mouse, scares, the, mouse] [ the, cats, scare, the, mouse] [ the, cats, scares, the, mouse] CONTEXT DEPENDENT!

NUMBER AGREEMENT CAN BE FORCED BY ARGUMENTS sentence( Number) --> noun_phrase( Number), verb_phrase( Number). verb_phrase( Number) --> verb( Number), noun_phrase( Number1). noun_phrase( Number) --> determiner( Number), noun( Number). noun( singular) --> [ mouse]. noun( plural) --> [ mice]. verb( singular) --> [scares]. verb( plural) --> [scare].

NUMBER AGREEMENT CAN BE FORCED BY ARGUMENTS ?- sentence( Number, [the, cats, scares, the, mouse], []). no ?- sentence( Number, [the, cats, scare, the, mouse], []). Number = plural

CONSTRUCTING PARSE TREES [ up, down, up] move step move up step move down step up

DCG TO CONSTRUCT PARSE TREES Tree = move( step(up), move( step(down),...)) move( move( Step)) --> step( Step). move( move( Step, Move)) --> step( Step), move( Move). step( step( up)) --> [up]. step( step( down)) --> [down].

DEFINING MEANING Define: Meaning of move = Distance travelled meaning ( ‘up up down up’) = = 2 meaning( ‘up up down up’) = meaning( ‘up’) + meaning( ‘up down up’)

FROM PARSE TREE TO MEANING To find meaning of sentence: (1) Construct parse tree (2) Process parse tree

MEANING OF MOVES TREE meaning( move( Step, Move), Dist) :- meaning( Step, D1), meaning( Move, D2), Dist is D1 + D2. meaning( step( up), 1). meaning( step( down), -1).

INTERLEAVING SYNTAX AND MEANING sentence parse tree meaning Avoid parse tree, encode meaning directly in DCG

PROLOG goals in DCG: {Goal} move( Dist) --> step( Dist). move( Dist) --> step( D1), move( D2), {Dist is D1 + D2}. step( 1) --> [ up]. step( -1) --> [ down]. ?- move( D, [ up, up, down, up], [ ] ). D = 2

MEANING OF NATURAL LANGUAGE  Representation of meaning = ?  Depends on use of meaning, e.g. natural language querying  Logic is a good candidate for representing meaning

SOME MEANINGS IN LOGIC Sentence Formalised meaning ``John paints’’ paints( john) ``John likes Annie’’ likes( john, annie)

SOME MEANINGS IN LOGIC Sentence ``A man paints’’ Formalised meaning exists( X, man(X) and paints(X)) Note: ``paints’’ is intransitive verb, ``likes’’ is trans. verb

A SYNTAX sentence ---> noun_phrase, verb_phrase. noun_phrase --> proper_noun. verb_phrase --> intrans_verb. verb_phrase --> trans_verb, noun_phrase. intrans_verb --> [ paints]. trans_verb --> [ likes]. proper_noun --> [ john]....

INCORPORATING MEANING % “john’’ means “john’’ proper_noun( john) --> [ john]. % “paints’’ means “paints( X)’’ intrans_verb( paints( X)) --> [ paints].

COMBINING MEANING OF NOUN PHRASE AND VERB PHRASE “ John paints” sentence noun_phrase verb_phrase proper_noun intrans_verb john paints

COMBINING MEANING OF NOUN PHRASE AND VERB PHRASE paints( john) sentence john noun_phrase verb_phrase paints( X) john proper_noun intrans_verb paints( X) john paints

COMBINING MEANING OF NOUN PHRASE AND VERB PHRASE john + paints( X) = paints( john) Meaning of NP Meaning of sentence Meaning of VP

COMBINING OF MEANING OF VERB PHRASE AND NOUN PHRASE noun_phrase( NP) --> proper_noun( NP). verb_phrase( VP) --> intrans_verb( VP). sentence( S) ---> noun_phrase( NP), verb_phrase( VP), { compose( NP, VP, S) }.

COMPOSING NP AND VP MEANINGS actor( paints( X), X). compose( NP, VP, VP) :- % Meaning of sentence is VP actor( VP, NP). % Where actor in VP is NP ?- compose( john, paints( X), S). S = paints( john)

MORE ELEGANT DEFINE MEANING OF TRANSITIVE VERB SO THAT ACTOR BECOMES EXTRA ARGUMENT intrans_verb( Actor, paints( Actor)) --> [ paints]. verb_phrase( Actor, VP) --> intrans_verb( Actor, VP). sentence( VP) ---> noun_phrase( Actor), verb_phrase( Actor, VP).

This makes “slots” in meaning “visible” paints( Actor) Slot to be filled by context

MEANING OF TRANSITIVE VERBS  “likes” means likes( Somebody, Something) trans_verb( Somebody, Something, likes(Somebody,Something)) --> [ likes]. verb_phrase( Somebody, VP) --> trans_verb( Somebody, Something, VP), noun_phrase( Something).

MEANING OF DETERMINERS “A” AND “EVERY”  “A man paints” means: exists( X, man( X) and paints( X) )  Determiner “a” dictates the meaning of whole sentence!  “a man” means: exists( X, man( X) and Assertion) Statement about X

MEANING OF “A”  “a” means: There is some X such that: X has some property and some assertion holds about X. exists( X, Property and Assertion)  Make X, Property and Assertion visible: determiner( X, Property, Assn, exists( X, Property and Assn)) --> [ a].

INTEGRATING MEANING OF DETERMINERS AND OTHER PHRASES sentence noun_phrase verb_phrase determiner noun intrans_verb a man paints paints(X)man(X)exists( X, P and A) exists( X, man(X) and A) paints(X) exists( X, man(X) and paints(X) )

INTEGRATING MEANING OF DETERMINERS AND OTHER PHRASES sentence( S) --> noun_phrase( X, Assn, S), verb_phrase( X, Assn). noun_phrase( X, Assn, S) --> determiner( X, Prop, Assn, S), noun( X, Prop). noun_phrase( X, Assn, Assn) --> proper_noun( X).

INTEGRATING MEANING OF DETERMINERS AND OTHER PHRASES verb_phrase( X, Assn) --> intrans_verb( X, Assn). determiner( X, Prop, Assn, exists( X, Prop and Assn)) --> [a]. noun( X, man( X)) --> [ man]. intrans_verb( X, paints(X)) --> [paints].

DETERMINER “EVERY” “Every woman dances” means: all( X, woman( X) ==> dances( X) ) determiner( X, Prop, Assn, all( X, Prop ==> Assn ) ) --> [ every].

RELATIVE CLAUSES “Every man that paints admires Monet” SYNTAX: noun_phrase --> determiner, noun, rel_clause. rel_clause --> [ that], verb_phrase. rel_clause --> [ ]. % Empty relative clause

RELATIVE CLAUSES “Every man that paints admires Monet” MEANING: all( X, man( X) and paints( X) ==> admires( X, monet) )

RELATIVE CLAUSES MEANING, GENERAL FORM all( X, Prop1 and Prop2 ==> Assertion ) noun verb phrase verb phrase of rel. clause of sentence

RELATIVE CLAUSES: SYNTAX AND MEANING rel_clause( X, Prop1, Prop1 and Prop2) --> [ that ], verb_phrase( Prop2). noun_phrase( X, Assn, S) --> determiner( X, Prop12, Assn, S), noun( X, Prop1), rel_clause( X, Prop1, Prop12). rel_clause( X, Prop1, Prop1) --> [ ].

COMPLETE GRAMMAR % Meaning of subset of natural language :- op( 100, xfy, and). :- op( 150, xfy, =>). sentence( S) --> noun_phrase( X, P, S), verb_phrase( X, P). noun_phrase( X, P, S) --> determiner( X, P12, P, S), noun( X, P1), rel_clause( X, P1, P12). noun_phrase( X, P, P) --> proper_noun( X). verb_phrase( X, P) --> trans_verb( X, Y, P1), noun_phrase( Y, P1, P). verb_phrase( X, P) --> intrans_verb( X, P).

COMPLETE GRAMMAR, CTD. rel_clause( X, P1, P1 and P2) --> [that], verb_phrase( X, P2). rel_clause( X, P1, P1) --> []. determiner( X, P1, P, all( X, P1 => P)) --> [every]. determiner( X, P1, P, exists( X, P1 and P)) --> [a]. noun( X, man(X)) --> [man]. noun( X, woman(X)) --> [woman]. proper_noun( john) --> [john]. proper_noun( annie) --> [annie]. proper_noun( monet) --> [monet]. trans_verb( X, Y, likes( X, Y)) --> [ likes]. trans_verb( X, Y, admires( X, Y)) --> [admires]. intrans_verb( X, paints(X)) --> [paints].

SOME TEST SENTENCES % Some tests test1( M) :- sentence( M, [john,paints],[]). test2( M) :- sentence( M, [a, man, paints], []). test3( M) :- sentence( M, [every,man,that,paints,admires,monet],[]). test4( M) :- sentence( M, [annie,admires,every,man,that,paints],[]). test5( M) :- sentence( M, [every,woman,that,admires,a,man,that,paints,likes,monet],[]).

EXAMPLES OF SENTENCES THIS GRAMMAR HANDLES “Every man that paints admires Monet” “Annie admires every man that paints” “Every woman that admires a man that paints likes Monet” Meaning constructed for this sentence: all( X, woman( X) and exists( Y, ( man( Y) and paints (Y)) and admires( X, Y) ) ==> likes( X, monet ) )

USE IN QUESTION ANSWERING Meanings in logic can be translated into Prolog: admires( X, monet) :- man( X), paints( X). admires( annie, X) :- man( X), paints( X). likes( X, monet) :- woman( X), man( Y), paints( Y), admires( X, Y). “Does Annie admire anybody who admires Monet?” ?- admires( annie, X), admires( X, monet).

GENERATING SENTENCES  Our grammar also generates sentences with given meaning ?- sentence( likes(john,annie), S, []). S = [john,likes,annie] ?- sentence( exists(X, man(X) and paints(X)), S, []). S = [a,man,paints]

LANGUAGE TRANSLATION WITH DCG  Translate from language 1 to langauage 2: ?-..., sentence_lang1( Meaning, Sent1, []), sentence_lang2( Meaning, Sent2, []).  Can also be used for program compilation (Spakowicz, BYTE, Aug. 1987) ?-..., program_source( M, SourceProg, []), % Parse program_target( M, TargetProg, []). % Generate