I'm new to NLTK and was wondering if anyone would be able to help me in solving the following situation:
I'm working on a corpus of new articles and have texts in the following format:
t= "While at a rally in Wilmington, Republican presidential nominee Donald Trump made a clear insinuation that Democratic nominee Hillary Clinton has to keep away from becoming president"
and have following code in place:
from nltk.tokenize import word_tokenize
from nltk.tokenize import MWETokenizer
mwetokenizer = MWETokenizer([('Donald','Trump')], separator=' ')
mwetokenizer.add_mwe(('Hillary','Clinton'))
mwetokenized_sentence = mwetokenizer.tokenize(word_tokenize(t))
print(mwetokenized_sentence)
Which gives the following result:
['While', 'at', 'a', 'rally', 'in', 'Wilmington', ',', 'Republican', 'presidential', 'nominee', 'Donald Trump', 'made', 'a', 'clear', 'insinuation', 'that', 'Democratic', 'nominee', 'Hillary Clinton', 'has', 'to', 'keep', 'away', 'from', 'becoming', 'president']
As we can see the words "Hillary Clinton" and "Donald trump" are together which is as required/expected.
Is there any way that I can figure out similar multi-words in an entire corpus of sentences without looking at individual text?