CSC108H Assignment 3
CSC108H Assignment 3
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
"person to networks":
o
"network to people":
o
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:
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
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
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
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:
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.
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