Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Python program that given a keyword and a text file, will print out all the contexts where the keyword appears in the file.

Write a Python program that given a keyword and a text file, will print out all the contexts where the keyword appears in the file. We define a context of a keyword as the two words that precede it and the two words that immediately follow it, if they exist. For example, if the given keyword is "keyword" and the input file contains the description of this project, then its contexts should include

"given a keyword and a"

"where the keyword appears in"

"precede the keyword and the"

"the given keyword is "keyword""

Your program should take the file name as a command line argument. It should repeatedly ask for a new keyword from the user until 'Q' is entered to terminate the program. When a keyword is given, your program should output in the console, all of the contexts where this keyword appears in the input file, one per line.

You are required to use a dictionary that maps each keyword to the collection of its contexts.

To test your solution, create three small input files for which you know what the expected output should be. Once this is done successfully, test your program with the bible file that I post with this assignment to ensure that your program still works and that it is fast enough.

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago