There are a bunch of questions that get at extracting a particular sentence that contains a word (like extract a sentence using python and Python extract sentence containing word), and I have enough beginner experience with NLTK and SciPy to be able to do that on my own.
However, I'm getting stuck trying to extract a sentence containing a word... as well as the sentences before and after the target sentence.
For example:
"I was walking along to school the other day, when it began to rain. I reached for my umbrella, but I realized I had forgotten it at home. What could I do? I immediately ran for the nearest tree. But then I realized I couldn't stay try with a tree without any leaves."
In this example, the target word is "could." If I wanted to extract the target sentence (What could I do?) as well as the preceding and following sentences (I reached for my umbrella, but I realized I had forgotten it at home. and I immediately ran for the nearest tree.), what would be a good approach?
Assume I have each paragraph sectioned off as its own text...
for paragraph in document:
do something
... is there a proper way to tackle this question? I have about 10,000 paragraphs with varying numbers of sentences around the target word (which appears is every single paragraph).