Question: 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 

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

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 Programming Questions!