Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Prolog gives us a simple way to write context-free grammars, thanks to built-in support for Definite Clause Grammars (DCGs). In this first part, we don't

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Prolog gives us a simple way to write context-free grammars, thanks to built-in support for Definite Clause Grammars (DCGs). In this first part, we don't need to worry about what exactly DCGs are. (But those who are curious, the prolog tutorial linked from the course front page on canvas has a section on DCGs: http://www.learnprolognow.org/Ipnpage.php? pagetype-html&pageid=lpn_htmlse29.) All we need to know is that if we have a context-free grammar rule like SNP VP (where S stands for sentence, NP stands for noun phrase, and VP stands for verb phrase), we can write the rule in a prolog file this way: s np, vp Note the period at the end, the comma between the symbols in the right-hand side, and the two dashes that form the arrow. The arrow must look like the one above, there must always be a period at the end, and there must be comma between symbols on the right-hand side. The rule above deals only with non-terminals. Rules with terminals are similar, but we will use square brackets around the terminal symbols, as in the example below: n -dogs Consider the small treebank below: A treebank is a collection of trees, where the trees are syntactic analyses for sentences.) s np, vp. So include that rule in your file. The add the rules that involve NPs, VPs, etc Download hw4part1-template.pl from the HW4 folder in canvas to get started. Notice the table statements in the beginning of the file. Make sure that all of our non-terminals listed there. Once you have your grammar (name it hw4part1.pl) and it is in your working directory, you can try the following: ?- [hw4part1] ?- sC[the, dogs,chased, the,cats], D) which should be true, and ?- sC[the, dogs, the which should be false. You can also try , cats, chased], ) ?- s(X, ) and see what happens. (You don't need to turn in prolog output, just your grammar.) After changing your grammar and reloading it in prolog, use the following to clear all tables computed for the previous grammar: ?- abolish_all_tables Prolog gives us a simple way to write context-free grammars, thanks to built-in support for Definite Clause Grammars (DCGs). In this first part, we don't need to worry about what exactly DCGs are. (But those who are curious, the prolog tutorial linked from the course front page on canvas has a section on DCGs: http://www.learnprolognow.org/Ipnpage.php? pagetype-html&pageid=lpn_htmlse29.) All we need to know is that if we have a context-free grammar rule like SNP VP (where S stands for sentence, NP stands for noun phrase, and VP stands for verb phrase), we can write the rule in a prolog file this way: s np, vp Note the period at the end, the comma between the symbols in the right-hand side, and the two dashes that form the arrow. The arrow must look like the one above, there must always be a period at the end, and there must be comma between symbols on the right-hand side. The rule above deals only with non-terminals. Rules with terminals are similar, but we will use square brackets around the terminal symbols, as in the example below: n -dogs Consider the small treebank below: A treebank is a collection of trees, where the trees are syntactic analyses for sentences.) s np, vp. So include that rule in your file. The add the rules that involve NPs, VPs, etc Download hw4part1-template.pl from the HW4 folder in canvas to get started. Notice the table statements in the beginning of the file. Make sure that all of our non-terminals listed there. Once you have your grammar (name it hw4part1.pl) and it is in your working directory, you can try the following: ?- [hw4part1] ?- sC[the, dogs,chased, the,cats], D) which should be true, and ?- sC[the, dogs, the which should be false. You can also try , cats, chased], ) ?- s(X, ) and see what happens. (You don't need to turn in prolog output, just your grammar.) After changing your grammar and reloading it in prolog, use the following to clear all tables computed for the previous grammar: ?- abolish_all_tables

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

25 Vba Macros For Data Analysis In Microsoft Excel

Authors: Klemens Nguyen

1st Edition

B0CNSXYMTC, 979-8868455629

More Books

Students also viewed these Databases questions