Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Assignment 3

Please read this document very carefully.  Follow instructions exactly.  If you have any questions please post them on the A3 channel.

This assignment is due April 9th, by 11:59pm

Imagine you work for a social media company named Chirper. ’  On this social media platform users have profiles and publish relatively short text messages for other users to read, like, and/or dislike; these messages are referred to as chirps. You are tasked with implementing functions which parse and manipulate the data of this social network platform. You are given a le, assignment3 .py, with five incomplete functions. For this assignment, you are required to complete these func- tions. A description regarding the intended behaviour of these functions follows.

Note: One potential difficulty of this assignment is to realize how the data is stored and what it represents. Pay close attention to the input and returns types of each function.

To give you a better idea to how the social platform works, here are some summary points and definitions.

1.  A chirp is string (like a message).  A chirp may also have tags  associated with it which users can add.  These tags have %’s in front of them, do not include white space or other %’s in them.

For example, a chirp may be:  ‘Nothing  on the midterm was taught  in  lecture!   %CS1MD3 %Unfair   %ShouldHaveGoneToWestern’

Valid tags are: %2EZ, %my cute cat, %EarnDat$$, etc.

Invalid tags are: %my  cute  cat, %The99%, my tag, etc.

2.  Each Chirper user has a set of profiles they follow, and a set of profiles which follow them. If User 1 follows User 2, it does not necessarily mean User 2 follows User 1.

3.  A profiles dictionary is of the type Dict[int, Tuple[str, List[int], List[int]]]; profiles dictionary is used as a shorthand for this type in the function descriptions later in this document.  The keys of a profiles dictionary are unique integers representing user id numbers.  The profiles dictionary values contain the profile information corresponding to the specific user id number given as the key. The values are Tuples, where the first element of the list is the corresponding user name, the second element is a list of user ids representing the user’s followers  (the user id given as the key), and the third  element  is a list of user ids that the user in question is following.

4.  A chirp dictionary is of the type Dict[int, Tuple[int,  str, List[str], List[int], List[int]]]; chirp dictionary is used as a shorthand for this type in the function descrip- tions later in this document. The keys of a chirp dictionary are unique integers representing chirp id numbers. The chirp dictionary values contain the chirp information corresponding to the specific chirp id number given as the key.  The values are Tuples.  The first element of the list is the user id chirp’s author. The second element is the chirp itself. The third element is a list of tags  associated with the chirp.  The forth  element  is a list of user ids which liked the chirp. And the fifth element is a list of user ids which disliked the chirp.

Functions

You are required to implement all of the following functions.  Pay attention to parameters of each function. For example, if it is said an input will be a Dict[int, str], you can trust your function will never be tested on input which isn’t a Dict[int, str]. For further examples of how these functions are intended to operate, view the docstrings of the starter code for this assignment.

1.  create_profile_dictionary(str)  -> profiles_dictionary

The input parameter is the name of a text le containing all of Chirper’s profile information. You may assume the le is in the same directory as assignment3 .py.  The le is a series of profile data, where data for each profile has the following format:

USERID

USERNAME

FOLLOWER1, FOLLOWER2,  . . . , FOLLOWERn

FOLLOWED1, FOLLOWED2,  . . . , FOLLOWEDm

where USERID, FOLLOWERi, and FOLLOWEDj are all unique numbers.  The third line represents the users which follow USERNAME, and the forth line represents the users which USERNAME fol- lows. In the text le there is always a blank-line between different profiles. See profiles .txt as an example.

Based off this data, the function constructs a profiles_dictionary where the orders of the ids representing followers and users follows, are the same orders as which they appear in the text le. See the doctstring and profiles .txt for further clarification. Assume that the given text file is perfect and that there are no formatting errors.

2.  create_chirp_dictionary(str)  ->  chirp_dictionary

The input parameter is the name of a text le containing all of Chirper’s message information. You may assume the le is in the same directory as the as assignment3 .py. The le is a series of message data, where data for each message has the following format:

CHIRPID

USERID

MESSAGE

TAG1, TAG2,  . . . , TAGk

LIKED1, LIKED2,  . . . , LIKEDn

DISLIKED1, DISLIKED2,  . . . , DISLIKEDm

where CHIRPID, USERID, LIKEDi, and DISLIKEDj are all unique numbers. USERID is the id of the user which made the chirp.  The third line  is the chirp itself.  The forth line  represents a list of tags associated with said chirp.  The fifth line is a sequence of user ids which liked the chirp. The sixth line is a sequence of user ids which disliked the chirp. In the text le there is always a blank-line between different chirps. See chirps .txt as an example.

Based off this data, the function constructs a profiles_dictionary where the orders of the tags and ids representing likes and dislikes, are in the same orders in which they appear in the text file.  If there are no tags associated with a chirp, the empty string is associated with it instead.  See the doctstring and chirps .txt for further clarification.  Assume that the given text file is perfect and that there are no formatting errors.

3. get_top_chirps(profile_dictionary,  chirp_dictionary,  int)  -> List[str]              The third parameter is a user id which is in the given profile_dictionary. Let the user with this user id be denoted by u. The function uses the data from the rst two parameters to nd the chirp with the most likes for each user followed by u. The function creates a list of these chirps and returns it. You may assume:

(a)  For a given user, there does not exist any two chirps with the same number of likes.

(b)  The order of the chirps in the returned list is arbitrary. As long as all the correct chirps

are present and no incorrect chirps are present, the function is correct. See the docstring for examples.

4.  create_tag_dictionary(chirp_dictionary)  -> Dict[str, Dict[int, List[str]]]       Takes in a chirp_dictionary and creates a new dictionary.  In the new dictionary, tags are keys, the values are dictionaries where the keys in these dictionaries are user ids, and the values of these dictionaries are chirps made by the corresponding user, which also had the corresponding tag. See the docstring for examples.

5. get_tagged_chirps(chirp_dictionary,  str)  -> List[str]

Takes in a chirp_dictionary and a tag, and returns a list which contains a list of all the chirps which had said tag on them.  The order of the returned list is arbitary, as long as all the correct chirps are present and no incorrect chirps are present, the function is correct. See the docstring for examples.

Submitting and Grading

This assignment will be submitted electronically via Avenue.  Your submitted le must have the name assignment3 .py, or you will receive 0.

This assignment is worth 10% of your nal grade.  Grading is done completely automatically. That is, a program calls your function, passes it certain arguments, and checks to see if it returns the expected output. Each function is worth 20% of assignment grade. For any one function, if you pass n of the m tests we run on that function, your grade for that function will be n/m.