Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to modify the program below? The goal of this lab is to modify lab.py so that it generates exactly the same output as lab.out

How to modify the program below?

The goal of this lab is to modify lab.py so that it generates exactly the same output as lab.out when it analyzes SCOF.txt.Put pasttenseConfig.py in the same directory as lab.py.

lab.py:

import re

from pasttenseconfig import endsED, irregularVerbs

def matchPast(line, lineNum):

'''

Displays possible past tense verbs on line of text

Parameters:

Return value: None

'''

#Edit the compiled regular expression to capture any of the list of

# irreregular verbs, delimited by a white space character at the

# start, and a white space character, a period, or a comma at the end.

# Use irregularVerbs from pastTenseConfig

#

irregularVerb = re.compile(r' been ')

iMatches = irregularVerb.finditer(line)

#Edit the compiled regular expression to capture a regular past tense

# verb, defined as a word ending in 'ed' that is NOT one of the

# non-verbs in the endED list (e.g., 'red').As with irregular verbs, the regular

# verb must bedelimited by a white space character at the start,

#and a white space character, a period, or a comma at the end.

#

regularVerb = re.compile(r' banned ')

rMatches = regularVerb.finditer(line)

first = False

for match in iMatches:

if not first:

first = True

print (" ",lineNum, line[:-1])

#Edit the print statement below so that it also displays the starting

# and ending position of the match

print (match.group())

for match in rMatches:

if not first:

first = True

print (" ",lineNum, line[:-1])

#Edit the print statement below so that it also displays the starting

# and ending position of the match

print (match.group())

if __name__ == '__main__':

while True:

filename = input('Enter file to check, or hit enter to quit: ')

if filename == '': break

try:

f = open(filename, 'r')

except:

print(f'Could not open "{filename}" for reading')

continue

print(f'Looking for past tense verbs in "{filename}" ...')

lineNum = 1

for line in f.readlines():

matchPast(line, lineNum)

lineNum += 1

print(f'... "{filename}" verb analysis complete ')

pasttenseConfig.py:

import re

endsED = ['red', 'bed', 'ted', 'led', 'bed', 'moped', 'oled', 'med']

irregularVerbs = ['caught', 'taught', 'bought', 'was', 'were', 'been',

'became', 'came', 'dealt', 'drew', 'drank', 'fought', 'flew', 'heard', 'hit',

'meant', 'lost', 'misread', 'wrote', 'bid', 'slept', 'spent', 'drank', 'saw',

'paid', 'put', 'made', 'took', 'shut', 'struckwore', 'thought']

SCOF.txt:

JAD ABUMRAD: Three, two, one. Hey. I'm Jad Abumrad. This is

RADIOLAB. Today, we have got a special collaboration with The New Yorker

magazine and The New Yorker Radio Hour - very excited. So for

the last several years, we here at RADIOLAB - and by we, I mean mainly

Simon Adler - he - we have been watching and reporting on Facebook -

specifically, how Facebook decides and then enforces what people can and

cannot post on their site. As many of you know, the way that they do it

is they've got this rule book, one single set of rules for the many

countries in the globe that define what is postable and what isn't. And

then they have a giant army of 15,000 souls who have to moderate all the

crip that we put on Facebook. Anyhow, in doing so, Facebook has managed

to getoff, well, just about everybody.

JAD ABUMRAD: I mean, despite all of the time, effort and money that they have thrown at this problem by taking posts down...

UNIDENTIFIED PERSON #4: ...Censorship of...

JAD ABUMRAD: ...They have been accused of censoring voices across the political spectrum and infringing on users' right to free expression.

UNIDENTIFIED REPORTER #1: The site won't let them post pictures nursing their...

UNIDENTIFIED REPORTER #2: ...Enemies of the First Amendment.

JAD ABUMRAD: And then by leaving material up...

UNIDENTIFIED REPORTER #3: ...Used to incite violence against Rohingya refugees.

UNIDENTIFIED PERSON #6: Investigators blame Facebook.

JAD ABUMRAD: ...They've been accused of helping to incite a genocide in Myanmar...

UNIDENTIFIED REPORTER #4: Big stories influence the election.

JAD ABUMRAD: ...And arguably swing the 2016 U.S. presidential election.

UNIDENTIFIED PERSON #7: (Unintelligible).

UNIDENTIFIED PERSON #8: We're working on this. The most impactful decision...

UNIDENTIFIED PERSON #9: Global struggle...

JAD ABUMRAD: And I start here with this wrap-up because since we last

reported on all of that, Facebook has actually made a pretty big shift

in how they are going to approach policing, refereeing the world's

speech. It's a shift that - it's going to have a massive impact on their

decisions about what is and is not allowed, including the

question - which we'll talk about in a second - of whether former

President Trump should be banned indefinitely from Facebook. But more

deeply, this is a shift that has Facebook really looking less like a

company and, oddly, a little bit more like a government, an unelected

government for the entire planet. So with all of that, let me now hand

off to...

MARCIA BELSKY: The photo is me as what can only be described as a cherub - cute little 7-year-old with big curly hair. And she's wearing this blue floral dress. Her teeth are all messed up.

SIMON ADLER: And into the photo, Marcia had edited in a speech bubble.

MARCIA BELSKY: That just says, kill all men. And so it's funny because a hit, a hit - it's funny, you know. Trust me. Whatever.

SIMON ADLER: Facebook had taken it down because it violated their hate speech policy.

lab.out:

Enter file to check, or hit enter to quit: Looking for past tense verbs in "SCOF.txt" ...

3 magazine and The New Yorker Radio Hour - very excited. So for

excited. (45, 54)

5 Simon Adler - he - we have been watching and reporting on Facebook -

been(26, 32)

11 crip that we put on Facebook. Anyhow, in doing so, Facebook has managed

put(12, 17)

managed

(63, 72)

19 JAD ABUMRAD: ...They have been accused of censoring voices across the political spectrum and infringing on users' right to free expression.

been(25, 31)

accused(30, 39)

32 JAD ABUMRAD: ...They've been accused of helping to incite a genocide in Myanmar...

been(23, 29)

accused(28, 37)

46 reported on all of that, Facebook has actually made a pretty big shift

made(46, 52)

49 decisions about what is and is not allowed, including the

allowed, (34, 43)

51 President Trump should be banned indefinitely from Facebook. But more

banned(25, 33)

53 company and, oddly, a little bit more like a government, an unelected

unelected

(59, 70)

58 MARCIA BELSKY: The photo is me as what can only be described as a cherub - cute little 7-year-old with big curly hair. And she's wearing this blue floral dress. Her teeth are all messed up.

described(50, 61)

messed(178, 186)

60 SIMON ADLER: And into the photo, Marcia had edited in a speech bubble.

edited(43, 51)

62 MARCIA BELSKY: That just says, kill all men. And so it's funny because a hit, a hit - it's funny, you know. Trust me. Whatever.

hit, (72, 77)

hit(79, 84)

64 SIMON ADLER: Facebook had taken it down because it violated their hate speech policy.

violated(50, 60)

... "SCOF.txt" verb analysis complete

Enter file to check, or hit enter to quit:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

App Inventor

Authors: David Wolber, Hal Abelson

1st Edition

1449397484, 9781449397487

More Books

Students also viewed these Programming questions

Question

Apply the distributive property to 4 - (5 - 4x).

Answered: 1 week ago

Question

What are the degrees of freedom associated with ????e.

Answered: 1 week ago