Skip to content

Commit

Permalink
🎉 Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mamal72 committed Jan 20, 2017
0 parents commit dd64d50
Show file tree
Hide file tree
Showing 9 changed files with 247 additions and 0 deletions.
96 changes: 96 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
include/
bin/
pip-selfcheck.json
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# dotenv
.env

# virtualenv
.venv/
venv/
ENV/

# Spyder project settings
.spyderproject

# Rope project settings
.ropeproject

# IDE stuff
.idea/
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: python

python:
- 3.5
- 3.6
- nightly

install:
- pip install -r requirements.txt
- pip install coveralls

script:
coverage run --omit=*/lib/* setup.py test

after_success:
coveralls
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Mohamad Jahani

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[![Build Status](https://travis-ci.org/mamal72/shekam.svg?branch=master)](https://travis-ci.org/mamal72/shekam)
[![Coverage Status](https://coveralls.io/repos/github/mamal72/shekam/badge.svg?branch=master)](https://coveralls.io/github/mamal72/shekam?branch=master)
[![license](https://img.shields.io/github/license/mamal72/shekam.svg)](https://github.com/mamal72/shekam/blob/master/LICENSE)

# Shekam
A simple python3 based HTTP API around [Hazm](https://github.com/sobhe/hazm) to fix common writing problems in Persian language.


## Tests

```bash
python setup.py test
```


## Ideas || Issues
Just fill an issue and describe it. I'll check it ASAP!


## Contribution

You can fork the repository, improve or fix some part of it and then send the pull requests back if you want to see them here. I really appreciate that. :heart:

Remember to write a few tests for your code before sending pull requests.


## License

Licensed under the [MIT License](https://github.com/mamal72/shekam/blob/master/LICENSE).
37 changes: 37 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import time
import os
from sanic import Sanic
from sanic.response import json
from hazm import Normalizer

app = Sanic()

normalizer = Normalizer()

def normalize(text):
start_time = time.time()
normalized = normalizer.normalize(text)
took = round(time.time() - start_time, 4)
return took, normalized

@app.route('/')
async def index_handler():
return json({'hello': 'world'})

@app.route('/normalize')
async def normalize_handler(request):
text = request.args.get('text')
if not text:
return json({
'error': 'no "text" querystring parameter passed'
}, 406)

took, normalized = normalize(text)

return json({
'took': took,
'normalized': normalized
})

if __name__ == '__main__':
app.run(host=os.getenv('HOST', '0.0.0.0'), port=os.getenv('PORT', 8000))
13 changes: 13 additions & 0 deletions main_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import unittest
from main import normalize

class MainTestClass(unittest.TestCase):
def test_normalize_function(self):
"""It should test normalize function and get a normalized text"""
input_text = 'در می‌زند و دوباره وارد مي شود . همه مي گویند قدمش پربرکت است .'
expected_text = 'در می‌زند و دوباره وارد می‌شود. همه می‌گویند قدمش پربرکت است.'
t, got_text = normalize(input_text)
self.assertEqual(expected_text, got_text)

if __name__ == '__main__':
unittest.main()
11 changes: 11 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
aiofiles==0.3.0
hazm==0.5.2
httptools==0.0.9
libwapiti==0.2.1
multidict==2.1.4
nltk==3.0.5
requests==2.12.5
Sanic==0.2.0
six==1.10.0
ujson==1.35
uvloop==0.7.2
23 changes: 23 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from setuptools import setup

setup(
name='shekam', version='0.1.0',
description='Shekam is an API based of Hazm',
author='Mohamad Jahani',
author_email='m4m4lj@gmail.com',
url='https://github.com/mamal72/shekam',
test_suite="tests",
install_requires=[
'aiofiles==0.3.0',
'hazm==0.5.2',
'httptools==0.0.9',
'libwapiti==0.2.1',
'multidict==2.1.4',
'nltk==3.0.5',
'requests==2.12.5',
'Sanic==0.2.0',
'six==1.10.0',
'ujson==1.35',
'uvloop==0.7.2'
]
)
1 change: 1 addition & 0 deletions tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from main_test import *

0 comments on commit dd64d50

Please sign in to comment.