-
Notifications
You must be signed in to change notification settings - Fork 990
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Major rewrite - now using NLP for query processing
- Loading branch information
1 parent
a13bd33
commit 9c1f53d
Showing
9 changed files
with
52 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
ACCESS_TOKEN = '<ACCESS_TOKEN>' | ||
VERIFY_TOKEN = '<VERIFY_TOKEN>' | ||
WIT_AI_SERVER_ACCESS_TOKEN = '<WIT_AI_SERVER_ACCESS_TOKEN>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,34 @@ | ||
import config | ||
import os | ||
import requests | ||
import sys | ||
from src import * | ||
|
||
WIT_AI_SERVER_ACCESS_TOKEN = os.environ.get('WIT_AI_SERVER_ACCESS_TOKEN', config.WIT_AI_SERVER_ACCESS_TOKEN) | ||
|
||
def process_query(input): | ||
try: | ||
r = requests.get('https://api.wit.ai/message?v=20160420&q=' + input, headers={ | ||
'Authorization': 'Bearer %s' % WIT_AI_SERVER_ACCESS_TOKEN | ||
}) | ||
data = r.json() | ||
intent = data['outcomes'][0]['intent'] | ||
entities = data['outcomes'][0]['entities'] | ||
confidence = data['outcomes'][0]['confidence'] | ||
if intent in src.__all__ and confidence > 0.5: | ||
return intent, entities | ||
else: | ||
return None, {} | ||
except: | ||
return None, {} | ||
|
||
def search(input): | ||
for module in src.__all__: | ||
if sys.modules['modules.src.' + module].match(input): | ||
data = sys.modules['modules.src.' + module].process(input) | ||
if data['success']: | ||
return data['output'] | ||
return 'I\'m still learning. Check back later!' | ||
intent, entities = process_query(input) | ||
if intent is not None: | ||
data = sys.modules['modules.src.' + intent].process(input, entities) | ||
if data['success']: | ||
return data['output'] | ||
else: | ||
return 'Something didn\'t work as expected! I\'ll report this to my master.' | ||
else: | ||
return 'I\'m still learning. Check back later!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
__all__ = [ | ||
'movie', | ||
'dictionary', | ||
# 'dictionary', | ||
'joke', | ||
'hello' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
from modules.src import hello | ||
import modules | ||
|
||
def test_joke(): | ||
assert(hello.match('Are you there?') == True) | ||
assert(hello.match('Hi, Jarvis!') == True) | ||
assert(hello.match('hello') == True) | ||
assert(hello.match('jarvis jarvis') == False) | ||
assert(hello.match('something random') == False) | ||
def test_hello(): | ||
assert('hello' == modules.process_query('hello')[0]) | ||
assert('hello' == modules.process_query('Hi, Jarvis!')[0]) | ||
assert('hello' == modules.process_query('Are you there?')[0]) | ||
assert('hello' != modules.process_query('something random')[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
from modules.src import joke | ||
import modules | ||
|
||
def test_joke(): | ||
assert(joke.match('tell me a joke') == True) | ||
assert(joke.match('random jokes') == True) | ||
assert(joke.match('Do you know a joke?') == True) | ||
assert(joke.match('joke is the') == False) | ||
assert(joke.match('something random') == False) | ||
assert('joke' == modules.process_query('tell me a joke')[0]) | ||
assert('joke' == modules.process_query('Do you know a joke?')[0]) | ||
assert('joke' == modules.process_query('random jokes')[0]) | ||
assert('joke' != modules.process_query('something random')[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
from modules.src import movie | ||
import modules | ||
|
||
def test_movie(): | ||
assert(movie.match('happyness movie') == True) | ||
assert(movie.match('batman movie') == True) | ||
assert(movie.match('happyness') == False) | ||
assert(movie.match('movie') == False) | ||
assert(movie.match('something random') == False) | ||
assert('movie' == modules.process_query('batman movie')[0]) | ||
assert('movie' == modules.process_query('iron man 2 movie plot')[0]) | ||
assert('movie' == modules.process_query('What is the rating of happyness movie?')[0]) | ||
assert('movie' != modules.process_query('something random')[0]) |