{ "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 }