CS 30 Homework 7

Due by the beginning of class Tuesday, October 29

For this assignment, you may use the version of query2.scm that we developed in class today as your starting point. This version includes support for patterns like (when was ... made).

  1. Add a pattern/action rule to your natural language system for the pattern shown below:
    (what (movie movies) (was were) made (in before after since) _)
    
    This pattern contains four wild-cards, so its associated action procedure should take four arguments. The third argument can be used to decide which type of comparison operator to use in searching the database. For example:
    (what movies were made before 1950)
    ((casablanca) (citizen kane) (gone with the wind) (metropolis))
    
  2. Add a pattern/action rule for the following pattern:
    (what (movie movies) (was were) made between _ and _)
    
    For example:
    (what movies were made between 1960 and 1970)
    ((lawrence of arabia) (the manchurian candidate) (spartacus))
    
  3. Write a predicate function called equal-titles? that compares two movie titles but ignores the articles a, an, or the in either title. Modify your interface so that it uses this predicate in the appropriate places. For example:
    (equal-titles? '(the godfather) '(godfather)) => #t
    (equal-titles? '(2001 a space odyssey) '(the 2001 space odyssey)) => #t
    (equal-titles? '(2001 a space odyssey) '(2001 a space oddity)) => #f
    
    (when was godfather made)
    1972
    
  4. Do Exercise 7.37 on page 201 of Concrete Abstractions. Use <number> as the wild-card symbol. Change the query system and rule patterns to handle this new wild-card, which matches only numbers in a pattern. For example:
    (matches? '(made in <number>) '(made in 1974)) => #t
    (matches? '(made in <number>) '(made in japan)) => #f
    
    (what movies were made in 1974)
    ((amarcord) (chinatown))
    
    (what movies were made in japan)
    (i do not understand)
    
  5. Unfortunately, the pattern (what (movie movies) (was were) made in _) matches questions such as (what movies was made in 1974). To enforce grammatical correctness, wild-cards should provide a choice among alternative lists of words, instead of among single words. One example of this would be the pattern
    (what ((movie was) (movies were)) made in _)
    
    Change the query system to support this new wild-card list format. Don't forget to update the wild-card lists in other pattern/action rules so that they contain lists instead of symbols.

    HINT: To get started, define a helping function called matches-head? that takes two lists and determines if all of the items in the first list appear at the head of the second list. Then define another function that checks to see whether any of the lists in a wild-card list matches the beginning of the input list.

  6. Add pattern/action rules that allow the user to ask other questions of your own choosing. Try to make the patterns as general as possible, for example, by allowing singular and plural as well as past and present tenses. Also allow for the various ways the user might pose the query.

EXTRA CREDIT

Do Exercise 7.35 on page 201. You should finish the above problems before attempting the extra credit.

Turning in your homework

Put your query2.scm and moviedb.scm files into a single folder called Your Name HW 7 and drop it into the CS 30 class folder drop box. If you prefer, you may instead copy your folder to a clean floppy disk, labeled with your name, and turn this in during class. You do not need to turn in a hardcopy printout.