-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the Define.py file, a MethodTest file and a ReadMe.
- Loading branch information
1 parent
d32a578
commit 7556578
Showing
3 changed files
with
71 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#Written by Jake Schultz | ||
import re | ||
from urllib2 import Request, urlopen, URLError | ||
import json | ||
|
||
WORDS = ["DEFINE"] | ||
|
||
PRIORITY = 1 | ||
|
||
|
||
def handle(text, mic, profile): | ||
|
||
dict_key = profile['keys']['YANDEX_DICT'] | ||
|
||
get_def(text,mic,dict_key) | ||
|
||
|
||
def get_def(text,mic,key): | ||
mic.say("What word would you like to define?") | ||
theWord = mic.activeListen() | ||
|
||
request = Request('https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key='+key+'&lang=en-en&text='+theWord) | ||
try: | ||
response = urlopen(request) | ||
data = json.load(response) | ||
word_type = data["def"][0]["pos"] | ||
mic.say("The word is a " + word_type) | ||
defs = data["def"][0]["tr"] | ||
for text in defs: | ||
mic.say(text["text"]) | ||
except URLError, e: | ||
mic.say("Unable to reach dictionary API.") | ||
|
||
|
||
def isValid(text): | ||
return bool(re.search(r'\Define\b',text, re.IGNORECASE)) |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from urllib2 import Request, urlopen, URLError | ||
import json | ||
from pprint import pprint | ||
|
||
key = '' | ||
|
||
|
||
def get_def(text,key): | ||
request = Request('https://dictionary.yandex.net/api/v1/dicservice.json/lookup?key='+key+'&lang=en-en&text='+text) | ||
try: | ||
response = urlopen(request) | ||
data = json.load(response) | ||
word_type = data["def"][0]["pos"] | ||
defs = data["def"][0]["tr"] | ||
for text in defs: | ||
print text["text"] | ||
except URLError, e: | ||
print 'Unable to get translation', e | ||
|
||
get_def('insect', key) |
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,16 @@ | ||
# jasper-dictionary | ||
A jasper module that defines a given word. | ||
|
||
jasper-dictionary is a jasper module that allows you to get the definition of a given word or phrase. It uses the Yandex Translate API (Free) to define words. | ||
|
||
Usage: | ||
|
||
- You: Jasper, Define | ||
- Japser: What word would you like to define? | ||
- You: Dog | ||
- Jasper: Lists definitions | ||
|
||
### Installation | ||
- Get an API Key - https://tech.yandex.com/dictionary/doc/dg/concepts/api-overview-docpage/ | ||
- Add the key to the Jasper .profile under keys as "YANDEX_DICT" | ||
- Add the Define.py file to the /client/modules dir. | ||
- THATS IT! |