CSc 110 - Digital Assistant

Digital Assistants

Many of us have used a digital assistant before (ranging from Google Assistant, Apple’s Siri, Amazon’s Alexa, Microsoft’s Cortana, and perhaps more). In this assignment, you will be creating a very simplistic version of a digital assistant such as these.

The digital assistant (DA) that you create will be MUCH simpler. The interface for using it will not be with your voice - rather, it will be with typed text on the python console. Also, it will only be able to recognize to main types of commands. You can either tell the DA something that you want it to remember, or you can ask the DA to recall something that you told it.

Tell the DA something

The first type of command (telling) will be a single sentence with the following form:

(entity) (category) (was / is / will be) (item)

There are four parts to this command.

Below are a few examples of full commands:

You program should process each command that is entered, and save this information into one or more dictionaries. You MUST use dictionaries to store the command info. You may use lists only for file reading and when processing the input commands (for example, string.split returns a list). In order to process the commands, you may want to use the split() function, as well as other string features of python.

Any time the DA requests a command / sentence from the user, the line should begin with USER: .

Ask the DA something

You can also ask the DA for information that you have previously told it. These requests will take the following form:

what (tense) (entity) (category)?

These ask commands will always begin with the word what. The tense, entity, and category should match up with what you previously saved / remembered. Again, you’ll want to use the string split() function along with other string functionality to extract the components of the command. You should use the strip() function to ignore the question-mark.

DA Replies

Any time the DA replies-to a command / sentence from the user, the line should begin with DA: followed by the message. When DA accepts new information, it should reply with DA: OK!. When the user asks the DA a question, the DA will reply with the expected information, or an error message. See the examples below for what the replies should look like.

There is also a special-case for the DA replies. If the user refers to “my”, the DA will switch it to “your” in the reply. Also, “your” should be switched to “my”. This is shown in one of the examples below.

Guided Example(s)

Let’s say that the user entered

USER:
joe's favorite food is orange chicken

Your program should remember that the entity joe's favorite food is (present tense) orange chicken. Later, the user could say:

USER:
what is joe's favorite food?

And the program should reply with:

DA: joe's favorite food is orange chicken.

If in the same program session, we were to then enter:

USER:
joe's favorite food was pizza
DA: OK!
USER:
joe's favorite food is salad
DA: OK!
USER:
joe's favorite food will be pasta
DA: OK!

Then the following would be the program’s response:

USER:
what is joe's favorite food?
DA: joe's favorite food is salad
USER:
what was joe's favorite food?
DA: joe's favorite food was pizza
USER:
what will be joe's favorite food?
DA: joe's favorite food will be pasta

Notice in this example that: (A) the software remembers a different food for the same person, for each of the three tenses, and (B) the old “orange chicken” favorite was overwritten by the new “salad” preference for the present-tense (is) case.

Unknown Request

If the user requests information that has not been provided to the DA yet, The DA should reply with DA: I don't know..

Loading from a file

At the beginning of execution, your program should also open a file named da.txt and potentially load in existing DA information. The format of the file will be like so:

(entity) (category)|(tense)|(item)
(entity) (category)|(tense)|(item)
(entity) (category)|(tense)|(item)
...

Notice the vertical bars separating the three components. Your program can read the lines of the file, split on the bars, and then put this information into the dictionarie(s) in the program. A sample file may look like so:

my favorite food|was|chicken
his smallest car|is|camry
America's current state count|is|50

How to store the information

One way to tackle this problem is to store the information from the user commands (and/or the file) in one dictionary. Each command from the user should follow this format:

(entity) (category) (was / is / will be) (item)

You can store this into one dictionary if you map the concatenation of the entity, category, and tense as the keys, and the items as values. For example, if the user provided this command:

my favorite meal is orange chicken

The mapping in the dictionary could be:

'my favorite meal is' -> 'orange chicken'

For each bit of information read in from a file or user, you can create a new mapping, or update an existing mapping.

Complete Examples

DA: Hi there, let's talk. . .
USER:
my favorite food is orange chicken
DA: OK!
USER:
what is my favorite food?
DA: your favorite food is orange chicken
USER:
james's hardest course is CS 500
DA: OK!
USER:
what is james's hardest course?
DA: james's hardest course is CS 500
USER:
bye
DA: bye!
DA: Hi there, let's talk. . .
USER:
my first car was a dodge durango
DA: OK!
USER:
your first car was nothing
DA: OK!
USER:
what was my first car?
DA: your first car was a dodge durango
USER:
what was your first car?
DA: my first car was nothing
USER:
bye
DA: bye!

Submission

Submit this to Gradescope by Tuesday, April 7th, at 7pm. Name the file digital_assistant.py.