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

Commit

Permalink
Merge pull request #25 from tenorz007/feature/response-handler
Browse files Browse the repository at this point in the history
Feature/response handler added 

## Version 0.0.6

- Added support for specifying response format
- Bug fixes
- PEP8 and flake enhancements
- Adding a new demo gif 

Fixes #23 #4
  • Loading branch information
prodicus committed Apr 1, 2017
2 parents 0040998 + ed466de commit 7573f21
Show file tree
Hide file tree
Showing 13 changed files with 264 additions and 58 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ Changelog
- Added `translate` module
- Improved Documentation
- Minor bug fixes

0.0.6
~~~~~

- Added support for specifying response format
10 changes: 5 additions & 5 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Contributing

1. Fork it.

2. Clone it
2. Clone it

create a `virtualenv <http://pypi.python.org/pypi/virtualenv>`__
create a `virtualenv <http://pypi.python.org/pypi/virtualenv>`__

.. code:: bash
Expand Down Expand Up @@ -36,19 +36,19 @@ Or, if ``virtualenv`` is not installed on your system:
(develop) $ ./tests.py -v
Conform to `PEP8 <https://www.python.org/dev/peps/pep-0008/>`__ and if everything is running fine, integrate your feature
Conform to `PEP8 <https://www.python.org/dev/peps/pep-0008/>`__ and if everything is running fine, integrate your feature

6. Push to the branch (``$ git push origin my-new-awesome-feature``)

7. Create new Pull Request

Hack away!
Hack away!

To do
~~~~~

- [X] Add translate module
- [] Add an option like `JSON=False` or `JSON=True` where the former returns a list object
- [X] Add an option like `JSON=False` or `JSON=True` where the former returns a list object

Tests
~~~~~
Expand Down
14 changes: 8 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.. figure:: http://i.imgur.com/ddxYie4.jpg
:alt:
:alt:

Vocabulary
==========

|PyPI version| |License| |Python Versions| |Build Status| |Requirements Status| |Gitter chat|
|PyPI version| |License| |Python Versions| |Build Status| |Requirements Status| |Gitter chat|

A dictionary magician in the form of a module!

Expand Down Expand Up @@ -43,7 +43,7 @@ Features
`[back to top] <https://github.com/prodicus/vocabulary#vocabulary>`__

- Written in uncomplicated ``Python``
- Returns ``JSON`` objects
- Returns ``JSON`` objects, ``PYTHON`` dictionaries and lists
- Minimum dependencies ( just uses `requests <https://github.com/kennethreitz/requests>`__ module )
- Easy to
`install <https://github.com/prodicus/vocabulary#installation>`__
Expand Down Expand Up @@ -110,7 +110,7 @@ Let's say you want to find out the synonyms for the word ``car``.
>>> car_synonyms = json.loads(vb.synonym("car"))
>>> type(car_synonyms)
<class 'list'>
>>>
>>>
So there you go. You get the data in an easy ``JSON`` format.

Expand Down Expand Up @@ -152,6 +152,8 @@ Demo
.. figure:: https://raw.githubusercontent.com/prodicus/vocabulary/master/assets/usage.gif
:alt: Demo link

.. figure:: https://raw.githubusercontent.com/prodicus/vocabulary/master/assets/usage-format.gif
:alt: Demo link

Documentation
-------------
Expand Down Expand Up @@ -207,7 +209,7 @@ Known Issues
~~~~~~~~~~~~
`[back to top] <https://github.com/prodicus/vocabulary#vocabulary>`__

- In **python2**, when using the method **Vocabulary.pronunciation()**
- In **python2**, when using the method **Vocabulary.pronunciation()**

.. code:: python
Expand Down Expand Up @@ -245,7 +247,7 @@ License :
---------
`[back to top] <https://github.com/prodicus/vocabulary#vocabulary>`__

Built with ♥ by `Tasdik Rahman <http://tasdikrahman.me/>`__ under the `MIT License <http://prodicus.mit-license.org/>`__ ©
Built with ♥ by `Tasdik Rahman <http://tasdikrahman.me/>`__ under the `MIT License <http://prodicus.mit-license.org/>`__ ©

You can find a copy of the License at http://prodicus.mit-license.org/

Expand Down
Binary file added assets/usage-format.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ Changelog

.. versionadded:: 0.0.5

- Added ``Vocabulary.translate()``
- Added ``Vocabulary.translate()``
- Improved Documentation
- Minor bug fixes

0.0.6
~~~~~

.. versionadded:: 0.06

- Added support for specifying response format
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@
# built documents.
#
# The short X.Y version.
version = '0.0.5'
version = '0.0.6'
# The full version, including alpha/beta/rc tags.
release = '4'
release = '5'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
12 changes: 6 additions & 6 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Contributing

1. Fork it.

2. Clone it
2. Clone it

create a `virtualenv <http://pypi.python.org/pypi/virtualenv>`__
create a `virtualenv <http://pypi.python.org/pypi/virtualenv>`__

.. code-block:: bash
Expand Down Expand Up @@ -37,19 +37,19 @@ Or, if ``virtualenv`` is not installed on your system:
(develop) $ ./tests.py -v
Conform to `PEP8 <https://www.python.org/dev/peps/pep-0008/>`__ and if everything is running fine, integrate your feature
Conform to `PEP8 <https://www.python.org/dev/peps/pep-0008/>`__ and if everything is running fine, integrate your feature

6. Push to the branch (``$ git push origin my-new-awesome-feature``)

7. Create new Pull Request

Hack away!
Hack away!

To do
=====

- [X] Add translate module
- [ ] Add an option like `JSON=False` or `JSON=True` where the former returns a list object
- [X] Add an option like `JSON=False` or `JSON=True` where the former returns a list object

Tests
=====
Expand Down Expand Up @@ -90,5 +90,5 @@ if you want to chat or if you have any questions.
Contributers
============

- Thanks to `Anton Relin <https://github.com/relisher>`__ for adding the `translate()` module
- Thanks to `Anton Relin <https://github.com/relisher>`__ for adding the `translate()` module
- A big shout out to all the `contributers <https://github.com/prodicus/vocabulary/graphs/contributors>`__
4 changes: 2 additions & 2 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ If you are behind a proxy

.. code-block:: bash
$ sudo apt-get install python-pip
$ sudo apt-get install python-pip
should fix that

Expand All @@ -40,7 +40,7 @@ Option 2: Installing from source
Upgrade
=======

You can update to the latest version by doing a
You can update to the latest version by doing a

.. code-block:: bash
Expand Down
17 changes: 14 additions & 3 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ Usage Examples

A Simple demonstration of the module

.. code-block:: python
.. code-block:: python
## Importing the module
>>> from vocabulary import Vocabulary as vb
## Extracting "Meaning"
>>> vb.meaning("hillbilly")
'[{"text": "Someone who is from the hills; especially from a rural area, with a connotation of a lack of refinement or sophistication.", "seq": 0}, {"text": "someone who is from the hills", "seq": 1}, {"text": "A white person from the rural southern part of the United States.", "seq": 2}]'
>>>
>>>
## "Synonym"
>>> vb.synonym("hurricane")
'[{"text": "storm", "seq": 0}, {"text": "tropical cyclone", "seq": 1}, {"text": "typhoon", "seq": 2}, {"text": "gale", "seq": 3}]'
>>>
>>>
## "Antonym"
>>> vb.antonym("respect")
Expand Down Expand Up @@ -53,3 +53,14 @@ A Simple demonstration of the module
>>> vb.translate("goodbye", "en","es")
'[{"seq": 0, "text": "hasta luego"}, {"seq": 1, "text": "vaya con Dios"}, {"seq": 2, "text": "despedida"}, {"seq": 3, "text": "adi\\u00f3s"}, {"seq": 4, "text": "vaya con dios"}, {"seq": 5, "text": "hasta la vista"}, {"seq": 6, "text": "nos vemos"}, {"seq": 7, "text": "adios"}, {"seq": 8, "text": "hasta pronto"}]'
>>>
## "Response Formatting"
>>> vb.antonym("love", format="dict")
{"text": "hate"}
>>> vb.antonym("love", format="list")
["hate"]
>>> vb.part_of_speech("code", format="dict")
{0: {"text": "noun", "example": "A systematically arranged and comprehensive collection of laws."}}
>>> vb.part_of_speech("code", format="list")
[["noun", "A systematically arranged and comprehensive collection of laws."]]
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@

setup(
name = 'Vocabulary',
version = '0.0.5',
version = '0.0.6',
author = 'Tasdik Rahman',
author_email = 'tasdik95@gmail.com',
author_email = 'tasdik95@gmail.com',
description = "Module to get meaning, synonym, antonym, part_of_speech, usage_example, pronunciation and hyphenation for a given word",
long_description=long_description,
url = 'https://github.com/prodicus/vocabulary',
url = 'https://github.com/prodicus/vocabulary',
license = 'MIT',
install_requires = [
"requests==2.13.0",
],
### adding package data to it
### adding package data to it
packages=find_packages(exclude=['contrib', 'docs']),
###
download_url = 'https://github.com/prodicus/vocabulary/tarball/0.0.5',
download_url = 'https://github.com/prodicus/vocabulary/tarball/0.0.6',
classifiers = [
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
Expand Down
73 changes: 64 additions & 9 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

from vocabulary import Vocabulary as vb
from vocabulary.responselib import Response as rp
import unittest
import sys
try:
Expand All @@ -19,14 +20,14 @@ def test_meaning_valid_phrase(self):
result = '[{"text": "The sound of something that hums; a hum.", "seq": 0}, {"text": "<i>present participle of [i]hum</i>[/i]", "seq": 1}, {"text": "the act of singing with closed lips", "seq": 2}, {"text": "a humming noise; &quot;the hum of distant traffic&quot;", "seq": 3}, {"text": "Present participle of hum.", "seq": 4}]'
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 +38,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("angry")
result = '[{"text": "get angry", "seq": 0}, {"text": "mad", "seq": 1}]'
Expand All @@ -51,11 +52,11 @@ 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"]}'
expected_result = json.loads(result)
expected_result = json.dumps(json.loads(result))
if sys.version_info[:2] <= (2, 7):
self.assertItemsEqual(current_result, expected_result)
else:
Expand All @@ -64,7 +65,7 @@ def test_antonym_valid_phrase_1(self):
def test_antonym_valid_phrase_2(self):
current_result = vb.antonym("respect")
result = '{"text": ["disesteem", "disrespect"]}'
expected_result = json.loads(result)
expected_result = json.dumps(json.loads(result))
if sys.version_info[:2] <= (2, 7):
self.assertItemsEqual(current_result, expected_result)
else:
Expand Down Expand Up @@ -115,7 +116,7 @@ def test_usageExamples_not_valid_phrase(self):
def test_pronunciation_valid_phrase(self):
current_result = vb.pronunciation("hippopotamus")
result = '[{"rawType": "ahd-legacy", "raw": "(hĭpˌə-pŏtˈə-məs)", "seq": 0}, {"rawType": "arpabet", "raw": "HH IH2 P AH0 P AA1 T AH0 M AH0 S", "seq": 0}]'
expected_result = json.loads(result)
expected_result = json.dumps(json.loads(result))
if sys.version_info[:2] <= (2, 7):
self.assertItemsEqual(current_result, expected_result)
else:
Expand Down Expand Up @@ -153,5 +154,59 @@ def test_translate_not_valid_phrase(self):
current_result = vb.translate("asldkfj", "en", "ru")
self.assertEqual(current_result, False)

def test_respond_as_dict_1(self):
data = json.loads('[{"text": "hummus", "seq": 0}]')
expected_result = {0: {"text": "hummus"}}
result = rp().respond(data, 'dict')
if sys.version_info[:2] <= (2, 7):
self.assertItemsEqual(expected_result, result)
else:
self.assertCountEqual(expected_result, result)

def test_respond_as_dict_2(self):
data = json.loads('[{"text": "hummus", "seq": 0},{"text": "hummusy", "seq": 1}]')
expected_result = {0: {"text": "hummus"}, 1: {"text": "hummusy"}}
result = rp().respond(data, 'dict')
if sys.version_info[:2] <= (2, 7):
self.assertItemsEqual(expected_result, result)
else:
self.assertCountEqual(expected_result, result)

def test_respond_as_dict_3(self):
data = json.loads('{"text": ["hummus"]}')
expected_result = {"text" : "hummus"}
result = rp().respond(data, 'dict')
if sys.version_info[:2] <= (2, 7):
self.assertItemsEqual(expected_result, result)
else:
self.assertCountEqual(expected_result, result)

def test_respond_as_list_1(self):
data = json.loads('[{"text": "hummus", "seq": 0}]')
expected_result = ["hummus"]
result = rp().respond(data, 'list')
if sys.version_info[:2] <= (2, 7):
self.assertItemsEqual(expected_result, result)
else:
self.assertCountEqual(expected_result, result)

def test_respond_as_list_2(self):
data = json.loads('[{"text": "hummus", "seq": 0},{"text": "hummusy", "seq": 1}]')
expected_result = ["hummus", "hummusy"]
result = rp().respond(data, 'list')
if sys.version_info[:2] <= (2, 7):
self.assertItemsEqual(expected_result, result)
else:
self.assertCountEqual(expected_result, result)

def test_respond_as_list_3(self):
data = json.loads('{"text": ["hummus"]}')
expected_result = ["hummus"]
result = rp().respond(data, 'list')
if sys.version_info[:2] <= (2, 7):
self.assertItemsEqual(expected_result, result)
else:
self.assertCountEqual(expected_result, result)

if __name__ == "__main__":
unittest.main()
Loading

0 comments on commit 7573f21

Please sign in to comment.