0% found this document useful (0 votes)
299 views

CSC108H Assignment 3

The document describes an assignment to build a friend recommendation system for a social network. Students must write four functions in a3_functions.py to load profile data, invert a network dictionary, calculate friend recommendations based on mutual friends and networks, and sort the recommendations. The main program in a3_main.py will use these functions to run the recommendation system and output sample interactions as shown. Tests for each function must also be written and submitted. Functions will be evaluated based on correctness, code quality, and test coverage.

Uploaded by

Terry Gao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
299 views

CSC108H Assignment 3

The document describes an assignment to build a friend recommendation system for a social network. Students must write four functions in a3_functions.py to load profile data, invert a network dictionary, calculate friend recommendations based on mutual friends and networks, and sort the recommendations. The main program in a3_main.py will use these functions to run the recommendation system and output sample interactions as shown. Tests for each function must also be written and submitted. Functions will be evaluated based on correctness, code quality, and test coverage.

Uploaded by

Terry Gao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

CSC108H Assignment 3

Due Date: Tuesday, April 3rd, 2012, 10:00 pm

Friend Recommendations
In this assignment, you'll write a friend recommendation system for a
social network. Based on the scoring system described below, your
program will recommend people that a person may wish to befriend.

Starter code
For this assignment, we are giving you some basic starter code
(a3_functions.py and a3_main.py).

Design
As part of A3, you are asked to write four required functions. You
should use top-down design to break those tasks down into smaller
problems and write helper functions. Each helper function should
have a clear purpose and should not use global variables. You should
test those helper functions, but you will not submit your tests for
those functions.

Format of dictionaries
This assignment will involve working with 3 types of dictionaries:

"person to friends":
o

key: person's name (str)

value: list of friends' names (list of strs)

