Skip to content

Instantly share code, notes, and snippets.

@enginebai
Created June 21, 2017 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enginebai/361e806f8ae3c53106e0d5652a19782b to your computer and use it in GitHub Desktop.
Save enginebai/361e806f8ae3c53106e0d5652a19782b to your computer and use it in GitHub Desktop.
NLP module in Facebook messager bot
class Intent(Enum):
HELP = "help"
WORKS_PRIMARY = "works_primary"
WORKS_SECONDARY = "works_secondary"
PROJECTS = "projects"
OPEN_SOURCES = "open_sources"
JOBS = "jobs"
ARTICLES = "articles"
SPEECH = "speech"
REPORT = "report"
ADVANTAGES = "advantages"
PERSONALITY = "personality"
CONTACT_ME = "contact_me"
CONFUSED = "confused"
def parse_sentence(message):
if "quick_reply" in message:
print("quick_reply", message["quick_reply"])
return message["quick_reply"]["payload"]
elif "text" in message:
resp = wit_client.message(message["text"])
print("wit", resp["entities"])
print("wit", resp)
intents = resp["entities"]["intent"]
intent_values = set()
# add intent values with high confidence
for intent in intents:
if float(intent["confidence"]) > 0.9:
print("intent value", intent["value"])
intent_values.add(intent["value"])
print(intent_values)
if {"嗨"} <= intent_values:
return Intent.HELP.name
elif {"報導"} <= intent_values:
return Intent.REPORT.name
elif {"專案"} <= intent_values:
return Intent.WORKS_PRIMARY.name
else:
return Intent.HELP.name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment