Skip to content

Instantly share code, notes, and snippets.

@josht-jpg
Last active September 2, 2020 19:23
Show Gist options
  • Save josht-jpg/1ca8fde834ed957ec31fa6af6c7a690e to your computer and use it in GitHub Desktop.
Save josht-jpg/1ca8fde834ed957ec31fa6af6c7a690e to your computer and use it in GitHub Desktop.
providing_context
keep_words = ['no', 'not']
stop_words_context = [w for w in stop_words if w not in keep_words]
negations = ['not', 'no', 'never', 'without']
def bigram(book):
book_context = clean(book, stop_words_context)
book_bigrams = pd.DataFrame(list(nltk.bigrams(book_context['word'])),
columns = ['word1', 'word2'])
return book_bigrams
notes_bigrams = bigram(notes)
crime_bigrams = bigram(crime)
idiot_bigrams = bigram(idiot)
possessed_bigrams = bigram(possessed)
brothers_bigrams = bigram(brothers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment