Question: 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

 Prolog gives us a simple way to write context-free grammars, thanksto built-in support for Definite Clause Grammars (DCGs). In this first part,we don't need to worry about what exactly DCGs are. (But thosewho are curious, the prolog tutorial linked from the course front page

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!