def get_subwords(word): logging.info(f"Iterating over permutations of {word}") print_and_say(word, next_voice=True) variations = variants(word) # skip = next(variations) for i, variant in enumerate(variations, start=1): prefix = f"{i}.\t" if variant in words: yield variant
def read_antonyms(word): antonyms = dictionary.antonym(word) if antonyms is None: print_and_say(f"No antonyms known for {word}.") else: print_and_say(f"Found {len(antonyms)} antonyms for {word}.") for n, antonym in enumerate(antonyms): print_and_say(antonym, print_prefix=f"\t{n + 1}.\t") yield antonym
def read_synonyms(word): synonyms = dictionary.synonym(word) if synonyms is None: print_and_say(f"No synonyms known for {word}.") else: print_and_say(f"Found {len(synonyms)} synonyms for {word}.") for n, synonym in enumerate(synonyms): print_and_say(synonym, print_prefix=f"\t{n + 1}.\t", print_suffix='.') yield synonym
def read_definitions(word): definition = dictionary.meaning(word) if definition is None: print_and_say(f"The definition for {word} is unknown.") unknown_words.add(word) else: for part_of_speech, meanings in definition.items(): print_and_say(f"{word}, the {part_of_speech}, has {len(meanings)} meanings.") for n, meaning in enumerate(meanings): print_and_say(f"\t{n + 1}.\t{meaning}") for related_word in meaning.split(" "): yield related_word
def lookup(word): print_and_say(word) for definition in urbandict.define(word): print_and_say(f"Definition: {definition['def']}", print_prefix="\t") for related_entry in filter(lambda rw: rw not in en_stopwords, definition['def'].split()): yield related_entry print_and_say(f"For example: {definition['example']}", print_prefix="\t") for related_entry in filter(lambda rw: rw not in en_stopwords, definition['example'].split()): yield related_entry
from random import sample, randint from string import ascii_letters from nltk.corpus import brown from misty.utils import print_and_say category = sample(brown.categories(), 3)[0] category = None # print_and_say(f"Selected {category} for sub words") logging.warning("Loading Brown University corpus of words") words = set(map(str.lower, brown.words(categories=category))) # nltk.corpus.brown print_and_say(f'Loaded {len(words)} "{category}" words.') def variants(charset): for l in range(len(charset), 1, -1): for combination in permutations(charset, l): yield ''.join(combination) def get_subwords(word): logging.info(f"Iterating over permutations of {word}") print_and_say(word, next_voice=True) variations = variants(word) # skip = next(variations) for i, variant in enumerate(variations, start=1): prefix = f"{i}.\t"
from yelpapi import YelpAPI from misty.utils import print_and_say YELP_API_KEY = 'h81ylaT0alwtJCUUyI7RazCCHNHleVGnhD9ZONPT1s4kL9v5qhCXPZrcI20H4LYisDEjJZu_j4ibEsSTpM2ISDpWBeraK3t42rwV_PhxtYvmatDn2xquIUKdueYtYHYx' # plz no steal my api keyz! client = YelpAPI(YELP_API_KEY) biz_ids = [ 'pierce-j-r-plumbing-co-inc-of-sacramento-rocklin', 'ncm-roseville', ] random.shuffle(biz_ids) for biz_id in biz_ids: result = client.business_query(id=biz_id) print_and_say( f"{result['name']}. Phone number: {result['display_phone']}. Address: {''.join(result['location']['display_address'])}", next_voice=True) reviews = client.reviews_query(id=result['id']) print_and_say( f"Retrieved {len(reviews['reviews'])} of {reviews['total']} reviews.", next_voice=True) for review in reviews['reviews']: print_and_say( f"On {review['time_created']} {review['user']['name']} gave a rating of {review['rating']} stars, stating: {review['text']}.", next_voice=True)
def lookup(word): word = "".join(x for x in word if x in set(string.ascii_letters)) print_and_say(word, print_prefix=bcolors.UNDERLINE + bcolors.BOLD, print_suffix=bcolors.END) yield from read_synonyms(word) yield from read_antonyms(word) yield from read_definitions(word)