Skip to content

Instantly share code, notes, and snippets.

@varunagrawal
Last active August 29, 2015 13:56
Show Gist options
  • Save varunagrawal/8826270 to your computer and use it in GitHub Desktop.
Save varunagrawal/8826270 to your computer and use it in GitHub Desktop.
NLP Hack for WishWasher
def bday_wish(message):
""" Analyze message to ascertain if it is a birthday wish
Params:
meassage: The message received from FB friend
"""
keywords = ["birthday", "birth", "happy", "bday", "hpy", "hbd", "hb", "happi", "best", "memorable", "awesome", "fantastic", "super", "bappy", "hirthday", "returns", "many", "bless", "god", "belated"]
expansion = {"hbd":["happy", "birthday"], "hb":["happy", "birthday"]}
s = ''.join(c for c in message if c not in string.punctuation and c in string.printable)
t = s.lower().split()
l = []
for x in t:
if x in expansion.keys():
l.extend(expansion[x])
else:
l.append(x)
count = 0
for x in l:
if x in keywords:
count += 1
continue
else:
for k in keywords:
if x.count(k):
count += 1
break
if count >= 2:
return True
else:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment