Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

cleaning some code #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ def test_meaning_valid_phrase(self):
result = '[{"seq": 0, "text": "Present participle of hum."}]'
middle_val = json.loads(result)
expected_result = json.dumps(middle_val)
if sys.version_info[:2] <= (2, 7): ## python 2
if sys.version_info[:2] <= (2, 7): ## python 2
self.assertItemsEqual(current_result, expected_result)
else: # python 3
"""
assertItemsEqual() was renamed to assertCountEqual()
Why I am not using assertEqual() here?
assertItemsEqual() was renamed to assertCountEqual()
Why I am not using assertEqual() here?

Reference:
Reference:
- http://stackoverflow.com/a/7473137/3834059
- https://docs.python.org/2/library/unittest.html#unittest.TestCase.assertItemsEqual
- https://docs.python.org/3/library/unittest.html?highlight=assertcountequal#unittest.TestCase.assertCountEqual
Expand All @@ -37,7 +37,7 @@ def test_meaning_valid_phrase(self):
def test_meaning_not_valid_phrase(self):
current_result = vb.meaning("sxsw")
self.assertFalse(current_result)

def test_synonym_valid_phrase(self):
current_result = vb.synonym("repudiate")
result = '[{"seq": 0, "text": "deny"}]'
Expand All @@ -51,7 +51,7 @@ def test_synonym_valid_phrase(self):
def test_synonym_not_valid_phrase(self):
current_result = vb.synonym("sxsw")
self.assertFalse(current_result)

def test_antonym_valid_phrase_1(self):
current_result = vb.antonym("love")
result = '{"text": ["hate"]}'
Expand Down
22 changes: 4 additions & 18 deletions vocabulary/vocabulary.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __parse_content(tuc_content, content_to_be_parsed):
## for 'meanings', 'contents_raw' is a list
for meaning_content in contents_raw:
initial_parsed_content[i] = meaning_content['text']
i +=1
i += 1

final_parsed_content = {}
## removing duplicates(if any) from the dictionary
Expand Down Expand Up @@ -178,7 +178,6 @@ def meaning(phrase, source_lang="en", dest_lang="en"):
return False
'''get meanings'''
meanings_list = Vocabulary.__parse_content(tuc_content, "meanings")
# return meanings_list
return json.dumps(meanings_list)
else:
return False
Expand All @@ -204,13 +203,8 @@ def synonym(phrase, source_lang="en", dest_lang="en"):
return False
synonyms_list = Vocabulary.__parse_content(tuc_content, "phrase")
if synonyms_list:
# return synonyms_list
return json.dumps(synonyms_list)
else:
return False

else:
return False
return False

## TO-DO:
## if this gives me no results, will query "bighugelabs"
Expand Down Expand Up @@ -241,12 +235,8 @@ def translate(phrase, source_lang, dest_lang):
return False
translations_list = Vocabulary.__parse_content(tuc_content, "phrase")
if translations_list:
# return synonyms_list
return json.dumps(translations_list)
else:
return False
else:
return False
return False



Expand Down Expand Up @@ -295,7 +285,6 @@ def antonym(phrase):
final_dictionary[key] = value
antonyms.append(final_dictionary)

# return json.dumps(final_dictionary)
return final_dictionary
else:
return False
Expand Down Expand Up @@ -327,7 +316,6 @@ def part_of_speech(phrase):
final_list.append({ "seq": i, "text": key, "example:" :value})
i += 1
return json.dumps(final_list)
# return final_list
else:
return False
else:
Expand All @@ -352,7 +340,6 @@ def usage_example(phrase):
if word_examples:
## reforamatting "word_examples" using "__clean_dict()"
return json.dumps(Vocabulary.__clean_dict(word_examples))
# return Vocabulary.__clean_dict(word_examples)
else:
return False
else:
Expand All @@ -373,7 +360,7 @@ def pronunciation(phrase):
'''
Refer : http://stackoverflow.com/questions/18337407/saving-utf-8-texts-in-json-dumps-as-utf8-not-as-u-escape-sequence
'''
## TODO: Fix the unicode issue mentioned in
## TODO: Fix the unicode issue mentioned in
## https://github.com/prodicus/vocabulary#181known-issues
if sys.version_info[:2] <= (2, 7): ## python2
return json_obj
Expand All @@ -396,6 +383,5 @@ def hyphenation(phrase):
json_obj = Vocabulary.__return_json(url)
if json_obj:
return json.dumps(json_obj)
# return json_obj
else:
return False