Question

In: Computer Science

In python, 1- Modify your mapper to count words after removing punctuation marks during mapping. Practice...

In python,

1- Modify your mapper to count words after removing punctuation marks during mapping.

Practice the given tasks in Jupyter notebook first before running them on AWS. If your program fails, check out stderr log file for information about the error.

import sys
sys.path.append('.')

for line in sys.stdin:
   line = line.strip() #trim spaces from beginning and end
   keys = line.split() #split line by space
   for key in keys:
       value = 1
       print ("%s\t%d" % (key,value)) #for each word generate 'word TAB 1' line

Solutions

Expert Solution

If you have any doubts, please give me comment...

#!/usr/bin/env python

#the above just indicates to use python to intepret this file

#This mapper code will input a line of text and output <word, 1> #

import sys

import string

sys.path.append('.')

count = 0

for line in sys.stdin:

    line = line.strip() #trim spaces from beginning and end

    keys = line.split() #split line by space

    for key in keys:

        value = 1

        key = key.translate(str.maketrans('','', string.punctuation))

        print ("%s\t%d" % (key,value))

        count += value

print("count of words: "+str(count))

Let me know, If it doesn't match with your output on AWS, I will help you...


Related Solutions

In python, Modify your mapper to count the number of occurrences of each character (including punctuation...
In python, Modify your mapper to count the number of occurrences of each character (including punctuation marks) in the file. Practice the given tasks in Jupyter notebook first before running them on AWS. If your program fails, check out stderr log file for information about the error. import sys sys.path.append('.') for line in sys.stdin:    line = line.strip() #trim spaces from beginning and end    keys = line.split() #split line by space    for key in keys:        value...
I need to,  Modify my mapper to count the number of occurrences of each character (including punctuation...
I need to,  Modify my mapper to count the number of occurrences of each character (including punctuation marks) in the file. Code below: #!/usr/bin/env python #the above just indicates to use python to intepret this file #This mapper code will input a line of text and output <word, 1> # import sys sys.path.append('.') for line in sys.stdin: line = line.strip() #trim spaces from beginning and end keys = line.split() #split line by space for key in keys: value = 1 print...
9. Modify the quicksort and mergesort programs we learnt during the class to count the number...
9. Modify the quicksort and mergesort programs we learnt during the class to count the number of element comparisons for the two sorting methods. Use the following test drive to test them. public class Sorts {    int numComparisions = 0;    public void quicksort(int [] x, int l, int h)    { // your modifies codes go here    }    public void mergesort(int [] x, int l, int h)    { // your modifies codes go here   ...
Provide the steps an auditor should follow during a stock count. [8 marks]
Provide the steps an auditor should follow during a stock count. [8 marks]
Question one: (25 marks) (Word count 200 words) Imagine you are a manager in an organization...
Question one: (Word count 200 words) Imagine you are a manager in an organization and one of your employee is in a meeting with you to discuss a situation that he faces at work: “Sir, can I have 10 minutes of your time? ….. My name is Racha and I’m facing a problem with one of my colleague Ahmed , we are supposed to be working together on a project to market and sell one of our brands, one of...
Question one: (25 marks) (Word count 200 words) Imagine you are a manager in an organization...
Question one: (Word count 200 words) Imagine you are a manager in an organization and one of your employee is in a meeting with you to discuss a situation that he faces at work: “Sir, can I have 10 minutes of your time? ….. My name is Racha and I’m facing a problem with one of my colleague Ahmed , we are supposed to be working together on a project to market and sell one of our brands, one of...
Your task is to count the frequency of words in a text file, and return the...
Your task is to count the frequency of words in a text file, and return the most frequent word with its count. For example, given the following text: there are two ways of constructing a software design one way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies. Based on the example your program should printout the following along with the...
Your task is to count the frequency of words in a text file, and return the...
Your task is to count the frequency of words in a text file, and return the most frequent word with its count. (Must use the code below without changing algorithms) For example, given the following text: there are two ways of constructing a software design one way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies. Based on the example your...
In Python b) Modify your program that reads 3 grades from the user (and computes the...
In Python b) Modify your program that reads 3 grades from the user (and computes the average and letter grade) so that it uses a while loop to read the 3 grades. In the loop body, you will just read one grade and update other variables appropriately. The loop header will ensure 3 iterations. c) Modify your program in part b so that it asks the user how many grades there are and uses a while loop to read that...
Question Two: (25 marks) (Word count 200 words) “A system” Name and explain any system that...
Question Two: (Word count 200 words) “A system” Name and explain any system that you deal with in real life, in your explanation use all what you have learned about the characteristics of a system, where all parts must be clear and applied.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT