Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will write a program to solve the co-occurrence problem. The co-occurrence problem is stat- ed as follows. We have a file containing English

   
 

You will write a program to solve the co-occurrence problem. The co-occurrence problem is stat- ed as follows. We have a file containing English sentences, one sentence per line. Given a list of query words, your program should output the line number of lines that have all those words. Show your pointer prowess in completing this assignment. Assume the text in file contains only lowercase letters, does not have these punctuation charac- ters (; " * - ) and no digits. Ignore all other punctuation characters while processing the file. Here is one example. Assume that the following is the content of the file. Line numbers are in- cluded for clarity; the actual file doesn't have line numbers. 1. try not to become a man of success, but rather try to become a man of value. 2. look deep into nature, and then you will understand everything better. 3. the true sign of intelligence is not knowledge but imagination. 4. we cannot solve our problems with the same thinking we used when we created them. 5. weakness of attitude becomes weakness of character. 6. you can not blame gravity for falling in love. 7. the difference between stupidity and genius is that genius has its limits. (These are quotes from Albert Einstein. ) If we are asked to find all the lines that contain this set of words: {"knowledge", "imagination","true"} the answer will be line 3 because all three words appeared in line 3. If they appear in more than one line, your program should report all of them. For example, co-oc- currence of {"the", "is"} will be lines 3 and 7. Sample Output Test 1 Enter a file name: einstein.txt Enter space-separated words: the The co-occurance for word: the Lines: 3, 4, 7 Enter space-separated words: the is The co-occurance for words: the, is Lines: 3, 7 Enter space-separated words: true knowledge imagination The co-occurance for: true, knowledge, imagination Lines: 3 Enter space-separated words: q

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

Data Structures and Algorithm Analysis in Java

Authors: Mark A. Weiss

3rd edition

132576279, 978-0132576277

More Books

Students also viewed these Programming questions