csc108h assignment 3

Upload: terry-gao

Post on 06-Jul-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/17/2019 CSC108H Assignment 3

    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)

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

    http://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/a3_functions.pyhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/a3_functions.pyhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/a3_main.pyhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/a3_main.pyhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/a3_main.pyhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/a3_functions.py

  • 8/17/2019 CSC108H Assignment 3

    2/8

    o  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)

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

    strs)

    o  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)

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

    strs)

    o  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 TeacherAssociation': ['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:

  • 8/17/2019 CSC108H Assignment 3

    3/8

      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 nameda3_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

    http://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/index.shtml#required_funcshttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/index.shtml#required_funcshttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/index.shtml#required_funcshttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/index.shtml#testinghttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/index.shtml#testinghttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/index.shtml#testinghttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/index.shtml#required_outputhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/index.shtml#required_outputhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/index.shtml#required_outputhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/rules.shtmlhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/rules.shtmlhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/rules.shtmlhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/profiles.txthttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/profiles.txthttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/profiles.txthttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/profiles.txthttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/rules.shtmlhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/index.shtml#required_outputhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/index.shtml#testinghttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/index.shtml#required_funcs

  • 8/17/2019 CSC108H Assignment 3

    4/8

    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 manyerrors you catch. Then, the TAs will check the test files for redundant

  • 8/17/2019 CSC108H Assignment 3

    5/8

    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 ofstrs}) -> dict of

    {str : list of strs} 

    Return a "network to people" dictionary basedon the given "person to networks" dictionary.

    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 thegiven 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.

    sort_recommendations: 

    (list of (str, int)

    tuples) -> list of strs 

    In the given list of tuples, 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.

  • 8/17/2019 CSC108H Assignment 3

    6/8

    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 friendsshould 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 thoroughlytest 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

    http://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/a3_type_checks.pyhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/a3_type_checks.pyhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/a3_type_checks.pyhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/profiles.txthttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/profiles.txthttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/profiles.txthttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/profiles.txthttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/starter/a3_type_checks.py

  • 8/17/2019 CSC108H Assignment 3

    7/8

    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 requiredfunctions. 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 theprogram 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 runthe 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

    http://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/rules.shtmlhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/rules.shtmlhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/rules.shtmlhttp://www.cdf.toronto.edu/~csc108h/winter/assignments/a3/rules.shtml

  • 8/17/2019 CSC108H Assignment 3

    8/8

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

    on CDF.