diff --git a/docs/SenpyClientUse.ipynb b/docs/SenpyClientUse.ipynb new file mode 100644 index 0000000..e332e9c --- /dev/null +++ b/docs/SenpyClientUse.ipynb @@ -0,0 +1,255 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Client" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Demo Endpoint\n", + "-------------" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Import Client and send a request" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "from senpy.client import Client\n", + "\n", + "c = Client('http://latest.senpy.cluster.gsi.dit.upm.es/api')\n", + "r = c.analyse('I like Pizza', algorithm='sentiment140')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Print response" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I like Pizza -> marl:Positive\n" + ] + } + ], + "source": [ + "for entry in r.entries:\n", + " print('{} -> {}'.format(entry['text'], entry['sentiments'][0]['marl:hasPolarity']))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Obtain a list of available plugins " + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "emoRand\n", + "rand\n", + "sentiment140\n" + ] + } + ], + "source": [ + "for plugin in c.request('/plugins')['plugins']:\n", + " print(plugin['name'])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Local Endpoint\n", + "--------------" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Run a docker container with Senpy image and default plugins" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a0157cd98057072388bfebeed78a830da7cf0a796f4f1a3fd9188f9f2e5fe562\r\n" + ] + } + ], + "source": [ + "!docker run -ti --name 'SenpyEndpoint' -d -p 5000:5000 gsiupm/senpy:0.8.6 --host 0.0.0.0 --default-plugins" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Import client and send a request to localhost" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "c_local = Client('http://127.0.0.1:5000/api')\n", + "r = c_local.analyse('Hello world', algorithm='sentiment140')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Print response" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello world -> marl:Neutral\n" + ] + } + ], + "source": [ + "for entry in r.entries:\n", + " print('{} -> {}'.format(entry['text'], entry['sentiments'][0]['marl:hasPolarity']))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Obtain a list of available plugins deployed locally" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "rand\n", + "sentiment140\n", + "emoRand\n" + ] + } + ], + "source": [ + "for plugin in c_local.request('/plugins')['plugins']:\n", + " print(plugin['name'])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Stop the docker container" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "SenpyEndpoint\n", + "SenpyEndpoint\n" + ] + } + ], + "source": [ + "!docker stop SenpyEndpoint\n", + "!docker rm SenpyEndpoint" + ] + } + ], + "metadata": { + "anaconda-cloud": {}, + "kernelspec": { + "display_name": "Python [default]", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.5.2" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/docs/research.rst b/docs/about.rst similarity index 98% rename from docs/research.rst rename to docs/about.rst index 996567c..b457ef6 100644 --- a/docs/research.rst +++ b/docs/about.rst @@ -1,4 +1,4 @@ -Research +About -------- If you use Senpy in your research, please cite `Senpy: A Pragmatic Linked Sentiment Analysis Framework `__ (`BibTex `__): diff --git a/docs/apischema.rst b/docs/apischema.rst index dc93d66..01b6a86 100644 --- a/docs/apischema.rst +++ b/docs/apischema.rst @@ -1,7 +1,7 @@ -API and Schema -############## +API and Examples +################ .. toctree:: vocabularies.rst api.rst - schema.rst + examples.rst diff --git a/docs/clidemo.rst b/docs/clidemo.rst new file mode 100644 index 0000000..72ce14c --- /dev/null +++ b/docs/clidemo.rst @@ -0,0 +1,10 @@ +Client demo +=========== + +This video shows how to use senpy through command-line tool. + +.. image:: https://asciinema.org/a/9uwef1ghkjk062cw2t4mhzpyk.png + :width: 100% + :target: https://asciinema.org/a/9uwef1ghkjk062cw2t4mhzpyk + :alt: CLI demo + diff --git a/docs/commandline.rst b/docs/commandline.rst new file mode 100644 index 0000000..69ab1ac --- /dev/null +++ b/docs/commandline.rst @@ -0,0 +1,24 @@ +Command line +============ + +In case you want to load modules, which are located in different folders under the root folder, use the next option. + +.. code:: bash + + senpy -f . + +The default port used by senpy is 5000, but you can change it using the `--port` flag. + +.. code:: bash + + senpy --port 8080 + +Also, the host can be changed where senpy is deployed. The default value is `127.0.0.1`. + +.. code:: bash + + senpy --host 0.0.0.0 + +For more options, see the `--help` page. + +Alternatively, you can use the modules included in senpy to build your own application. diff --git a/docs/conf.py b/docs/conf.py index 541c05f..7292228 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -37,7 +37,8 @@ extensions = [ 'sphinx.ext.todo', 'sphinxcontrib.httpdomain', 'sphinx.ext.coverage', - 'sphinx.ext.autosectionlabel' + 'sphinx.ext.autosectionlabel', + 'nbsphinx' ] # Add any paths that contain templates here, relative to this directory. diff --git a/docs/schema.rst b/docs/examples.rst similarity index 63% rename from docs/schema.rst rename to docs/examples.rst index d24a75a..9c1456f 100644 --- a/docs/schema.rst +++ b/docs/examples.rst @@ -1,4 +1,4 @@ -Schema +Examples ------ All the examples in this page use the :download:`the main schema <_static/schemas/definitions.json>`. @@ -17,6 +17,8 @@ Sentiment Analysis ..................... Description ,,,,,,,,,,, +This annotation corresponds to the sentiment analysis of an input. The example shows the sentiment represented according to Marl format. +The sentiments detected are contained in the Sentiments array with their related part of the text. Representation ,,,,,,,,,,,,,, @@ -29,6 +31,7 @@ Suggestion Mining ................. Description ,,,,,,,,,,, +The suggestions schema represented below shows the suggestions detected in the text. Within it, we can find the NIF fields highlighted that corresponds to the text of the detected suggestion. Representation ,,,,,,,,,,,,,, @@ -41,6 +44,7 @@ Emotion Analysis ................ Description ,,,,,,,,,,, +This annotation represents the emotion analysis of an input to Senpy. The emotions are contained in the emotions section with the text that refers to following Onyx format and the emotion model defined beforehand. Representation ,,,,,,,,,,,,,, @@ -53,7 +57,7 @@ Named Entity Recognition ........................ Description ,,,,,,,,,,, - +The Named Entity Recognition is represented as follows. In this particular case, it can be seen within the entities array the entities recognised. For the example input, Microsoft and Windows Phone are the ones detected. Representation ,,,,,,,,,,,,,, diff --git a/docs/index.rst b/docs/index.rst index f0194e2..aba1ffd 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -20,9 +20,9 @@ Senpy provides: senpy installation + demo usage apischema plugins conversion - demo - research.rst + about diff --git a/docs/requirements.txt b/docs/requirements.txt index 0e47a20..87087eb 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1 +1,2 @@ sphinxcontrib-httpdomain>=1.4 +nbsphinx diff --git a/docs/server.rst b/docs/server.rst new file mode 100644 index 0000000..407459d --- /dev/null +++ b/docs/server.rst @@ -0,0 +1,8 @@ +Senpy server +============ + +Once the server is launched, there is a basic endpoint in the server, which provides a playground to use the plugins that have been loaded. + +In case you want to know the different endpoints of the server, there is more information available in the NIF API section_. + + diff --git a/docs/usage.rst b/docs/usage.rst index 80c8614..df20434 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -5,69 +5,11 @@ First of all, you need to install the package. See :doc:`installation` for installation instructions. Once installed, the `senpy` command should be available. -Useful command-line options -=========================== +.. toctree:: -In case you want to load modules, which are located in different folders under the root folder, use the next option. + SenpyClientUse + server + clidemo + commandline -.. code:: bash - senpy -f . - -The default port used by senpy is 5000, but you can change it using the `--port` flag. - -.. code:: bash - - senpy --port 8080 - -Also, the host can be changed where senpy is deployed. The default value is `127.0.0.1`. - -.. code:: bash - - senpy --host 0.0.0.0 - -For more options, see the `--help` page. - -Alternatively, you can use the modules included in senpy to build your own application. - -Senpy server -============ - -Once the server is launched, there is a basic endpoint in the server, which provides a playground to use the plugins that have been loaded. - -In case you want to know the different endpoints of the server, there is more information available in the NIF API section_. - -CLI demo -======== - -This video shows how to use senpy through command-line tool. - -.. image:: https://asciinema.org/a/9uwef1ghkjk062cw2t4mhzpyk.png - :width: 100% - :target: https://asciinema.org/a/9uwef1ghkjk062cw2t4mhzpyk - :alt: CLI demo - - -Built-in client -=============== - -This example shows how to make a request to the default plugin: - -.. code:: python - - from senpy.client import Client - - c = Client('http://127.0.0.1:5000/api/') - r = c.analyse('hello world') - - for entry in r.entries: - print('{} -> {}'.format(entry.text, entry.emotions)) - - - -.. _section: http://senpy.readthedocs.org/en/latest/api.html - - -Conversion -========== -See :doc:`conversion` diff --git a/senpy/client.py b/senpy/client.py index 5867715..48c1238 100644 --- a/senpy/client.py +++ b/senpy/client.py @@ -22,7 +22,6 @@ class Client(object): response = requests.request(method=method, url=url, params=params) try: resp = models.from_dict(response.json()) - resp.validate(resp) except Exception as ex: logger.error(('There seems to be a problem with the response:\n' '\tURL: {url}\n'