-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3be9e1
commit 15ac52c
Showing
13 changed files
with
206 additions
and
47 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
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import urllib.request | ||
import json | ||
import unicodedata | ||
|
||
URL = 'https://googledictionaryapi.eu-gb.mybluemix.net/' | ||
|
||
''' | ||
Searching the word in Google Dictionary API (unofficial) | ||
:param word - the given word | ||
''' | ||
|
||
|
||
def getWordFromGoogleDictionary(word, trace = False): | ||
# Trace | ||
if trace is True: | ||
print("\t\tChecking Google dictionary for the word: \"" + word + "\"") | ||
|
||
# Replacing non-eng chars | ||
word = unicodedata.normalize('NFKD', word).encode('ascii', 'ignore').decode('utf8') | ||
|
||
url = URL + '?define=' + word + '&lang=en' | ||
|
||
meanings = [] | ||
|
||
try: | ||
request = urllib.request.Request(url) | ||
response = urllib.request.urlopen(request) | ||
content = response.read().decode('utf-8') | ||
contentJson = json.loads(content) | ||
|
||
for res in contentJson: | ||
meaning = res['meaning'] | ||
|
||
for key in meaning.keys(): | ||
for definition in meaning[key]: | ||
meanings.append(definition['definition']) | ||
|
||
except Exception as e: | ||
pass | ||
|
||
# Trace | ||
if trace is True and len(meanings) == 0: | ||
print("\t\tNo results from Google dictionary for the word: \"" + word + "\"\n") | ||
|
||
# Returning word | ||
word = { | ||
"word": word, | ||
"syn": [], | ||
"ant": [], | ||
"def": meanings, | ||
"examples": [] | ||
} | ||
|
||
return word | ||
|
||
|
||
# TEST | ||
# print(getWordFromGoogleDictionary('İSN\'T')) | ||
|
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
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
Oops, something went wrong.