Text:
some text some text Jack is the CEO. some text some text John DOE is the CEO.
Function to find all the 'is the CEO' in the text.
def get_ceo(text):
results = re.findall(r"is the CEO", text)
for i in results:
range = text[i-15:i]
print(range)
With get_ceo, I want to extract the result of findall + 15 characters of the text preceding it. I'm putting an arbitrary number of characters and I'll then perform an entity extraction with NLP on the range returned for each result.
Desired output:
['some text Jack is the CEO',' text John DOE is the CEO']
Here is the error I'm getting with the function:
line 62, in <module>
print(get_ceo(text))
line 50, in get_ceo
range = text[i-15:i]
TypeError: unsupported operand type(s) for -: 'str' and 'int'
Do I need to convert the result of the findall function into a different type or change the approach completely?