Program Assignment 4

100 Points
Due: 4/28 at 10:10am

For this programming assignment, once again you will be diagramming simple sentences. The sentence grammar is exactly the same as for Program 1 and Program 2.

For this assignment, your program must be written in Prolog. The same implementation restrictions as for Program 3 apply.

Write your program as a Prolog predicate called diagram_sentence. Your predicate should take two arguments. The first argument is a list of symbols that represents the input to be diagrammed. The second argument represents the result of your parse, which should either be the appropriate sentence diagram or an error message. For example, you might invoke your sentence diagrammer this way:

    ?- diagram_sentence( [alice, found, mean, green, book], Diagram ).

This setup is similar in many ways to that in Program 2, in that you are not responsible for reading from standard input or splitting a line into individual tokens (words). Further, your solution will process just a single input that is provided as an argument, rather than looping to read all lines from standard input. It differs from Program 1 in that the result is returned through the second parameter.

One way to organize your solution (but not the only way, and certainly not a requirement for this program) is to construct one predicate for each nonterminal that takes a list of atoms as a parameter and breaks the list into a diagram for that nonterminal (if possible) and the remainder of the input sequence. For example:

    /* adj( +List_Of_Symbols, -Diagram, -Remaining_Symbols ) */
    adj( [ green | Rest ], [green], Rest ).
    adj( [ lean  | Rest ], [lean],  Rest ).
    adj( [ mean  | Rest ], [mean],  Rest ).

The predicate adj/3 does the job for <adj>. This is just a simple skeleton of an implementation--it may not handle all of the necessary issues, including error checking. A sample invocation of adj/3 is

    ?- adj( [green, cow, saw, book], Word, Remainder ).

which returns

    Word = [green]
    Remainder = [cow, saw, book]

You may need to adjust or adapt this approach, depending on the overall design you use for your Prolog solution--or you may ignore it altogether and develop your own strategy.

For purposes of our Prolog implementation, the "diagram" produced by your program will be a Prolog nested list. This diagram should follow exactly the structure of the Scheme S-expression diagrams from Program 2, except that they will use Prolog syntax--square brackets with comma-separated elements. For example, consider the following sentence:

    [mean, cow, saw, carefully, green, alice, with, book]

The Prolog list diagram for this sample should be:

    [[[mean], cow], [saw, carefully], [[green], alice, [with, [book]]]]

Your diagram_sentence predicate should unify such a Prolog list structure with its second argument for a sentence that parses successfully. Otherwise, the second argument should be unified with a string containing the appropriate error message. The error message requirements are exactly the same as in Programs 1 and 2. The requirements for where brackets should appear in each diagram are the same as for Program 2.

In addition to writing your program, you will also need to write a set of test cases that demonstrate that your program works correctly. The Curator-assessed portion of your program grade will depend on all three of these factors:

Review the test case input guidelines to see the format for your test cases. Here is an example test case:

//==
diagram_sentence( [alice, found, mean, green, book], Answer )
//--
[ Answer = [[alice], [found], [[mean, green], book]]
]

Here, the input section of the test case is the Prolog goal to satisfy. The output section contains a list of one or more solutions separated by commas. Each solution is a list of Variable = Value pairs giving the value for each unbound variable listed in the Prolog goal. Not that neither the order of the solutions in the output section nor the order of the variables within a solution (if the goal contains more than one unbound variable) matter in the comparison. If the goal has no solution, simply list fail as the expected output. If the goal contains no unbound variables but should still succeed, list true as the expected output. An empty output section will be interpreted the same as fail.

Combine all of your test cases into a single ASCII file to submit to the Curator along with your program. In addition, you can use the tddplg.pl tool to run test cases on your own machine.

Your Prolog implementation is to be organized in a single file. All documentation and identifying information should be placed in comments within the single source file. The comments at the beginning of the file should identify the assignment and give your full name. Every Prolog predicate should be preceded by a comment block explaining its purpose, the meaning of each parameter, and the general strategy of its implementation if applicable.

In addition to your Prolog source file, you will also need to submit a plain ASCII file containing your test cases.

Your program and test case file will be both be submitted electronically through the Web-CAT Curator for automatic grading. The Web-CAT Curator will grade one half of your program score (50 points), as well as assess any deductions based on the late policy described in the syllabus. The TA will assess the remaining 50 points based on the program grading criteria. There is no need to print or turn in a hard copy version of your program; the TA will mark up a PDF version of your program and e-mail it back to you.