Skip to content

Instantly share code, notes, and snippets.

@HandcartCactus
Last active March 19, 2021 15:33
Show Gist options
  • Save HandcartCactus/2abf949196250bdceb76ca02b2ffc3dd to your computer and use it in GitHub Desktop.
Save HandcartCactus/2abf949196250bdceb76ca02b2ffc3dd to your computer and use it in GitHub Desktop.
All possible "Darth *" puns, computed using NLTK and a word list.
"""
Prints all possible puns of the form: "Darth *" Where * is every word that both
starts with "in" and has a negative-connotation, with the "in" removed. This is
based on a joke about the pattern of naming for most sith in the Star Wars franchise, such as
Darth Sidious (i.e. insidious) or Darth Vader (i.e. invader). The results are
funny, I promise. My favorite is "Darth Fection".
"""
import requests as r
import numpy as np
import nltk
from nltk.sentiment import SentimentIntensityAnalyzer
from nltk.stem import WordNetLemmatizer
# get word list
words_raw = r.get("https://raw.githubusercontent.com/MagicOctopusUrn/wordListsByLength/master/unsorted.txt")
words = str(words_raw.content).split('\\r\\n')
# instantiate nltk elements
nltk.download('wordnet')
sia = SentimentIntensityAnalyzer()
wnl = WordNetLemmatizer()
# tests for if words fit the format
is_negative_word = lambda w: bool(sia.polarity_scores(w)['neg'])
is_root = lambda w: wnl.lemmatize(w) == w # removes some duplicates
prefix_in = lambda w: w[:2]=="in"
# find words that fit the format
neg_inwords = [w for w in words if is_negative_word(w) and prefix_in(w) and is_root(w)]
# convert words
darth_names = [f"Darth {w[2:].capitalize()}" for w in neg_inwords]
for pun in darth_names:
print(pun)
@HandcartCactus
Copy link
Author

Darth Sipid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment