1. Homepage
  2. Programming
  3. CS 3304: Comparative Languages - Project 3 Logical Programming

CS 3304: Comparative Languages - Project 3 Logical Programming

Engage in a Conversation
USVirginia TechCS 3304CS3304 Comparative LanguagesLogical ProgrammingProlog

CS 3304: Comparative Languages

Project 3 CourseNana.COM

Logical Programming

At some point in your schooling, you may have encountered the concept of diagramming sentences. A diagram of a sentence is a tree-like drawing representing the sentence's grammatical structure, including parts such as the subject, verb, and object. Here is an extended BNF grammar for some simple English sentences that we will use for the purposes of diagramming. CourseNana.COM

\ --> \ \ \ \ --> \ \ --> \ | \ \ \ --> \ \ --> defined in the Verbs list loaded via the definitions.pl \ --> defined in the Adverbs list loaded via the definitions.pl \ --> [\] \ [\] \ --> defined in the Nouns list loaded via the definitions.pl \ --> \ | \ \ \ --> defined in the Adjectives list loaded via the definitions.pl \ --> \ \ \ --> defined in the Prepositions list loaded via the definitions.pl CourseNana.COM

The parts within the [ ] are optional. CourseNana.COM

This grammar can generate an infinite number of sentences. One sample is: CourseNana.COM

mean cow saw carefully green alice with book CourseNana.COM

(For simplicity, we ignore articles, punctuation, and capitalization, including proper nouns) CourseNana.COM

Implementation Language

For this project, we are going to be using Prolog. Your solution may only use standard Prolog code. This assignment will also give you more experience using BNF. Decide what basic operations you need to implement, how those will be written as predicates, and how they can be used to build higher-level predicates. CourseNana.COM

Input Format

Your program should read "candidate sentences", one per line, from a file named "input.txt". For each input line, your program should attempt to interpret the line's contents (a whitespace-separated list of words) as a sentence. You will need to read each entire line as a string. This string will have to be split into tokens, then feed them to your parsing routine. See the provided starter code for how to do this. If there is another sentence after the current sentence, it will be followed by a space and then a period. If there are no sentences after the current one, the sentence will end with a new line. CourseNana.COM

Output Format

The output of your program should be produced in a file named "output.txt". Your program should produce a "diagrammed" version of the input string, which means a sentence is in properly delimited form. "Properly delimited" means that each non-terminal appearing in the input string now has a set of delimiters around it For instance, the input string: "alice found mean green book" CourseNana.COM

would be delimited as CourseNana.COM

( [{alice}])[%found%]([<mean><green>{book}] )

A more complicated example is "mean cow saw carefully green alice with book" CourseNana.COM

which returns CourseNana.COM

( [ < mean > { cow } ] ) [ % saw % $ carefully $]([< green >{alice } * with * [ { book } ] ] )

In addition, there are two distinct error conditions that your program must recognize. First, if a given string does not consist of valid tokens. Second, if the parameter is a string consisting of valid tokens but it is not a legitimate sentence according to the grammar. In both cases, respond with the following error message. "ERROR" CourseNana.COM

Details

The subject and object each directly contains a noun phrase, so the ( ) on those parts indicates the subject or object phrase. Then the noun phrase and verb phrases are contained within [ ]. From there, each of the individual parts is contained within unique delimiters to set them apart from the other parts: CourseNana.COM

Part Delimiters
subject ( )
object ( )
noun phrase [ ]
verb phrase [ ]
adjective phrase none
prep phrase none
noun { }
verb % %
adjective < >
adverb $ $
preposition

Running/Testing your program

While you are working on your predicates, I recommend using swipl to load your file and make sure the smaller parts work. Once you are ready to test the entire program from the terminal, you can run this command: CourseNana.COM

swipl -q -f starter.pl -g make_go_now -g halt -- input.txt output.txt

It will run swipl with the file named starter.pl then write make_go_now() in the shell to meet that goal. If it is successful, it will return true. The last two arguments are: (1) the input filename from where you’d like to read the sentences, and (2) the output filename is where the output will be written. CourseNana.COM

This is the command I will be using to test your code. So make sure you have the make_go_now predicate that makes all of your code go. Also, make sure that your program works properly with the autograder. CourseNana.COM

Testing using Autograder

Eight test cases are provided with the project. We will use these tests for 80% of the grade. The remaining 20% will be tested on hidden test cases. To run provided test cases, use the following command. CourseNana.COM

$ python3 autograder.py --prolog_file starter.pl

Submitting Your Program

You will submit your code, starter.pl file, to Canvas for grading. Files Attached: CourseNana.COM

  • starter.pl
  • definitions.pl
  • input.txt
  • output.txt
  • input_2.txt
  • output_2.txt
  • input_3.txt
  • output_3.txt

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
US代写,Virginia Tech代写,CS 3304代写,CS3304代写, Comparative Languages代写,Logical Programming代写,Prolog代写,US代编,Virginia Tech代编,CS 3304代编,CS3304代编, Comparative Languages代编,Logical Programming代编,Prolog代编,US代考,Virginia Tech代考,CS 3304代考,CS3304代考, Comparative Languages代考,Logical Programming代考,Prolog代考,UShelp,Virginia Techhelp,CS 3304help,CS3304help, Comparative Languageshelp,Logical Programminghelp,Prologhelp,US作业代写,Virginia Tech作业代写,CS 3304作业代写,CS3304作业代写, Comparative Languages作业代写,Logical Programming作业代写,Prolog作业代写,US编程代写,Virginia Tech编程代写,CS 3304编程代写,CS3304编程代写, Comparative Languages编程代写,Logical Programming编程代写,Prolog编程代写,USprogramming help,Virginia Techprogramming help,CS 3304programming help,CS3304programming help, Comparative Languagesprogramming help,Logical Programmingprogramming help,Prologprogramming help,USassignment help,Virginia Techassignment help,CS 3304assignment help,CS3304assignment help, Comparative Languagesassignment help,Logical Programmingassignment help,Prologassignment help,USsolution,Virginia Techsolution,CS 3304solution,CS3304solution, Comparative Languagessolution,Logical Programmingsolution,Prologsolution,