Question: Instructions: For this assignment you will construct a single python file called a4.py, with several text-processing functions. You are free to use your own solutions

Instructions:

For this assignment you will construct a single python file called a4.py, with several text-processing functions. You are free to use your own solutions to these problems as building blocks for your other solutions. You may use any built-in methods you wish unless a question explicitly specifies otherwise. You may create any additional 'helper' functions you may need, however please ensure that the required functions exist, are correctly named, and well labeled. Please include the question number in the comments for each function.

You can assume that each space (' ') separates one word from the next. Note, however, that not all words are delimited by spaces on both sides. E.g. the first and last words are delimited by the start and end of file, and the last word on each line is delimited by a ' ' instead of a space. Fortunately, the default behaviour of the string.split() method is to split on ANY whitespace.

When considering unique words, you should not use case sensitivity or punctuation to distinguish words. That is, the words "Hello", "hello.", and "Hello!" should all be considered the same word (simply "hello").

Punctuation characters refers to the following set of characters: . , ? ! ; : \' \" . You may assume no other punctuation symbols exist in the provided textfiles.

A sentence is any string ending with either a '.', '?', or a '!'. You may assume that only one such character appears per sentence, and no other characters are used to terminate sentences.

Question 1:

Write a function called wordFrequency() that takes a filename(string) as an argument and returns a dictionary containing each unique word along with the number of times that word occurred in the text.

Example:

> python -i a4.py
>>> wordFrequency('phrases.txt') {'a': 16, 'stitch': 1, 'in': 5, 'time': 1, 'saves': 1, 'nine': 1, 'bite': 1, 'the': 14, 'bullet': 1, 'cry': 1, 'havoc': 1, 'and': 11, 'let': 1, 'slip': 1, 'dogs': 1, 'of': 11, 'war': 1, 'dont': 1, 'count': 1, 'your': 2, 'chickens': 1, 'before': 1, 'they': 1, 'are': 2, 'hatched': 1, 'eye': 1, 'newt': 1, 'toe': 1, 'frog': 1, 'wool': 1, 'bat': 1, 'tongue': 1, 'dog': 1, 'friends': 1, 'romans': 1, 'countrymen': 1, 'lend': 1, 'me': 1, 'ears': 1, 'give': 1, 'man': 1, 'fish': 2, 'you': 10, 'feed': 2, 'him': 3, 'for': 5, 'day': 2, 'show': 1, 'how': 2, 'to': 2, 'catch': 1, 'lifetime': 1, 'do': 2, 'make': 3, 'tissue': 1, 'dance': 1, 'put': 1, 'little': 1, 'boogie': 1, 'it': 3, 'i': 5, 'can': 3, 'run': 1, 'but': 6, 'not': 3, 'walk': 1, 'have': 4, 'mouth': 1, 'cannot': 2, 'talk': 1, 'bed': 1, 'sleep': 1, 'what': 2, 'am': 1, 'river': 1, 'jack': 1, 'all': 1, 'trades': 1, 'master': 1, 'none': 1, 'knock': 2, 'whos': 1, 'there': 1, 'etch': 2, 'who': 2, 'gesundheit': 1, 'laugh': 1, 'world': 1, 'laughs': 1, 'with': 4, 'weep': 2, 'alone': 1, 'sad': 1, 'old': 1, 'earth': 1, 'must': 1, 'borrow': 1, 'its': 2, 'mirth': 1, 'has': 1, 'trouble': 1, 'enough': 1, 'own': 1, 'everything': 1, 'as': 2, 'simple': 1, 'possible': 3, 'simpler': 1, 'no': 2, 'one': 2, 'see': 2, 'their': 1, 'reflection': 1, 'running': 1, 'water': 2, 'is': 7, 'only': 2, 'still': 1, 'that': 1, 'we': 4, 'once': 1, 'game': 1, 'over': 1, 'king': 1, 'pawn': 1, 'go': 3, 'back': 1, 'same': 2, 'box': 1, 'more': 1, 'matter': 2, 'attitude': 1, 'decision': 1, 'choose': 1, 'among': 1, 'impossible': 1, 'possibilities': 1, 'when': 2, 'sound': 1, 'opportunity': 1, 'becomes': 1, 'solution': 1, 'quid': 1, 'pro': 1, 'quo': 1, 'rain': 3, 'away': 1, 'come': 1, 'again': 1, 'another': 1, 'some': 1, 'people': 1, 'feel': 1, 'others': 1, 'just': 1, 'get': 1, 'wet': 1, 'best': 1, 'laid': 1, 'schemes': 1, 'mice': 1, 'men': 1, 'often': 1, 'awry': 1, 'leave': 1, 'us': 1, 'naught': 1, 'grief': 1, 'pain': 1, 'promised': 1, 'joy': 1, 'until': 1, 'peace': 1, 'youll': 1, 'never': 1, 'be': 1, 'content': 1, 'van': 1, 'gogh': 1, 'became': 1, 'painter': 1, 'because': 1, 'he': 1, 'had': 1, 'ear': 1, 'music': 1, 'solve': 1, 'our': 1, 'problems': 1, 'thinking': 1, 'used': 1, 'created': 1, 'them': 1, 'x': 1, 'marks': 1, 'spot': 1, 'yesterday': 1, 'canceled': 1, 'check': 1, 'tomorrow': 1, 'promissory': 1, 'note': 1, 'today': 1, 'cash': 1, 'so': 1, 'spend': 1, 'wisely': 1, 'zeal': 1, 'without': 2, 'knowledge': 1, 'fire': 1, 'light': 1} 

You can use the following text-file to test your answers: http://people.scs.carleton.ca/~arunka/courses/comp1005/assignments/a4/phrases.txt

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!