example: {'Jay Pritchett': ['Gloria Pritchett', 'Manny


Delgado', 'Claire Dunphy'], 'Claire Dunphy': ['Phil Dunphy',
'Mitchell Pritchett', 'Jay Pritchett'], 'Manny Delgado':
['Gloria Pritchett', 'Jay Pritchett', 'Luke Dunphy'],
'Mitchell Pritchett': ['Claire Dunphy', 'Cameron Tucker',
'Luke Dunphy'], 'Alex Dunphy': ['Luke Dunphy'], 'Cameron
Tucker': ['Mitchell Pritchett', 'Gloria Pritchett'], 'Haley
Gwendolyn Dunphy': ['Dylan D-Money'], 'Phil Dunphy':
['Claire Dunphy', 'Luke Dunphy'], 'Dylan D-Money': ['Haley
Gwendolyn Dunphy'], 'Gloria Pritchett': ['Jay Pritchett',
'Cameron Tucker', 'Manny Delgado'], 'Luke Dunphy': ['Manny
Delgado', 'Alex Dunphy', 'Phil Dunphy', 'Mitchell
Pritchett']}

"person to networks":
o

key: person's name (str)

value: list of networks that person belongs to (list of


strs)

example: {'Phil Dunphy': ['Real Estate Association'],


'Claire Dunphy': ['Parent Teacher Association'], 'Manny
Delgado': ['Chess Club'], 'Mitchell Pritchett': ['Law
Association'], 'Alex Dunphy': ['Orchestra', 'Chess Club'],
'Cameron Tucker': ['Clown School', 'Wizard of Oz Fan Club'],
'Gloria Pritchett': ['Parent Teacher Association']}

"network to people":
o

key: network (str)

value: list of people belonging to that network (list of


strs)

example: {'Wizard of Oz Fan Club': ['Cameron Tucker'],


'Real Estate Association': ['Phil Dunphy'], 'Orchestra':
['Alex Dunphy'], 'Clown School': ['Cameron Tucker'], 'Law
Association': ['Mitchell Pritchett'], 'Parent Teacher
Association': ['Claire Dunphy', 'Gloria Pritchett'], 'Chess
Club': ['Manny Delgado', 'Alex Dunphy']}

Recommendation score
For each person, all people in the social network who they are not
currently friends with are potential friends. For a particular person,
each potential friend is scored using the following point system:

for every mutual friend that the person and the potential friend
have, add 1 point to the potential friend's score

for each network that the person and the potential friend both
belong to, add 1 point to the potential friend's score

if the person has the same last name as a potential friend who
was identified through one or both of the previous two methods,
add 1 point to the potential friend's score

Program Requirements
Your program must meet the following requirements:
1. Your main program must be specified in a file named a3_main.py.
2. A second file, a3_functions.py, must contain implementations of
the four top-level functions described below. The four top-level
functions should be fully tested as discussed here.
3. When a3_main.py is run, your program should produce the input
and output below. It should import a3_functions and make use of
the functions in that module.
4. Your code must be well designed and documented and must
follow the style described in the assignment style guidelines.

Input
The profile information for people in the social network will be stored
in a file and your program will need to process that file and read in the
data.
The file will contain 0 or more profiles with the following format:

1 line with the person's name

0 or more lines with a network that this person belongs to (one


per line)

0 or more lines with the names of this person's friends (one per
line

There will be a blank line between profiles. For an example and to see
the format of the various types of lines, see profiles.txt.

Output

A transcript of the program has been copied below. The program's


output is in codetext and the user's input is in bold. Your program
should copy the format of the transcript exactly, including whitespace.
After the text shown here, there are no extra spaces or tabs, only a
newline character at the end of each line (including the last.)
Notice that when a name that is not part of the social network is
entered or when there are no recommendations for a particular
person, the message "There are no recommendations for this
person." is displayed. When the user finally presses enter without
entering a name, the message "Thank you for using the
recommendation system!" is displayed and the program exits. Be
careful to match the output exactly.
Please enter a person (or press return to exit): Claire Dunphy
Luke Dunphy
Gloria Pritchett
Cameron Tucker
Manny Delgado
Please enter a person (or press return to exit): Lily Tucker-Pritchett
There are no recommendations for this person.
Please enter a person (or press return to exit): Haley Dunphy
There are no recommendations for this person.
Please enter a person (or press return to exit): Gloria Pritchett
Claire Dunphy
Mitchell Pritchett
Luke Dunphy
Please enter a person (or press return to exit):
Thank you for using the recommendation system!

Testing
Write (and submit) a nose testfile for each of the required functions.
Name these four files test_load_profiles.py,
test_invert_networks_dict.py, test_make_recommendations.py and
test_sort_recommendations.py.
We will evaluate the completeness of your test files by running them
against flawed implementations we have written to see how many
errors you catch. Then, the TAs will check the test files for redundant

tests. The goal is to catch all of our errors without extra, unnecessary
tests.
Also be sure to test your main block in a3_main.py and be very careful
that the output is exactly a match for the description in this handout.
This is not tested by the type-checker (see below).

Required Functions
In the starter code file a3_functions.py, complete the following
function definitions. Include a docstring comment for each.
Function name:
(Parameter types)
-> Return type

Description

load_profiles:
(file, dict of {str :
list of strs}, dict of
{str : list of strs})
-> NoneType

The open file parameter has the file format


described above. The second parameter is a
"person to friends" dictionary and the third
parameter is a "person to networks" dictionary.
Update the two dictionaries to include the data
from the open file.

invert_networks_dict:
(dict of {str : list of Return a "network to people" dictionary based
strs}) -> dict of
on the given "person to networks" dictionary.
{str : list of strs}

make_recommendations:
(str, dict of {str :
list of strs}, dict of
{str : list of strs})
-> list of (str, int)
tuples

The first parameter is a person's name (in the


same format as the dictionary keys), the second
parameter is a "person to friends" dictionary,
and the third parameter is a "person to
networks" dictionary. Using the
recommendation system described above,
return the friend recommendations for the
given person in a list of tuples where the first
element of each tuple is a potential friend's
name (in the same format as the dictionary
keys) and the second element is that potential
friend's score. Only potential friends with
non-zero scores should be included in the list.

In the given list of tuples, the first element of


sort_recommendations:
each tuple is a potential friend's name (in the
(list of (str, int)
same format as the dictionary keys) and the
tuples) -> list of strs
second element is that potential friend's score.

Return a list of potential friend's names ordered


by score (highest to lowest).
Duplicate scores: If multiple potential friends
have the same score, those potential friends
should appear in the list in alphabetical order
relative to each other, such as by using
list.sort on those names. Note: sort the entire
name as is (e.g., "Cameron Tucker" comes
before "Phil Dunphy").

Type checks
We are providing a type-check module that can be used to test
whether your functions in a3_functions.py have the correct parameter
and return types. To use the type checks, place a3_type_checks.py
and profiles.txt in the same directory as your a3_functions.py and Run
it.
If the type-checks pass: Then the function parameters and return
types match the assignment specification. This does not mean that
your code works correctly in all situations. We will do a thorough
job of testing your code once you hand it in, so be sure to thoroughly
test your code yourself before submitting.
If the type-checks fail: Look carefully at the message provided.
One or more of your parameter or return types does not match the
assignment specification. Fix your code and re-run the tests. Make
sure the tests pass before submitting.

Marking
Your assignment will be evaluated using these three criteria:

Correctness: Your a3_main.py program should run as described


in the requirements section by using the functions from
a3_functions.py. We will test your a3_main.py using our correct
implementations of a3_functions, so even if you weren't able to
get the functions in your a3_functions.py working properly you
should finish a3_main.py. We will also check the correctness of
each of the four required functions from a3_functions.py.
Remember that spelling of file and function names, including
case, is important, and that functions should have exactly the

number of parameters required and be placed in the same order


as specified. Correctness, as evaluated by our tests and the TAs,
will count for 50% of the assignment marks.

Testing: We will run the nose tests that you submit on a series
of flawed (incorrect) implementations of the four required
functions. Your testing mark will depend on how many of the
flawed implementations your nose tests catch, whether or not
they successfully pass a working (correct) implementation, and
whether your test files contain redundant (unnecessary) tests.
Testing will count for 30% of the assignment marks.

Style and Design: Your code should be well documented with


docstrings as well as internal comments, and it should adhere to
the Assignment Style Rules. Your program should be broken down
into functions, both to avoid repetitive code and to make the
program easier to read. Each helper function should have a
coherent purpose and should use parameters, rather than
global variables, to get all the information they need from the
caller. They should use a return value or mutable parameter to
send information back to the caller. Style and design will count
for 20% of the assignment marks.

What to Hand In
The very last thing you do before submitting should be to run
the type-check module one last time. Otherwise, you could make
a small error in your final changes before submitting that causes your
code to receive zero for correctness.
Following the instructions on the course website, submit the following
files:

a3_functions.py

a3_main.py

test_load_profiles.py

test_invert_networks_dict.py

test_make_recommendations.py

test_sort_recommendations.py

any text files that your tests use

Remember that spelling of filenames, including case, counts: your file


must be named exactly as above. Remember also that your

submission will be marked on CDF, so you should make sure it works


on CDF.

You might also like