How to check the exact word in a string?
I need to consider cases where the word "king" has a question mark following it, as in the example below.
unigrams , it must be False
In [1]: answer = "king"
In [2]: context = "we run with the king? on sunday"
n_grams , it should be False
In [1]: answer = "king tut"
In [2]: context = "we run with the king tut? on sunday"
unigrams , it must be True
In [1]: answer = "king"
In [2]: context = "we run with the king on sunday"
n_grams , it must be True
In [1]: answer = "king tut"
In [2]: context = "we run with the king tut on sunday"
As mentioned above, for the case of unigram, we can handle this by dividing the string into a list, but this does not work for n_grams.
After reading some posts, I think I should try to process using the look, but I'm not sure.