{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial\n", "\n", "This short tutorial will teach you how to consume senpy services for several tasks, and how to take advantage of the features of the framework.\n", "\n", "In particular, it covers:\n", "\n", "* Annotating text with sentiment and emotion using interoperable services\n", "* Switching to different services (service interoperability)\n", "* Getting results in different formats (Turtle, XML, text...)\n", "* Asking for specific emotion models (automatic model conversion)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Requirements" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will use the demo server at http://senpy.gsi.upm.es abd the requests library.\n", "\n", "We will use a variable for our endpoint so you can try these examples on other instances:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "endpoint = 'http://senpy.gsi.upm.es/api'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We will also add a little helper function (`query`) to simplify our queries and pretty-print the results with syntax highlighting:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import requests\n", "from IPython.display import Code\n", " \n", "def query(endpoint, **kwargs):\n", " '''Query a given Senpy endpoint with specific parameters, and prettify the output'''\n", " res = requests.get(endpoint,\n", " params=kwargs)\n", " if res.status_code != 200:\n", " raise Exception(res)\n", " return Code(res.text, language=kwargs.get('outformat', 'json-ld'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sentiment Analysis of Text" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To start, let us analyse the sentiment in the following sentence: *senpy is awesome*.\n", "\n", "For now, we will use the [sentiment140](http://www.sentiment140.com/) service, through the sentiment140 plugin.\n", "We will later cover how to use a different service.\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
{\n",
       "  "@context": "http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudDE0MD9pbnB1dD1TZW5weStpcythd2Vzb21lIw%3D%3D",\n",
       "  "@type": "Results",\n",
       "  "entries": [\n",
       "    {\n",
       "      "@id": "prefix:",\n",
       "      "@type": "Entry",\n",
       "      "marl:hasOpinion": [\n",
       "        {\n",
       "          "@type": "Sentiment",\n",
       "          "marl:hasPolarity": "marl:Positive",\n",
       "          "prov:wasGeneratedBy": "prefix:Analysis_1563372853.439696"\n",
       "        }\n",
       "      ],\n",
       "      "nif:isString": "Senpy is awesome",\n",
       "      "onyx:hasEmotionSet": []\n",
       "    }\n",
       "  ]\n",
       "}\n",
       "
\n" ], "text/latex": [ "\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n", "\\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@context\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudDE0MD9pbnB1dD1TZW5weStpcythd2Vzb21lIw\\PYZpc{}3D\\PYZpc{}3D\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Results\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}entries\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@id\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Entry\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}marl:hasOpinion\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Sentiment\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}marl:hasPolarity\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}marl:Positive\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}prov:wasGeneratedBy\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:Analysis\\PYZus{}1563372853.439696\\PYZdq{}}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}nif:isString\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Senpy is awesome\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionSet\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\\PY{p}{]}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\n", "\\PY{p}{\\PYZcb{}}\n", "\\end{Verbatim}\n" ], "text/plain": [ "{\n", " \"@context\": \"http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudDE0MD9pbnB1dD1TZW5weStpcythd2Vzb21lIw%3D%3D\",\n", " \"@type\": \"Results\",\n", " \"entries\": [\n", " {\n", " \"@id\": \"prefix:\",\n", " \"@type\": \"Entry\",\n", " \"marl:hasOpinion\": [\n", " {\n", " \"@type\": \"Sentiment\",\n", " \"marl:hasPolarity\": \"marl:Positive\",\n", " \"prov:wasGeneratedBy\": \"prefix:Analysis_1563372853.439696\"\n", " }\n", " ],\n", " \"nif:isString\": \"Senpy is awesome\",\n", " \"onyx:hasEmotionSet\": []\n", " }\n", " ]\n", "}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query(f'{endpoint}/sentiment140', input=\"Senpy is awesome\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Senpy services always return an object of type `senpy:Results`, with a list of entries.\n", "You can think of an entry as a self-contained textual context (`nif:Context` and `senpy:Entry`).\n", "Entries can be as short as a sentence, or as long as a news article.\n", "\n", "Each entry has a `nif:isString` property that contains the original text of the entry, and several other properties that are provided by the plugins.\n", "\n", "For instance, sentiment annotations are provided through `marl:hasOpinion`.\n", "\n", "The annotations are semantic.\n", "This is clear if we request a different semantic format, such as `turtle`.\n", "The output format is controlled with the `outformat` parameter:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
@prefix : <http://www.gsi.upm.es/onto/senpy/ns#> .\n",
       "@prefix dc: <http://dublincore.org/2012/06/14/dcelements#> .\n",
       "@prefix emoml: <http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/emotionml/ns#> .\n",
       "@prefix endpoint: <http://senpy.gsi.upm.es/api/> .\n",
       "@prefix fam: <http://vocab.fusepool.info/fam#> .\n",
       "@prefix marl: <http://www.gsi.dit.upm.es/ontologies/marl/ns#> .\n",
       "@prefix nif: <http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#> .\n",
       "@prefix onyx: <http://www.gsi.dit.upm.es/ontologies/onyx/ns#> .\n",
       "@prefix prefix: <http://senpy.invalid/> .\n",
       "@prefix prov: <http://www.w3.org/ns/prov#> .\n",
       "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .\n",
       "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n",
       "@prefix senpy: <http://www.gsi.upm.es/onto/senpy/ns#> .\n",
       "@prefix wna: <http://www.gsi.dit.upm.es/ontologies/wnaffect/ns#> .\n",
       "@prefix xml: <http://www.w3.org/XML/1998/namespace> .\n",
       "@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n",
       "\n",
       "prefix: a senpy:Entry ;\n",
       "    nif:isString "Senpy is awesome" ;\n",
       "    marl:hasOpinion [ a senpy:Sentiment ;\n",
       "            marl:hasPolarity "marl:Positive" ;\n",
       "            prov:wasGeneratedBy prefix:Analysis_1563372853.6874764 ] .\n",
       "\n",
       "[] a senpy:Results ;\n",
       "    prov:used prefix: .\n",
       "
\n" ], "text/latex": [ "\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://www.gsi.upm.es/onto/senpy/ns\\PYZsh{}\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{dc:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://dublincore.org/2012/06/14/dcelements\\PYZsh{}\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{emoml:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/emotionml/ns\\PYZsh{}\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{endpoint:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://senpy.gsi.upm.es/api/\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{fam:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://vocab.fusepool.info/fam\\PYZsh{}\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{marl:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://www.gsi.dit.upm.es/ontologies/marl/ns\\PYZsh{}\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{nif:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://persistence.uni\\PYZhy{}leipzig.org/nlp2rdf/ontologies/nif\\PYZhy{}core\\PYZsh{}\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{onyx:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://www.gsi.dit.upm.es/ontologies/onyx/ns\\PYZsh{}\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{prefix:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://senpy.invalid/\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{prov:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://www.w3.org/ns/prov\\PYZsh{}\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{rdf:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://www.w3.org/1999/02/22\\PYZhy{}rdf\\PYZhy{}syntax\\PYZhy{}ns\\PYZsh{}\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{rdfs:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://www.w3.org/2000/01/rdf\\PYZhy{}schema\\PYZsh{}\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{senpy:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://www.gsi.upm.es/onto/senpy/ns\\PYZsh{}\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{wna:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://www.gsi.dit.upm.es/ontologies/wnaffect/ns\\PYZsh{}\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{xml:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://www.w3.org/XML/1998/namespace\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\\PY{k}{@prefix}\\PY{+w}{ }\\PY{n+nn}{xsd:}\\PY{+w}{ }\\PY{n+nv}{\\PYZlt{}http://www.w3.org/2001/XMLSchema\\PYZsh{}\\PYZgt{}}\\PY{+w}{ }\\PY{p}{.}\n", "\n", "\\PY{err}{p}\\PY{err}{r}\\PY{err}{e}\\PY{err}{f}\\PY{err}{i}\\PY{err}{x}\\PY{p}{:}\\PY{+w}{ }\\PY{k+kt}{a}\\PY{+w}{ }\\PY{n+nn}{senpy:}\\PY{n+nt}{Entry}\\PY{+w}{ }\\PY{p}{;}\n", "\\PY{+w}{ }\\PY{n+nn}{nif:}\\PY{n+nt}{isString}\\PY{+w}{ }\\PY{l+s}{\\PYZdq{}}\\PY{l+s}{Senpy is awesome}\\PY{l+s}{\\PYZdq{}}\\PY{+w}{ }\\PY{p}{;}\n", "\\PY{+w}{ }\\PY{n+nn}{marl:}\\PY{n+nt}{hasOpinion}\\PY{+w}{ }\\PY{p}{[}\\PY{+w}{ }\\PY{k+kt}{a}\\PY{+w}{ }\\PY{n+nn}{senpy:}\\PY{n+nt}{Sentiment}\\PY{+w}{ }\\PY{p}{;}\n", "\\PY{+w}{ }\\PY{n+nn}{marl:}\\PY{n+nt}{hasPolarity}\\PY{+w}{ }\\PY{l+s}{\\PYZdq{}}\\PY{l+s}{marl:Positive}\\PY{l+s}{\\PYZdq{}}\\PY{+w}{ }\\PY{p}{;}\n", "\\PY{+w}{ }\\PY{n+nn}{prov:}\\PY{n+nt}{wasGeneratedBy}\\PY{+w}{ }\\PY{n+nn}{prefix:}\\PY{n+nt}{Analysis\\PYZus{}1563372853}\\PY{l+m+mf}{.6874764}\\PY{+w}{ }\\PY{p}{]}\\PY{+w}{ }\\PY{p}{.}\n", "\n", "\\PY{p}{[}\\PY{p}{]}\\PY{+w}{ }\\PY{k+kt}{a}\\PY{+w}{ }\\PY{n+nn}{senpy:}\\PY{n+nt}{Results}\\PY{+w}{ }\\PY{p}{;}\n", "\\PY{+w}{ }\\PY{n+nn}{prov:}\\PY{n+nt}{used}\\PY{+w}{ }\\PY{err}{p}\\PY{err}{r}\\PY{err}{e}\\PY{err}{f}\\PY{err}{i}\\PY{err}{x}\\PY{p}{:}\\PY{+w}{ }\\PY{p}{.}\n", "\\end{Verbatim}\n" ], "text/plain": [ "@prefix : .\n", "@prefix dc: .\n", "@prefix emoml: .\n", "@prefix endpoint: .\n", "@prefix fam: .\n", "@prefix marl: .\n", "@prefix nif: .\n", "@prefix onyx: .\n", "@prefix prefix: .\n", "@prefix prov: .\n", "@prefix rdf: .\n", "@prefix rdfs: .\n", "@prefix senpy: .\n", "@prefix wna: .\n", "@prefix xml: .\n", "@prefix xsd: .\n", "\n", "prefix: a senpy:Entry ;\n", " nif:isString \"Senpy is awesome\" ;\n", " marl:hasOpinion [ a senpy:Sentiment ;\n", " marl:hasPolarity \"marl:Positive\" ;\n", " prov:wasGeneratedBy prefix:Analysis_1563372853.6874764 ] .\n", "\n", "[] a senpy:Results ;\n", " prov:used prefix: .\n" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query(f'{endpoint}/sentiment140',\n", " input=\"Senpy is awesome\",\n", " outformat=\"turtle\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Moving to a different service" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "All senpy plugins use the same API, which makes moving from one service to another a breeze.\n", "\n", "Let us modify the earlier example, which uses the `sentiment140` service, to use a different service (e.g. the `sentiment-basic` plugin).\n", "We can do it just by changing the URL of the service:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "scrolled": false }, "outputs": [ { "data": { "text/html": [ "
{\n",
       "  "@context": "http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudC1iYXNpYz9pbnB1dD1TZW5weStpcythd2Vzb21lIw%3D%3D",\n",
       "  "@type": "Results",\n",
       "  "entries": [\n",
       "    {\n",
       "      "@id": "prefix:",\n",
       "      "@type": "Entry",\n",
       "      "marl:hasOpinion": [\n",
       "        {\n",
       "          "@type": "Sentiment",\n",
       "          "marl:hasPolarity": "marl:Neutral",\n",
       "          "prov:wasGeneratedBy": "prefix:Analysis_1563372853.8034046"\n",
       "        }\n",
       "      ],\n",
       "      "nif:isString": "Senpy is awesome",\n",
       "      "onyx:hasEmotionSet": []\n",
       "    }\n",
       "  ]\n",
       "}\n",
       "
\n" ], "text/latex": [ "\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n", "\\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@context\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudC1iYXNpYz9pbnB1dD1TZW5weStpcythd2Vzb21lIw\\PYZpc{}3D\\PYZpc{}3D\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Results\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}entries\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@id\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Entry\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}marl:hasOpinion\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Sentiment\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}marl:hasPolarity\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}marl:Neutral\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}prov:wasGeneratedBy\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:Analysis\\PYZus{}1563372853.8034046\\PYZdq{}}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}nif:isString\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Senpy is awesome\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionSet\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\\PY{p}{]}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\n", "\\PY{p}{\\PYZcb{}}\n", "\\end{Verbatim}\n" ], "text/plain": [ "{\n", " \"@context\": \"http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudC1iYXNpYz9pbnB1dD1TZW5weStpcythd2Vzb21lIw%3D%3D\",\n", " \"@type\": \"Results\",\n", " \"entries\": [\n", " {\n", " \"@id\": \"prefix:\",\n", " \"@type\": \"Entry\",\n", " \"marl:hasOpinion\": [\n", " {\n", " \"@type\": \"Sentiment\",\n", " \"marl:hasPolarity\": \"marl:Neutral\",\n", " \"prov:wasGeneratedBy\": \"prefix:Analysis_1563372853.8034046\"\n", " }\n", " ],\n", " \"nif:isString\": \"Senpy is awesome\",\n", " \"onyx:hasEmotionSet\": []\n", " }\n", " ]\n", "}" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query(f'{endpoint}/sentiment-basic',\n", " input=\"Senpy is awesome\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you can see, the structure and annotation schema of the response is the same.\n", "This makes it very easy to compare and migrate to different services.\n", "\n", "Service interoperability is not only useful for users.\n", "It is also key for other features such as [automated evaluation](http://senpy.readthedocs.io/Evaluation.html).\n", "This is a compelling reason to adapt existing services to use the Senpy API.\n", "In fact, the `sentiment140` senpy service is proxy to the public [Sentiment 140 service](http://www.sentiment140.com/)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Emotion analysis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "Senpy uses the `onyx` vocabulary to represent emotions, which incorporates the notion of `EmotionSet`'s, an emotion that is composed of several emotions.\n", "In a nutshell, an `Entry` is linked to one or more `EmotionSet`, which in turn is made up of one or more `Emotion`.\n", "\n", "Let's illustrate it with an example, using the `emotion-depechemood` plugin." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
{\n",
       "  "@context": "http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tZGVwZWNoZW1vb2Q_aW5wdXQ9U2VucHkraXMrYSt3b25kZXJmdWwrdGhhdCtzZXJ2aWNlIw%3D%3D",\n",
       "  "@type": "Results",\n",
       "  "entries": [\n",
       "    {\n",
       "      "@id": "prefix:",\n",
       "      "@type": "Entry",\n",
       "      "marl:hasOpinion": [],\n",
       "      "nif:isString": "Senpy is a wonderful that service",\n",
       "      "onyx:hasEmotionSet": [\n",
       "        {\n",
       "          "@type": "EmotionSet",\n",
       "          "onyx:hasEmotion": [\n",
       "            {\n",
       "              "@type": "Emotion",\n",
       "              "onyx:hasEmotionCategory": "wna:negative-fear",\n",
       "              "onyx:hasEmotionIntensity": 0.06258366271018097\n",
       "            },\n",
       "            {\n",
       "              "@type": "Emotion",\n",
       "              "onyx:hasEmotionCategory": "wna:amusement",\n",
       "              "onyx:hasEmotionIntensity": 0.15784834034155437\n",
       "            },\n",
       "            {\n",
       "              "@type": "Emotion",\n",
       "              "onyx:hasEmotionCategory": "wna:anger",\n",
       "              "onyx:hasEmotionIntensity": 0.08728815135373413\n",
       "            },\n",
       "            {\n",
       "              "@type": "Emotion",\n",
       "              "onyx:hasEmotionCategory": "wna:annoyance",\n",
       "              "onyx:hasEmotionIntensity": 0.12184635680460143\n",
       "            },\n",
       "            {\n",
       "              "@type": "Emotion",\n",
       "              "onyx:hasEmotionCategory": "wna:indifference",\n",
       "              "onyx:hasEmotionIntensity": 0.1374081151031531\n",
       "            },\n",
       "            {\n",
       "              "@type": "Emotion",\n",
       "              "onyx:hasEmotionCategory": "wna:joy",\n",
       "              "onyx:hasEmotionIntensity": 0.12267040802346799\n",
       "            },\n",
       "            {\n",
       "              "@type": "Emotion",\n",
       "              "onyx:hasEmotionCategory": "wna:awe",\n",
       "              "onyx:hasEmotionIntensity": 0.21085262130713067\n",
       "            },\n",
       "            {\n",
       "              "@type": "Emotion",\n",
       "              "onyx:hasEmotionCategory": "wna:sadness",\n",
       "              "onyx:hasEmotionIntensity": 0.09950234435617733\n",
       "            }\n",
       "          ],\n",
       "          "prov:wasGeneratedBy": "prefix:Analysis_1563372853.9469151"\n",
       "        }\n",
       "      ]\n",
       "    }\n",
       "  ]\n",
       "}\n",
       "
\n" ], "text/latex": [ "\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n", "\\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@context\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tZGVwZWNoZW1vb2Q\\PYZus{}aW5wdXQ9U2VucHkraXMrYSt3b25kZXJmdWwrdGhhdCtzZXJ2aWNlIw\\PYZpc{}3D\\PYZpc{}3D\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Results\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}entries\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@id\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Entry\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}marl:hasOpinion\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\\PY{p}{]}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}nif:isString\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Senpy is a wonderful that service\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionSet\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}EmotionSet\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotion\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotion\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionCategory\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}wna:negative\\PYZhy{}fear\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionIntensity\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{0.06258366271018097}\n", " \\PY{p}{\\PYZcb{}}\\PY{p}{,}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotion\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionCategory\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}wna:amusement\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionIntensity\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{0.15784834034155437}\n", " \\PY{p}{\\PYZcb{}}\\PY{p}{,}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotion\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionCategory\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}wna:anger\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionIntensity\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{0.08728815135373413}\n", " \\PY{p}{\\PYZcb{}}\\PY{p}{,}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotion\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionCategory\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}wna:annoyance\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionIntensity\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{0.12184635680460143}\n", " \\PY{p}{\\PYZcb{}}\\PY{p}{,}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotion\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionCategory\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}wna:indifference\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionIntensity\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{0.1374081151031531}\n", " \\PY{p}{\\PYZcb{}}\\PY{p}{,}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotion\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionCategory\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}wna:joy\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionIntensity\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{0.12267040802346799}\n", " \\PY{p}{\\PYZcb{}}\\PY{p}{,}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotion\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionCategory\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}wna:awe\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionIntensity\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{0.21085262130713067}\n", " \\PY{p}{\\PYZcb{}}\\PY{p}{,}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotion\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionCategory\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}wna:sadness\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionIntensity\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{0.09950234435617733}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}prov:wasGeneratedBy\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:Analysis\\PYZus{}1563372853.9469151\\PYZdq{}}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\n", "\\PY{p}{\\PYZcb{}}\n", "\\end{Verbatim}\n" ], "text/plain": [ "{\n", " \"@context\": \"http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tZGVwZWNoZW1vb2Q_aW5wdXQ9U2VucHkraXMrYSt3b25kZXJmdWwrdGhhdCtzZXJ2aWNlIw%3D%3D\",\n", " \"@type\": \"Results\",\n", " \"entries\": [\n", " {\n", " \"@id\": \"prefix:\",\n", " \"@type\": \"Entry\",\n", " \"marl:hasOpinion\": [],\n", " \"nif:isString\": \"Senpy is a wonderful that service\",\n", " \"onyx:hasEmotionSet\": [\n", " {\n", " \"@type\": \"EmotionSet\",\n", " \"onyx:hasEmotion\": [\n", " {\n", " \"@type\": \"Emotion\",\n", " \"onyx:hasEmotionCategory\": \"wna:negative-fear\",\n", " \"onyx:hasEmotionIntensity\": 0.06258366271018097\n", " },\n", " {\n", " \"@type\": \"Emotion\",\n", " \"onyx:hasEmotionCategory\": \"wna:amusement\",\n", " \"onyx:hasEmotionIntensity\": 0.15784834034155437\n", " },\n", " {\n", " \"@type\": \"Emotion\",\n", " \"onyx:hasEmotionCategory\": \"wna:anger\",\n", " \"onyx:hasEmotionIntensity\": 0.08728815135373413\n", " },\n", " {\n", " \"@type\": \"Emotion\",\n", " \"onyx:hasEmotionCategory\": \"wna:annoyance\",\n", " \"onyx:hasEmotionIntensity\": 0.12184635680460143\n", " },\n", " {\n", " \"@type\": \"Emotion\",\n", " \"onyx:hasEmotionCategory\": \"wna:indifference\",\n", " \"onyx:hasEmotionIntensity\": 0.1374081151031531\n", " },\n", " {\n", " \"@type\": \"Emotion\",\n", " \"onyx:hasEmotionCategory\": \"wna:joy\",\n", " \"onyx:hasEmotionIntensity\": 0.12267040802346799\n", " },\n", " {\n", " \"@type\": \"Emotion\",\n", " \"onyx:hasEmotionCategory\": \"wna:awe\",\n", " \"onyx:hasEmotionIntensity\": 0.21085262130713067\n", " },\n", " {\n", " \"@type\": \"Emotion\",\n", " \"onyx:hasEmotionCategory\": \"wna:sadness\",\n", " \"onyx:hasEmotionIntensity\": 0.09950234435617733\n", " }\n", " ],\n", " \"prov:wasGeneratedBy\": \"prefix:Analysis_1563372853.9469151\"\n", " }\n", " ]\n", " }\n", " ]\n", "}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query(f'{endpoint}/emotion-depechemood',\n", " input=\"Senpy is a wonderful that service\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you have probably noticed, there are several emotions in this result, each with a different intensity.\n", "\n", "We can also tell senpy to only return the emotion with the maximum intensity using the `maxemotion` parameter:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
{\n",
       "  "@context": "http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tZGVwZWNoZW1vb2Q_aW5wdXQ9U2VucHkraXMrYSt3b25kZXJmdWwrc2VydmljZSZtYXhlbW90aW9uPVRydWUj",\n",
       "  "@type": "Results",\n",
       "  "entries": [\n",
       "    {\n",
       "      "@id": "prefix:",\n",
       "      "@type": "Entry",\n",
       "      "marl:hasOpinion": [],\n",
       "      "nif:isString": "Senpy is a wonderful service",\n",
       "      "onyx:hasEmotionSet": [\n",
       "        {\n",
       "          "@type": "EmotionSet",\n",
       "          "onyx:hasEmotion": [\n",
       "            {\n",
       "              "@type": "Emotion",\n",
       "              "onyx:hasEmotionCategory": "wna:awe",\n",
       "              "onyx:hasEmotionIntensity": 0.21085262130713067\n",
       "            }\n",
       "          ],\n",
       "          "prov:wasGeneratedBy": "prefix:Analysis_1563372854.0490181"\n",
       "        }\n",
       "      ]\n",
       "    }\n",
       "  ]\n",
       "}\n",
       "
\n" ], "text/latex": [ "\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n", "\\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@context\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tZGVwZWNoZW1vb2Q\\PYZus{}aW5wdXQ9U2VucHkraXMrYSt3b25kZXJmdWwrc2VydmljZSZtYXhlbW90aW9uPVRydWUj\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Results\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}entries\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@id\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Entry\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}marl:hasOpinion\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\\PY{p}{]}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}nif:isString\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Senpy is a wonderful service\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionSet\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}EmotionSet\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotion\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotion\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionCategory\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}wna:awe\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionIntensity\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{0.21085262130713067}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}prov:wasGeneratedBy\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:Analysis\\PYZus{}1563372854.0490181\\PYZdq{}}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\n", "\\PY{p}{\\PYZcb{}}\n", "\\end{Verbatim}\n" ], "text/plain": [ "{\n", " \"@context\": \"http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tZGVwZWNoZW1vb2Q_aW5wdXQ9U2VucHkraXMrYSt3b25kZXJmdWwrc2VydmljZSZtYXhlbW90aW9uPVRydWUj\",\n", " \"@type\": \"Results\",\n", " \"entries\": [\n", " {\n", " \"@id\": \"prefix:\",\n", " \"@type\": \"Entry\",\n", " \"marl:hasOpinion\": [],\n", " \"nif:isString\": \"Senpy is a wonderful service\",\n", " \"onyx:hasEmotionSet\": [\n", " {\n", " \"@type\": \"EmotionSet\",\n", " \"onyx:hasEmotion\": [\n", " {\n", " \"@type\": \"Emotion\",\n", " \"onyx:hasEmotionCategory\": \"wna:awe\",\n", " \"onyx:hasEmotionIntensity\": 0.21085262130713067\n", " }\n", " ],\n", " \"prov:wasGeneratedBy\": \"prefix:Analysis_1563372854.0490181\"\n", " }\n", " ]\n", " }\n", " ]\n", "}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query(f'{endpoint}/emotion-depechemood',\n", " input=\"Senpy is a wonderful service\",\n", " maxemotion=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Emotion conversion\n", "\n", "Sometimes the model used by a plugin is not right for your application. Senpy ships with emotion conversion capabilities: you can ask for a specific emotion model in your request and the service will try to automatically convert the results.\n", "\n", "For example, the `emotion-anew` plugin uses the dimensional `pad` (or VAD, valence-arousal-dominance) model, as we can see here:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
{\n",
       "  "@context": "http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tYW5ldz9pbnB1dD1TZW5weStpcythK3dvbmRlcmZ1bCtzZXJ2aWNlK2FuZCtJK2xvdmUraXQj",\n",
       "  "@type": "Results",\n",
       "  "entries": [\n",
       "    {\n",
       "      "@id": "prefix:",\n",
       "      "@type": "Entry",\n",
       "      "marl:hasOpinion": [],\n",
       "      "nif:isString": "Senpy is a wonderful service and I love it",\n",
       "      "onyx:hasEmotionSet": [\n",
       "        {\n",
       "          "@id": "Emotions0",\n",
       "          "@type": "EmotionSet",\n",
       "          "onyx:hasEmotion": [\n",
       "            {\n",
       "              "@id": "Emotion0",\n",
       "              "@type": "Emotion",\n",
       "              "http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#arousal": 6.44,\n",
       "              "http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#dominance": 7.11,\n",
       "              "http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#valence": 8.72,\n",
       "              "prov:wasGeneratedBy": "prefix:Analysis_1563372854.2822595"\n",
       "            }\n",
       "          ],\n",
       "          "prov:wasGeneratedBy": "prefix:Analysis_1563372854.2822595"\n",
       "        }\n",
       "      ]\n",
       "    }\n",
       "  ]\n",
       "}\n",
       "
\n" ], "text/latex": [ "\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n", "\\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@context\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tYW5ldz9pbnB1dD1TZW5weStpcythK3dvbmRlcmZ1bCtzZXJ2aWNlK2FuZCtJK2xvdmUraXQj\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Results\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}entries\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@id\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Entry\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}marl:hasOpinion\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\\PY{p}{]}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}nif:isString\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Senpy is a wonderful service and I love it\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionSet\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@id\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotions0\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}EmotionSet\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotion\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@id\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotion0\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotion\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns\\PYZsh{}arousal\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{6.44}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns\\PYZsh{}dominance\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{7.11}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns\\PYZsh{}valence\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{8.72}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}prov:wasGeneratedBy\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:Analysis\\PYZus{}1563372854.2822595\\PYZdq{}}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}prov:wasGeneratedBy\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:Analysis\\PYZus{}1563372854.2822595\\PYZdq{}}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\n", "\\PY{p}{\\PYZcb{}}\n", "\\end{Verbatim}\n" ], "text/plain": [ "{\n", " \"@context\": \"http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tYW5ldz9pbnB1dD1TZW5weStpcythK3dvbmRlcmZ1bCtzZXJ2aWNlK2FuZCtJK2xvdmUraXQj\",\n", " \"@type\": \"Results\",\n", " \"entries\": [\n", " {\n", " \"@id\": \"prefix:\",\n", " \"@type\": \"Entry\",\n", " \"marl:hasOpinion\": [],\n", " \"nif:isString\": \"Senpy is a wonderful service and I love it\",\n", " \"onyx:hasEmotionSet\": [\n", " {\n", " \"@id\": \"Emotions0\",\n", " \"@type\": \"EmotionSet\",\n", " \"onyx:hasEmotion\": [\n", " {\n", " \"@id\": \"Emotion0\",\n", " \"@type\": \"Emotion\",\n", " \"http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#arousal\": 6.44,\n", " \"http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#dominance\": 7.11,\n", " \"http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#valence\": 8.72,\n", " \"prov:wasGeneratedBy\": \"prefix:Analysis_1563372854.2822595\"\n", " }\n", " ],\n", " \"prov:wasGeneratedBy\": \"prefix:Analysis_1563372854.2822595\"\n", " }\n", " ]\n", " }\n", " ]\n", "}" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query(f'{endpoint}/emotion-anew',\n", " input=\"Senpy is a wonderful service and I love it\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we need a category level, we can ask for the equivalent results in the `big6` model:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
{\n",
       "  "@context": "http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tYW5ldz9pbnB1dD1TZW5weStpcythK3dvbmRlcmZ1bCtzZXJ2aWNlK2FuZCtJK2xvdmUraXQmZW1vdGlvbm1vZGVsPWVtb21sJTNBYmlnNiM%3D",\n",
       "  "@type": "Results",\n",
       "  "entries": [\n",
       "    {\n",
       "      "@id": "prefix:",\n",
       "      "@type": "Entry",\n",
       "      "marl:hasOpinion": [],\n",
       "      "nif:isString": "Senpy is a wonderful service and I love it",\n",
       "      "onyx:hasEmotionSet": [\n",
       "        {\n",
       "          "@id": "Emotions0",\n",
       "          "@type": "EmotionSet",\n",
       "          "onyx:hasEmotion": [\n",
       "            {\n",
       "              "@id": "Emotion0",\n",
       "              "@type": "Emotion",\n",
       "              "http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#arousal": 6.44,\n",
       "              "http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#dominance": 7.11,\n",
       "              "http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#valence": 8.72,\n",
       "              "prov:wasGeneratedBy": "prefix:Analysis_1563372854.3354168"\n",
       "            }\n",
       "          ],\n",
       "          "prov:wasGeneratedBy": "prefix:Analysis_1563372854.3354168"\n",
       "        }\n",
       "      ]\n",
       "    }\n",
       "  ]\n",
       "}\n",
       "
\n" ], "text/latex": [ "\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n", "\\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@context\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tYW5ldz9pbnB1dD1TZW5weStpcythK3dvbmRlcmZ1bCtzZXJ2aWNlK2FuZCtJK2xvdmUraXQmZW1vdGlvbm1vZGVsPWVtb21sJTNBYmlnNiM\\PYZpc{}3D\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Results\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}entries\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@id\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Entry\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}marl:hasOpinion\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\\PY{p}{]}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}nif:isString\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Senpy is a wonderful service and I love it\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionSet\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@id\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotions0\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}EmotionSet\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotion\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@id\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotion0\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotion\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns\\PYZsh{}arousal\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{6.44}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns\\PYZsh{}dominance\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{7.11}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns\\PYZsh{}valence\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{8.72}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}prov:wasGeneratedBy\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:Analysis\\PYZus{}1563372854.3354168\\PYZdq{}}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}prov:wasGeneratedBy\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:Analysis\\PYZus{}1563372854.3354168\\PYZdq{}}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\n", "\\PY{p}{\\PYZcb{}}\n", "\\end{Verbatim}\n" ], "text/plain": [ "{\n", " \"@context\": \"http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tYW5ldz9pbnB1dD1TZW5weStpcythK3dvbmRlcmZ1bCtzZXJ2aWNlK2FuZCtJK2xvdmUraXQmZW1vdGlvbm1vZGVsPWVtb21sJTNBYmlnNiM%3D\",\n", " \"@type\": \"Results\",\n", " \"entries\": [\n", " {\n", " \"@id\": \"prefix:\",\n", " \"@type\": \"Entry\",\n", " \"marl:hasOpinion\": [],\n", " \"nif:isString\": \"Senpy is a wonderful service and I love it\",\n", " \"onyx:hasEmotionSet\": [\n", " {\n", " \"@id\": \"Emotions0\",\n", " \"@type\": \"EmotionSet\",\n", " \"onyx:hasEmotion\": [\n", " {\n", " \"@id\": \"Emotion0\",\n", " \"@type\": \"Emotion\",\n", " \"http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#arousal\": 6.44,\n", " \"http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#dominance\": 7.11,\n", " \"http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#valence\": 8.72,\n", " \"prov:wasGeneratedBy\": \"prefix:Analysis_1563372854.3354168\"\n", " }\n", " ],\n", " \"prov:wasGeneratedBy\": \"prefix:Analysis_1563372854.3354168\"\n", " }\n", " ]\n", " }\n", " ]\n", "}" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query(f'{endpoint}/emotion-anew',\n", " input=\"Senpy is a wonderful service and I love it\",\n", " emotionmodel=\"emoml:big6\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Because we don't usually care about the original emotion, the conversion can be presented in three ways:\n", "\n", "* full: the original and converted emotions are included at the same level\n", "* filtered: the original emotion is replaced by the converted emotion\n", "* nested: the original emotion is replaced, but the converted emotion points to it\n", "\n", "For example, here's how the `nested` structure would look like:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
{\n",
       "  "@context": "http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tYW5ldz9pbnB1dD1TZW5weStpcythK3dvbmRlcmZ1bCtzZXJ2aWNlK2FuZCtJK2xvdmUraXQmZW1vdGlvbm1vZGVsPWVtb21sJTNBYmlnNiZjb252ZXJzaW9uPW5lc3RlZCM%3D",\n",
       "  "@type": "Results",\n",
       "  "entries": [\n",
       "    {\n",
       "      "@id": "prefix:",\n",
       "      "@type": "Entry",\n",
       "      "marl:hasOpinion": [],\n",
       "      "nif:isString": "Senpy is a wonderful service and I love it",\n",
       "      "onyx:hasEmotionSet": [\n",
       "        {\n",
       "          "@id": "Emotions0",\n",
       "          "@type": "EmotionSet",\n",
       "          "onyx:hasEmotion": [\n",
       "            {\n",
       "              "@id": "Emotion0",\n",
       "              "@type": "Emotion",\n",
       "              "http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#arousal": 6.44,\n",
       "              "http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#dominance": 7.11,\n",
       "              "http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#valence": 8.72,\n",
       "              "prov:wasGeneratedBy": "prefix:Analysis_1563372854.3876536"\n",
       "            }\n",
       "          ],\n",
       "          "prov:wasGeneratedBy": "prefix:Analysis_1563372854.3876536"\n",
       "        }\n",
       "      ]\n",
       "    }\n",
       "  ]\n",
       "}\n",
       "
\n" ], "text/latex": [ "\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n", "\\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@context\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tYW5ldz9pbnB1dD1TZW5weStpcythK3dvbmRlcmZ1bCtzZXJ2aWNlK2FuZCtJK2xvdmUraXQmZW1vdGlvbm1vZGVsPWVtb21sJTNBYmlnNiZjb252ZXJzaW9uPW5lc3RlZCM\\PYZpc{}3D\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Results\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}entries\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@id\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Entry\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}marl:hasOpinion\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\\PY{p}{]}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}nif:isString\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Senpy is a wonderful service and I love it\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionSet\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@id\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotions0\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}EmotionSet\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}onyx:hasEmotion\\PYZdq{}}\\PY{p}{:} \\PY{p}{[}\n", " \\PY{p}{\\PYZob{}}\n", " \\PY{n+nd}{\\PYZdq{}@id\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotion0\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nd}{\\PYZdq{}@type\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}Emotion\\PYZdq{}}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns\\PYZsh{}arousal\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{6.44}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns\\PYZsh{}dominance\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{7.11}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns\\PYZsh{}valence\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{8.72}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}prov:wasGeneratedBy\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:Analysis\\PYZus{}1563372854.3876536\\PYZdq{}}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\\PY{p}{,}\n", " \\PY{n+nt}{\\PYZdq{}prov:wasGeneratedBy\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:Analysis\\PYZus{}1563372854.3876536\\PYZdq{}}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\n", " \\PY{p}{\\PYZcb{}}\n", " \\PY{p}{]}\n", "\\PY{p}{\\PYZcb{}}\n", "\\end{Verbatim}\n" ], "text/plain": [ "{\n", " \"@context\": \"http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tYW5ldz9pbnB1dD1TZW5weStpcythK3dvbmRlcmZ1bCtzZXJ2aWNlK2FuZCtJK2xvdmUraXQmZW1vdGlvbm1vZGVsPWVtb21sJTNBYmlnNiZjb252ZXJzaW9uPW5lc3RlZCM%3D\",\n", " \"@type\": \"Results\",\n", " \"entries\": [\n", " {\n", " \"@id\": \"prefix:\",\n", " \"@type\": \"Entry\",\n", " \"marl:hasOpinion\": [],\n", " \"nif:isString\": \"Senpy is a wonderful service and I love it\",\n", " \"onyx:hasEmotionSet\": [\n", " {\n", " \"@id\": \"Emotions0\",\n", " \"@type\": \"EmotionSet\",\n", " \"onyx:hasEmotion\": [\n", " {\n", " \"@id\": \"Emotion0\",\n", " \"@type\": \"Emotion\",\n", " \"http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#arousal\": 6.44,\n", " \"http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#dominance\": 7.11,\n", " \"http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#valence\": 8.72,\n", " \"prov:wasGeneratedBy\": \"prefix:Analysis_1563372854.3876536\"\n", " }\n", " ],\n", " \"prov:wasGeneratedBy\": \"prefix:Analysis_1563372854.3876536\"\n", " }\n", " ]\n", " }\n", " ]\n", "}" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "query(f'{endpoint}/emotion-anew',\n", " input=\"Senpy is a wonderful service and I love it\",\n", " emotionmodel=\"emoml:big6\",\n", " conversion=\"nested\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Learn more\n", "\n", "[A separate notebook](Advanced.ipynb) covers advanced topics such as listing all plugins available in an endpoint, or creating analysis pipelines that chain several analysis services." ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python 3", "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.7.3" }, "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_minor": 1 }