How do I verify an exact word occurs in a string?
I need to account for cases when a word such as "king" has a question mark immediately following as in the example below.
unigrams this should be False
In [1]: answer = "king"
In [2]: context = "we run with the king? on sunday"
n_grams this should be False
In [1]: answer = "king tut"
In [2]: context = "we run with the king tut? on sunday"
unigrams this should be True
In [1]: answer = "king"
In [2]: context = "we run with the king on sunday"
n_grams this should be True
In [1]: answer = "king tut"
In [2]: context = "we run with the king tut on sunday"
As people mentioned, for the unigram case we can handle it by splitting the string into a list, but that doesn't work for n_grams.
After reading some posts, I think I should attempt to handle using a look behind, but I'm not sure.