Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dictionary module added #1

Merged
merged 5 commits into from
Apr 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__all__ = [
'movie',
'dictionary',
'joke',
'hello'
]
18 changes: 18 additions & 0 deletions modules/src/dictionary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import re
import requests

def match(input):
return bool(re.match(r'^.*\s+definition$', input))

def process(input):
output = {}
word = re.match(r'^(?P<definition>.*)\s+definition$', input).group('definition')
try:
r = requests.get("https://glosbe.com/gapi/translate?from=eng&dest=eng&format=json&phrase=" + word + "&pretty=true")
data = r.json()
output['input'] = input
output['output'] = "Definition of " + input + ": " + data['tuc'][0]['meanings'][0]['text']
output['success'] = True
except:
output['success'] = False
return output
9 changes: 9 additions & 0 deletions modules/tests/test_dictionary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from modules.src import dictionary

def test_joke():
assert(dictionary.match('jarvis definition') == True)
assert(dictionary.match('word definition') == True)
assert(dictionary.match('computer definition') == True)
assert(dictionary.match('definition definition') == True)
assert(dictionary.match('jarvis jarvis') == False)
assert(dictionary.match('something random') == False)