Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

tasks related to parsing English sentences. Background: Rules for legal English

ID: 3864592 • Letter: T

Question

tasks related to parsing English sentences.

Background:

Rules for legal English sentences can be represented as grammar rules. For the purposes of this project, we will only have the following rules:

For example, the first rule says that a noun followed by a verb followed by a noun (and nothing else) is one way to make a legal sentence.

Of course the actual English language contains many more such rules. Also note that we are concerned purely with syntax, and can thus construct sentences that are semantic nonsense (e.g., "I perform depression") or do not take into account other grammatical rules such as those about subject-verb agreement (e.g., "I are large bird").

Input:

You have available to you 4 input files1, named nouns, verbs, adjectives, and pronouns. These files have been filtered to exclude words that can be multiple parts of speech (e.g., dance). Each file contains one word per line, all lowercase.

The input files are supplied in tar form. To extract them, type "tar -xvf words.tar" without the quotes

Part A:

Prompt the user for a sentence. Depending on whether or not the sentence is a legal English sentence according to the above rules, output one of the following 6 messages (exactly as stated) to the screen, and terminate:

Your sentence is a legal sentence by rule {1,2,3,4,5}.
Your sentence is not a legal sentence.

You may assume that the input sentence contains only letters and spaces, though letters may be either upper or lower case. Words in the sentence are separated by at least one space.

Part B:

Elbonian is similar to English, but has 2 differences:

Verbs always occur at the beginning of the sentence (rumor has it that Elbonians like to start doing things before understanding the problem). Other words are still in the same order as in English. For example, rule 1 above would be as follows in Elbonian:sentence = verb noun noun

There are no adjective words, and the modified noun is changed instead. More specifically, the modified noun is changed to have the first letter of the adjective as a prefix and the remaining letters as a suffix.

For example, the English sentence "I avoid large thing" would be "avoid I lthingarge" in Elbonian.

Given a file of sentences named "engsents", produce a second file named "elbsents" containing the equivalent Elbonian sentences. Both files contain one sentence per line. If an input is not a legal sentence, you should output "Illegal sentence found" on its own line in the output file and proceed to the next sentence. Your translation should preserve cases, though the output should have exactly one space between words.

the file : http://e-gym.org/uploads/words.tar

1. noun 2. sentence noun verbs adjective noun 3. sentence pronoun. verb noun 4. sentence pronoun. verb adjective noun. verb>

Explanation / Answer

<sentence> ::= <noun><verb><noun>
<sentence> ::= <noun><verb><adjective><noun>
<sentence> ::= <pronoun><verb><noun>
<sentence> ::= <pronoun><verb><adjective><noun>
<sentence> ::= <pronoun><verb><pronoun>