I need to find a good mechanism to extract a specific word (provided by user) and 7 words on each side of the word. For example if we have the following text
text = "The mean distance of the Sun from the Earth is approximately 149.6 million kilometers (1 AU), though the distance varies as the Earth moves from perihelion in January to aphelion in July"
and if the user type the word “Earth”, I should be able to extract the following part of the text
mean distance of the Sun from the Earth is approximately 149.6 million kilometers (1 AU)
So as you can see the word “Earth” surrounded by 7 words on each side. How can I do this in Java?
1 Answer