Created
August 6, 2012 17:45
-
-
Save yvmarques/3277046 to your computer and use it in GitHub Desktop.
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
Use requirements.txt to install all requirements. | |
pip install -r requirements.txt | |
Then start simple the small server with the fellowing command | |
python detect_language.py | |
To try the web service you can use curl | |
curl -H "Accept: application/json" -H "Content-Type: application/x-www-form-urlencoded" -X POST -d "text=Hello+world.+Has+the+sun+risen+on+you+today%3F" http://localhost:8001/ |
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
# -*- coding: utf-8 -*- | |
""" | |
Small webservice based on wsgiservice that try to detect the natural language of one text | |
""" | |
from wsgiservice import * | |
from guess_language import guessLanguage | |
@mount('/') | |
class Index(Resource): | |
NOT_FOUND = (KeyError,) | |
def POST(self): | |
""" | |
Get text from the post form and then try to determine de language | |
with guess-language library | |
""" | |
text = None | |
if self.request.POST['text'] is not None: | |
text = self.request.POST['text'] | |
language = 'UNKNOWN' # Default value by guessLanguage | |
if text is not None: | |
language = guessLanguage(text) | |
return dict(language=language) | |
app = get_app(globals()) | |
if __name__ == '__main__': | |
from wsgiref.simple_server import make_server | |
print "Running on port 8001" | |
make_server('', 8001, app).serve_forever() |
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
WsgiService==0.3 | |
-e git://github.com/dsc/guess-language.git#egg=guess-language |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment