Commit 188c3333 authored by J. Fernando Sánchez's avatar J. Fernando Sánchez
Browse files

Removed nbsphinx

It requires pandoc, which cannot be installed with pip.

We can either link to the nbfile or convert the file
manually/automatically:

```
nbconvert SenpyClientUse.ipynb --to rst
```
parent 955e17eb
...@@ -2,14 +2,35 @@ ...@@ -2,14 +2,35 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {
"ExecuteTime": {
"end_time": "2017-04-10T17:05:31.465571Z",
"start_time": "2017-04-10T19:05:31.458282+02:00"
},
"deletable": true,
"editable": true
},
"source": [ "source": [
"# Client" "# Client"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
"source": [
"The built-in senpy client allows you to query any Senpy endpoint. We will illustrate how to use it with the public demo endpoint, and then show you how to spin up your own endpoint using docker."
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [ "source": [
"Demo Endpoint\n", "Demo Endpoint\n",
"-------------" "-------------"
...@@ -17,213 +38,235 @@ ...@@ -17,213 +38,235 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {
"deletable": true,
"editable": true
},
"source": [ "source": [
"Import Client and send a request" "To start using senpy, simply create a new Client and point it to your endpoint. In this case, the latest version of Senpy at GSI."
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "ExecuteTime": {
"end_time": "2017-04-10T17:29:12.827640Z",
"start_time": "2017-04-10T19:29:12.818617+02:00"
},
"collapsed": false,
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"from senpy.client import Client\n", "from senpy.client import Client\n",
"\n", "\n",
"c = Client('http://latest.senpy.cluster.gsi.dit.upm.es/api')\n", "c = Client('http://latest.senpy.cluster.gsi.dit.upm.es/api')\n"
"r = c.analyse('I like Pizza', algorithm='sentiment140')"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {
"deletable": true,
"editable": true
},
"source": [ "source": [
"Print response" "Now, let's use that client analyse some queries:"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "ExecuteTime": {
"end_time": "2017-04-10T17:29:14.011657Z",
"start_time": "2017-04-10T19:29:13.701808+02:00"
},
"collapsed": false,
"deletable": true,
"editable": true
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"I like Pizza -> marl:Positive\n"
]
}
],
"source": [ "source": [
"for entry in r.entries:\n", "r = c.analyse('I like sugar!!', algorithm='sentiment140')\n",
" print('{} -> {}'.format(entry['text'], entry['sentiments'][0]['marl:hasPolarity']))" "r"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {
"ExecuteTime": {
"end_time": "2017-04-10T17:08:19.616754Z",
"start_time": "2017-04-10T19:08:19.610767+02:00"
},
"deletable": true,
"editable": true
},
"source": [ "source": [
"Obtain a list of available plugins " "As you can see, that gave us the full JSON result. A more concise way to print it would be:"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "ExecuteTime": {
"end_time": "2017-04-10T17:29:14.854213Z",
"start_time": "2017-04-10T19:29:14.842068+02:00"
},
"collapsed": false,
"deletable": true,
"editable": true
}, },
"outputs": [ "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": [ "source": [
"Local Endpoint\n", "for entry in r.entries:\n",
"--------------" " print('{} -> {}'.format(entry['text'], entry['sentiments'][0]['marl:hasPolarity']))"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {
"deletable": true,
"editable": true
},
"source": [ "source": [
"Run a docker container with Senpy image and default plugins" "We can also obtain a list of available plugins with the client:"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "ExecuteTime": {
"end_time": "2017-04-10T17:29:16.245198Z",
"start_time": "2017-04-10T19:29:16.056545+02:00"
},
"collapsed": false,
"deletable": true,
"editable": true
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"a0157cd98057072388bfebeed78a830da7cf0a796f4f1a3fd9188f9f2e5fe562\r\n"
]
}
],
"source": [ "source": [
"!docker run -ti --name 'SenpyEndpoint' -d -p 5000:5000 gsiupm/senpy:0.8.6 --host 0.0.0.0 --default-plugins" "c.plugins()"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {
"deletable": true,
"editable": true
},
"source": [ "source": [
"Import client and send a request to localhost" "Or, more concisely:"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "ExecuteTime": {
"end_time": "2017-04-10T17:29:17.663275Z",
"start_time": "2017-04-10T19:29:17.484623+02:00"
},
"collapsed": false,
"deletable": true,
"editable": true
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"c_local = Client('http://127.0.0.1:5000/api')\n", "c.plugins().keys()"
"r = c_local.analyse('Hello world', algorithm='sentiment140')"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {
"deletable": true,
"editable": true
},
"source": [ "source": [
"Print response" "Local Endpoint\n",
"--------------"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"To run your own instance of senpy, just create a docker container with the latest Senpy image. Using `--default-plugins` you will get some extra plugins to start playing with the API."
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "ExecuteTime": {
"end_time": "2017-04-10T17:29:20.637539Z",
"start_time": "2017-04-10T19:29:19.938322+02:00"
},
"collapsed": false,
"deletable": true,
"editable": true
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello world -> marl:Neutral\n"
]
}
],
"source": [ "source": [
"for entry in r.entries:\n", "!docker run -ti --name 'SenpyEndpoint' -d -p 6000:5000 gsiupm/senpy:0.8.6 --host 0.0.0.0 --default-plugins"
" print('{} -> {}'.format(entry['text'], entry['sentiments'][0]['marl:hasPolarity']))"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {
"deletable": true,
"editable": true
},
"source": [ "source": [
"Obtain a list of available plugins deployed locally" "To use this endpoint:"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "ExecuteTime": {
"end_time": "2017-04-10T17:29:21.263976Z",
"start_time": "2017-04-10T19:29:21.260595+02:00"
},
"collapsed": false,
"deletable": true,
"editable": true
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"rand\n",
"sentiment140\n",
"emoRand\n"
]
}
],
"source": [ "source": [
"for plugin in c_local.request('/plugins')['plugins']:\n", "c_local = Client('http://127.0.0.1:6000/api')"
" print(plugin['name'])"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {
"deletable": true,
"editable": true
},
"source": [ "source": [
"Stop the docker container" "That's all! After you are done with your analysis, stop the docker container:"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": null,
"metadata": { "metadata": {
"collapsed": false "ExecuteTime": {
"end_time": "2017-04-10T17:29:33.226686Z",
"start_time": "2017-04-10T19:29:22.392121+02:00"
},
"collapsed": false,
"deletable": true,
"editable": true
}, },
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"SenpyEndpoint\n",
"SenpyEndpoint\n"
]
}
],
"source": [ "source": [
"!docker stop SenpyEndpoint\n", "!docker stop SenpyEndpoint\n",
"!docker rm SenpyEndpoint" "!docker rm SenpyEndpoint"
...@@ -233,7 +276,7 @@ ...@@ -233,7 +276,7 @@
"metadata": { "metadata": {
"anaconda-cloud": {}, "anaconda-cloud": {},
"kernelspec": { "kernelspec": {
"display_name": "Python [default]", "display_name": "Python 3",
"language": "python", "language": "python",
"name": "python3" "name": "python3"
}, },
...@@ -247,7 +290,26 @@ ...@@ -247,7 +290,26 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.2" "version": "3.6.0"
},
"toc": {
"colors": {
"hover_highlight": "#DAA520",
"running_highlight": "#FF0000",
"selected_highlight": "#FFD700"
},
"moveMenuLeft": true,
"nav_menu": {
"height": "68px",
"width": "252px"
},
"navigate_menu": true,
"number_sections": true,
"sideBar": true,
"threshold": 4,
"toc_cell": false,
"toc_section_display": "block",
"toc_window_display": false
} }
}, },
"nbformat": 4, "nbformat": 4,
......
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Client # Client
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
The built-in senpy client allows you to query any Senpy endpoint. We will illustrate how to use it with the public demo endpoint, and then show you how to spin up your own endpoint using docker.
%% Cell type:markdown id: tags:
Demo Endpoint Demo Endpoint
------------- -------------
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Import Client and send a request To start using senpy, simply create a new Client and point it to your endpoint. In this case, the latest version of Senpy at GSI.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
from senpy.client import Client from senpy.client import Client
c = Client('http://latest.senpy.cluster.gsi.dit.upm.es/api') c = Client('http://latest.senpy.cluster.gsi.dit.upm.es/api')
r = c.analyse('I like Pizza', algorithm='sentiment140')
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Print response Now, let's use that client analyse some queries:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
for entry in r.entries: r = c.analyse('I like sugar!!', algorithm='sentiment140')
print('{} -> {}'.format(entry['text'], entry['sentiments'][0]['marl:hasPolarity'])) r
``` ```
%%%% Output: stream
I like Pizza -> marl:Positive
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Obtain a list of available plugins As you can see, that gave us the full JSON result. A more concise way to print it would be:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
for plugin in c.request('/plugins')['plugins']: for entry in r.entries:
print(plugin['name']) print('{} -> {}'.format(entry['text'], entry['sentiments'][0]['marl:hasPolarity']))
``` ```
%%%% Output: stream
emoRand
rand
sentiment140
%% Cell type:markdown id: tags:
Local Endpoint
--------------
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Run a docker container with Senpy image and default plugins We can also obtain a list of available plugins with the client:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
!docker run -ti --name 'SenpyEndpoint' -d -p 5000:5000 gsiupm/senpy:0.8.6 --host 0.0.0.0 --default-plugins c.plugins()
``` ```
%%%% Output: stream
a0157cd98057072388bfebeed78a830da7cf0a796f4f1a3fd9188f9f2e5fe562
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Import client and send a request to localhost Or, more concisely:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
c_local = Client('http://127.0.0.1:5000/api') c.plugins().keys()
r = c_local.analyse('Hello world', algorithm='sentiment140')
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Print response Local Endpoint
--------------
%% Cell type:markdown id: tags:
To run your own instance of senpy, just create a docker container with the latest Senpy image. Using `--default-plugins` you will get some extra plugins to start playing with the API.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
for entry in r.entries: !docker run -ti --name 'SenpyEndpoint' -d -p 6000:5000 gsiupm/senpy:0.8.6 --host 0.0.0.0 --default-plugins
print('{} -> {}'.format(entry['text'], entry['sentiments'][0]['marl:hasPolarity']))
``` ```
%%%% Output: stream
Hello world -> marl:Neutral
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Obtain a list of available plugins deployed locally To use this endpoint:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
for plugin in c_local.request('/plugins')['plugins']: c_local = Client('http://127.0.0.1:6000/api')
print(plugin['name'])
``` ```
%%%% Output: stream
rand
sentiment140
emoRand
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Stop the docker container That's all! After you are done with your analysis, stop the docker container:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
!docker stop SenpyEndpoint !docker stop SenpyEndpoint
!docker rm SenpyEndpoint !docker rm SenpyEndpoint
``` ```
%%%% Output: stream