SenpyClientUse.rst 1.67 KB
Newer Older
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106

Client
======

Demo Endpoint
-------------

Import Client and send a request

.. code:: python

    from senpy.client import Client
    
    c = Client('http://latest.senpy.cluster.gsi.dit.upm.es/api')
    r = c.analyse('I like Pizza', algorithm='sentiment140')

Print response

.. code:: python

    for entry in r.entries:
          print('{} -> {}'.format(entry['text'], entry['sentiments'][0]['marl:hasPolarity']))


.. parsed-literal::

    I like Pizza -> marl:Positive


Obtain a list of available plugins

.. code:: python

    for plugin in c.request('/plugins')['plugins']:
        print(plugin['name'])


.. parsed-literal::

    emoRand
    rand
    sentiment140


Local Endpoint
--------------

Run a docker container with Senpy image and default plugins

.. code::

    docker run -ti --name 'SenpyEndpoint' -d -p 5000:5000 gsiupm/senpy:0.8.6 --host 0.0.0.0 --default-plugins


.. parsed-literal::

    a0157cd98057072388bfebeed78a830da7cf0a796f4f1a3fd9188f9f2e5fe562


Import client and send a request to localhost

.. code:: python

    c_local = Client('http://127.0.0.1:5000/api')
    r = c_local.analyse('Hello world', algorithm='sentiment140')

Print response

.. code:: python

    for entry in r.entries:
          print('{} -> {}'.format(entry['text'], entry['sentiments'][0]['marl:hasPolarity']))


.. parsed-literal::

    Hello world -> marl:Neutral


Obtain a list of available plugins deployed locally

.. code:: python

    c_local.plugins().keys()


.. parsed-literal::

    rand
    sentiment140
    emoRand


Stop the docker container

.. code:: python

    !docker stop SenpyEndpoint
    !docker rm SenpyEndpoint


.. parsed-literal::

    SenpyEndpoint
    SenpyEndpoint