Nile
1 Introduction
2 Assignment
2.1 Recommend a book:
2.2 Recommend a pair:
2.3 Example:
3 Handing In

Nile

1 Introduction

You are creating Nile.com, which you hope will be the next big thing in online bookstores. You know that you can save money by anticipating what books people will buy; you will pass these savings on to your users by offering a discount if they buy books that Nile recommends.

To do this, you offer an incentive for people to upload their lists of recommended books. From their lists, you can establish suggested pairs. A pair of books is a suggested pair if both books appear on one person’s recommendation list. Of course, some suggested pairs are more popular than others. Also, any given book is paired with some books much more frequently than with others.

2 Assignment

You need to organize the list of recommended books to support two tasks:

2.1 Recommend a book:

When someone buys a book, you want to be able to suggest a second book to accompany it. Specifically, you should provide the book it is most frequently paired with, along with a count of how frequent this is. Because there may be more than one book with that count, you should return a list of books (even if there is only one) as well as the count.

2.2 Recommend a pair:

Sometimes, an indecisive user asks for a book recommendation. Nile offers not one recommendation at a time, but pairs of them! Wow! To support this, you must be able to identify the most popular pairs of suggested books. Return the most popular pair, with a count of how often it occurs. Again, because there may be multiple pairs with the same count, you should return a list of pairs (even if there is only one).

A list of recommended books is represented as a File:

data File:

    | file(name :: String, content :: String)

end

Each file contains a single input list, with single book descriptions on each line. That is, book descriptions will be separated by "\n". Each book has a unique and unambiguous description; that is, if two lines in two different input lists are identical, they refer to the same book. Otherwise they refer to different books. Input lists will always contain at least two books, and they will never contain duplicates. For example, an input file could be

file("vty.txt", "Crime and Punishment\nHeaps are Lame\nLord of the Flies")

An output recommendation is represented as a Recommendation:

data Recommendation:

    | recommendation(count :: Number, names :: List<String>)

end

2.3 Example:

f1=file("alist.txt","1984\nAnimal Farm\nHigurashi\nLife of Pi")

f2=file("blist.txt","Animal Farm\nHigurashi\nLife of Pi")

f3=file("clist.txt","1984\nHeart of Darkness")

 

check:

  recommend("1925",[list: f1,f2,f3]) is

    recommendation(0,[list: ])

  recommend("1984",[list: f1,f2,f3]) is

    recommendation(1,[list: "Animal Farm","Higurashi","Life of Pi","Heart of Darkness"])

 

  popular-pairs([list: f1,f2,f3]) is

    recommendation(2,[list: "Animal Farm+Higurashi","Animal Farm+Life of Pi","Higurashi+Life of Pi"])

end

fun recommend(title :: String, book-records :: List<File>) -> Recommendation

recommend takes a book title and a list of Files and produces a Recommendation. The Recommendation’s names is a list of the titles of the books that are most often paired with the input book. The Recommendation’s count is the number of times the books in the names list are each paired with the input book.

fun popular-pairs(records :: List<File>) -> Recommendation

popular-pairs takes a list of Files and produces a Recommendation. The Recommendation’s names is a list of Strings each of which represent a pair of books. Each of these Strings contains two titles separated by a "+", for example "book1+book2". Each most popular pair of books should appear exactly once and order is irrelevant. The Recommendation’s "count" is the number of times each pair occurred together in a file.

3 Handing In

You can hand in your code by sharing a copy of your work on code.pyret.org, and then submitting the link to your shared copy using the handin script. With your code open, click the share button at the top of the page, and click on “Share a New Copy” to generate a snapshot of your code at the current moment. Choose the shared copy you would like to submit and copy the url of the shared copy. In your terminal, run the command:

cs019-cpo-handin nile <shared copy url>

where <shared copy url> is enclosed in quotation marks. This will send us the link to your code. If you submit more than one shared copy in this manner, only your most recent copy will be graded.