Commit 435d1076 authored by J. Fernando Sánchez's avatar J. Fernando Sánchez
Browse files

Add headers and minor fixes

parent c4321dc5
......@@ -4,8 +4,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
## [1.0.1]
### Added
* License headers
* Description for PyPI (setup.py)
### Changed
* The evaluation tab shows datasets inline, and a tooltip shows the number of instances
* The docs should be clearer now
## [1.0.0]
### Fixed
* Restored hash changing function in `main.js`
......
......@@ -4,20 +4,19 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Senpy in 30 minutes"
"# Advanced features"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This tutorial takes up where the [10 minute tutorial](Quickstart-10minutes.ipynb) left off.\n",
"This tutorial takes up where the [basic tutorial](Quickstart.ipynb) left off.\n",
"\n",
"It covers more advanced tasks such as:\n",
"\n",
"* Asking for specific emotion models (automatic model conversion)\n",
"* Listing available services in an endpoint\n",
"* Transforming the results\n",
"* Transforming the results of a service\n",
"* Calling multiple services in the same request (Pipelines)\n",
"* Running your own Senpy instance"
]
......@@ -47,25 +46,22 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"try:\n",
" from IPython.display import Code\n",
" def pretty(txt, language='json-ld'):\n",
" return Code(txt, language=language)\n",
"except ImportError:\n",
" def pretty(txt, **kwargs):\n",
" print(txt)"
"from IPython.display import Code\n",
" \n",
"def query(endpoint, raw=False, **kwargs):\n",
" '''Query a given Senpy endpoint with specific parameters, and prettify the output'''\n",
" res = requests.get(endpoint,\n",
" params=kwargs)\n",
" if raw:\n",
" return res\n",
" return Code(res.text, language=kwargs.get('outformat', 'json-ld'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -87,137 +83,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\"Senpy is a wonderful service\"]\n"
]
}
],
"source": [
"res = requests.get(f'{endpoint}/sentiment140',\n",
" params={\"input\": \"Senpy is a wonderful service\",\n",
" \"fields\": 'entries[].\"nif:isString\"'})\n",
"print(res.text)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Or we could get both the text and the polarity of the text (assuming there is only one opinion per entry) with a slightly more complicated query:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\"Senpy is a service. Wonderful service.\", \"marl:Neutral\"]\n"
]
}
],
"source": [
"res = requests.get(f'{endpoint}/sentiment140',\n",
" params={\"input\": \"Senpy is a service. Wonderful service.\",\n",
" \"delimiter\": \"sentence\",\n",
" \"fields\": 'entries[0].[\"nif:isString\", \"marl:hasOpinion\"[0].\"marl:hasPolarity\"]'})\n",
"print(res.text)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"jmespath is rather extensive for this tutorial. We will cover only the most simple cases, so you do not need to learn much about the notation.\n",
"\n",
"For more complicated transformations, check out [jmespath](http://jmespath.org).\n",
"In addition to a fairly complete documentation, they have a live environment you can use to test your queries."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Emotion conversion"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If the model used by a plugin is not right for your application, you can ask for a specific emotion model in your request.\n",
"\n",
"Senpy ships with emotion conversion capabilities, and it 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": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{\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_1554382982.775705\"\n",
" }\n",
" ],\n",
" \"prov:wasGeneratedBy\": \"prefix:Analysis_1554382982.775705\"\n",
" }\n",
" ]\n",
" }\n",
" ]\n",
"}\n"
]
}
],
"source": [
"res = requests.get(f'{endpoint}/emotion-anew',\n",
" params={\"input\": \"Senpy is a wonderful service and I love it\"})\n",
"print(res.text)"
]
},
{
"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": 14,
"execution_count": 3,
"metadata": {},
"outputs": [
{
......@@ -291,163 +157,39 @@
".output_html .vg { color: #19177C } /* Name.Variable.Global */\n",
".output_html .vi { color: #19177C } /* Name.Variable.Instance */\n",
".output_html .vm { color: #19177C } /* Name.Variable.Magic */\n",
".output_html .il { color: #666666 } /* Literal.Number.Integer.Long */</style><div class=\"highlight\"><pre><span></span><span class=\"p\">{</span>\n",
" <span class=\"nd\">&quot;@context&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tYW5ldz9pbnB1dD1TZW5weStpcythK3dvbmRlcmZ1bCtzZXJ2aWNlK2FuZCtJK2xvdmUraXQmZW1vdGlvbi1tb2RlbD1lbW9tbCUzQWJpZzYj&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nd\">&quot;@type&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Results&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;entries&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span>\n",
" <span class=\"p\">{</span>\n",
" <span class=\"nd\">&quot;@id&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;prefix:&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nd\">&quot;@type&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Entry&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;marl:hasOpinion&quot;</span><span class=\"p\">:</span> <span class=\"p\">[],</span>\n",
" <span class=\"nt\">&quot;nif:isString&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Senpy is a wonderful service and I love it&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;onyx:hasEmotionSet&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span>\n",
" <span class=\"p\">{</span>\n",
" <span class=\"nd\">&quot;@id&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Emotions0&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nd\">&quot;@type&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;EmotionSet&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;onyx:hasEmotion&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span>\n",
" <span class=\"p\">{</span>\n",
" <span class=\"nd\">&quot;@id&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Emotion0&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nd\">&quot;@type&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Emotion&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#arousal&quot;</span><span class=\"p\">:</span> <span class=\"mf\">6.44</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#dominance&quot;</span><span class=\"p\">:</span> <span class=\"mf\">7.11</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#valence&quot;</span><span class=\"p\">:</span> <span class=\"mf\">8.72</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;prov:wasGeneratedBy&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;prefix:Analysis_1554382982.8068626&quot;</span>\n",
" <span class=\"p\">}</span>\n",
" <span class=\"p\">],</span>\n",
" <span class=\"nt\">&quot;prov:wasGeneratedBy&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;prefix:Analysis_1554382982.8068626&quot;</span>\n",
" <span class=\"p\">},</span>\n",
" <span class=\"p\">{</span>\n",
" <span class=\"nd\">&quot;@type&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;EmotionSet&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;onyx:hasEmotion&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span>\n",
" <span class=\"p\">{</span>\n",
" <span class=\"nd\">&quot;@type&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Emotion&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;onyx:algorithmConfidence&quot;</span><span class=\"p\">:</span> <span class=\"mf\">7.449999999999999</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;onyx:hasEmotionCategory&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;emoml:big6fear&quot;</span>\n",
" <span class=\"p\">}</span>\n",
" <span class=\"p\">],</span>\n",
" <span class=\"nt\">&quot;prov:wasGeneratedBy&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;prefix:Analysis_1554382982.8106468&quot;</span>\n",
" <span class=\"p\">}</span>\n",
" <span class=\"p\">]</span>\n",
" <span class=\"p\">}</span>\n",
" <span class=\"p\">]</span>\n",
"<span class=\"p\">}</span>\n",
".output_html .il { color: #666666 } /* Literal.Number.Integer.Long */</style><div class=\"highlight\"><pre><span></span><span class=\"p\">[</span><span class=\"s2\">&quot;Senpy is a wonderful service&quot;</span><span class=\"p\">]</span>\n",
"</pre></div>\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/YXBpL2Vtb3Rpb24tYW5ldz9pbnB1dD1TZW5weStpcythK3dvbmRlcmZ1bCtzZXJ2aWNlK2FuZCtJK2xvdmUraXQmZW1vdGlvbi1tb2RlbD1lbW9tbCUzQWJpZzYj\\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{}1554382982.8068626\\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{}1554382982.8068626\\PYZdq{}}\n",
" \\PY{p}{\\PYZcb{}}\\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:algorithmConfidence\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{7.449999999999999}\\PY{p}{,}\n",
" \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionCategory\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}emoml:big6fear\\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{}1554382982.8106468\\PYZdq{}}\n",
" \\PY{p}{\\PYZcb{}}\n",
" \\PY{p}{]}\n",
" \\PY{p}{\\PYZcb{}}\n",
" \\PY{p}{]}\n",
"\\PY{p}{\\PYZcb{}}\n",
"\\PY{p}{[}\\PY{l+s+s2}{\\PYZdq{}Senpy is a wonderful service\\PYZdq{}}\\PY{p}{]}\n",
"\\end{Verbatim}\n"
],
"text/plain": [
"{\n",
" \"@context\": \"http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tYW5ldz9pbnB1dD1TZW5weStpcythK3dvbmRlcmZ1bCtzZXJ2aWNlK2FuZCtJK2xvdmUraXQmZW1vdGlvbi1tb2RlbD1lbW9tbCUzQWJpZzYj\",\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_1554382982.8068626\"\n",
" }\n",
" ],\n",
" \"prov:wasGeneratedBy\": \"prefix:Analysis_1554382982.8068626\"\n",
" },\n",
" {\n",
" \"@type\": \"EmotionSet\",\n",
" \"onyx:hasEmotion\": [\n",
" {\n",
" \"@type\": \"Emotion\",\n",
" \"onyx:algorithmConfidence\": 7.449999999999999,\n",
" \"onyx:hasEmotionCategory\": \"emoml:big6fear\"\n",
" }\n",
" ],\n",
" \"prov:wasGeneratedBy\": \"prefix:Analysis_1554382982.8106468\"\n",
" }\n",
" ]\n",
" }\n",
" ]\n",
"}"
"[\"Senpy is a wonderful service\"]"
]
},
"execution_count": 14,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res = requests.get(f'{endpoint}/emotion-anew',\n",
" params={\"input\": \"Senpy is a wonderful service and I love it\",\n",
" \"emotion-model\": \"emoml:big6\"})\n",
"pretty(res.text)"
"query(f'{endpoint}/sentiment140',\n",
" input=\"Senpy is a wonderful service\",\n",
" fields='entries[].\"nif:isString\"')"
]
},
{
"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:"
"Or we could get both the text and the polarity of the text (assuming there is only one opinion per entry) with a slightly more complicated query:"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 4,
"metadata": {},
"outputs": [
{
......@@ -521,158 +263,57 @@
".output_html .vg { color: #19177C } /* Name.Variable.Global */\n",
".output_html .vi { color: #19177C } /* Name.Variable.Instance */\n",
".output_html .vm { color: #19177C } /* Name.Variable.Magic */\n",
".output_html .il { color: #666666 } /* Literal.Number.Integer.Long */</style><div class=\"highlight\"><pre><span></span><span class=\"p\">{</span>\n",
" <span class=\"nd\">&quot;@context&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tYW5ldz9pbnB1dD1TZW5weStpcythK3dvbmRlcmZ1bCtzZXJ2aWNlK2FuZCtJK2xvdmUraXQmZW1vdGlvbi1tb2RlbD1lbW9tbCUzQWJpZzYmY29udmVyc2lvbj1uZXN0ZWQj&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nd\">&quot;@type&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Results&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;entries&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span>\n",
" <span class=\"p\">{</span>\n",
" <span class=\"nd\">&quot;@id&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;prefix:&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nd\">&quot;@type&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Entry&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;marl:hasOpinion&quot;</span><span class=\"p\">:</span> <span class=\"p\">[],</span>\n",
" <span class=\"nt\">&quot;nif:isString&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Senpy is a wonderful service and I love it&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;onyx:hasEmotionSet&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span>\n",
" <span class=\"p\">{</span>\n",
" <span class=\"nd\">&quot;@type&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;EmotionSet&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;onyx:hasEmotion&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span>\n",
" <span class=\"p\">{</span>\n",
" <span class=\"nd\">&quot;@type&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Emotion&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;onyx:algorithmConfidence&quot;</span><span class=\"p\">:</span> <span class=\"mf\">7.449999999999999</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;onyx:hasEmotionCategory&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;emoml:big6fear&quot;</span>\n",
" <span class=\"p\">}</span>\n",
" <span class=\"p\">],</span>\n",
" <span class=\"nt\">&quot;prov:wasDerivedFrom&quot;</span><span class=\"p\">:</span> <span class=\"p\">{</span>\n",
" <span class=\"nd\">&quot;@id&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Emotions0&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nd\">&quot;@type&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;EmotionSet&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;onyx:hasEmotion&quot;</span><span class=\"p\">:</span> <span class=\"p\">[</span>\n",
" <span class=\"p\">{</span>\n",
" <span class=\"nd\">&quot;@id&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Emotion0&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nd\">&quot;@type&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Emotion&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#arousal&quot;</span><span class=\"p\">:</span> <span class=\"mf\">6.44</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#dominance&quot;</span><span class=\"p\">:</span> <span class=\"mf\">7.11</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;http://www.gsi.dit.upm.es/ontologies/onyx/vocabularies/anew/ns#valence&quot;</span><span class=\"p\">:</span> <span class=\"mf\">8.72</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;prov:wasGeneratedBy&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;prefix:Analysis_1554382982.8948743&quot;</span>\n",
" <span class=\"p\">}</span>\n",
" <span class=\"p\">],</span>\n",
" <span class=\"nt\">&quot;prov:wasGeneratedBy&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;prefix:Analysis_1554382982.8948743&quot;</span>\n",
" <span class=\"p\">},</span>\n",
" <span class=\"nt\">&quot;prov:wasGeneratedBy&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;prefix:Analysis_1554382982.8985674&quot;</span>\n",
" <span class=\"p\">}</span>\n",
" <span class=\"p\">]</span>\n",
" <span class=\"p\">}</span>\n",
" <span class=\"p\">]</span>\n",
"<span class=\"p\">}</span>\n",
".output_html .il { color: #666666 } /* Literal.Number.Integer.Long */</style><div class=\"highlight\"><pre><span></span><span class=\"p\">[</span><span class=\"s2\">&quot;Senpy is a service. Wonderful service.&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;marl:Neutral&quot;</span><span class=\"p\">]</span>\n",
"</pre></div>\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/YXBpL2Vtb3Rpb24tYW5ldz9pbnB1dD1TZW5weStpcythK3dvbmRlcmZ1bCtzZXJ2aWNlK2FuZCtJK2xvdmUraXQmZW1vdGlvbi1tb2RlbD1lbW9tbCUzQWJpZzYmY29udmVyc2lvbj1uZXN0ZWQj\\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{}@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:algorithmConfidence\\PYZdq{}}\\PY{p}{:} \\PY{l+m+mf}{7.449999999999999}\\PY{p}{,}\n",
" \\PY{n+nt}{\\PYZdq{}onyx:hasEmotionCategory\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}emoml:big6fear\\PYZdq{}}\n",
" \\PY{p}{\\PYZcb{}}\n",
" \\PY{p}{]}\\PY{p}{,}\n",
" \\PY{n+nt}{\\PYZdq{}prov:wasDerivedFrom\\PYZdq{}}\\PY{p}{:} \\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{}1554382982.8948743\\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{}1554382982.8948743\\PYZdq{}}\n",
" \\PY{p}{\\PYZcb{}}\\PY{p}{,}\n",
" \\PY{n+nt}{\\PYZdq{}prov:wasGeneratedBy\\PYZdq{}}\\PY{p}{:} \\PY{l+s+s2}{\\PYZdq{}prefix:Analysis\\PYZus{}1554382982.8985674\\PYZdq{}}\n",
" \\PY{p}{\\PYZcb{}}\n",
" \\PY{p}{]}\n",
" \\PY{p}{\\PYZcb{}}\n",
" \\PY{p}{]}\n",
"\\PY{p}{\\PYZcb{}}\n",
"\\PY{p}{[}\\PY{l+s+s2}{\\PYZdq{}Senpy is a service. Wonderful service.\\PYZdq{}}\\PY{p}{,} \\PY{l+s+s2}{\\PYZdq{}marl:Neutral\\PYZdq{}}\\PY{p}{]}\n",
"\\end{Verbatim}\n"
],
"text/plain": [
"{\n",
" \"@context\": \"http://senpy.gsi.upm.es/api/contexts/YXBpL2Vtb3Rpb24tYW5ldz9pbnB1dD1TZW5weStpcythK3dvbmRlcmZ1bCtzZXJ2aWNlK2FuZCtJK2xvdmUraXQmZW1vdGlvbi1tb2RlbD1lbW9tbCUzQWJpZzYmY29udmVyc2lvbj1uZXN0ZWQj\",\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",
" \"@type\": \"EmotionSet\",\n",
" \"onyx:hasEmotion\": [\n",
" {\n",
" \"@type\": \"Emotion\",\n",
" \"onyx:algorithmConfidence\": 7.449999999999999,\n",
" \"onyx:hasEmotionCategory\": \"emoml:big6fear\"\n",
" }\n",
" ],\n",
" \"prov:wasDerivedFrom\": {\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_1554382982.8948743\"\n",
" }\n",
" ],\n",
" \"prov:wasGeneratedBy\": \"prefix:Analysis_1554382982.8948743\"\n",
" },\n",
" \"prov:wasGeneratedBy\": \"prefix:Analysis_1554382982.8985674\"\n",
" }\n",
" ]\n",
" }\n",
" ]\n",
"}"
"[\"Senpy is a service. Wonderful service.\", \"marl:Neutral\"]"
]
},
"execution_count": 15,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res = requests.get(f'{endpoint}/emotion-anew',\n",
" params={\"input\": \"Senpy is a wonderful service and I love it\",\n",
" \"emotion-model\": \"emoml:big6\",\n",
" \"conversion\": \"nested\"})\n",
"pretty(res.text)"
"query(f'{endpoint}/sentiment140',\n",
" input=\"Senpy is a service. Wonderful service.\",\n",
" delimiter=\"sentence\",\n",
" fields='entries[0].[\"nif:isString\", \"marl:hasOpinion\"[0].\"marl:hasPolarity\"]')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"jmespath is rather extensive for this tutorial. We will cover only the most simple cases, so you do not need to learn much about the notation.\n",
"\n",
"For more complicated transformations, check out [jmespath](http://jmespath.org).\n",
"In addition to a fairly complete documentation, they have a live environment you can use to test your queries."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Emotion conversion with field selection"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Again, for completion, we could get only the label with the `fields` parameter:"
"We could mix emotion conversion with field selection to only get the label of an emotion analysis that has been automatically converted:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 5,
"metadata": {},
"outputs": [
{
......@@ -746,30 +387,29 @@
".output_html .vg { color: #19177C } /* Name.Variable.Global */\n",
".output_html .vi { color: #19177C } /* Name.Variable.Instance */\n",
".output_html .vm { color: #19177C } /* Name.Variable.Magic */\n",
".output_html .il { color: #666666 } /* Literal.Number.Integer.Long */</style><div class=\"highlight\"><pre><span></span><span class=\"p\">[[</span><span class=\"s2\">&quot;Senpy is a wonderful service and I love it&quot;</span><span class=\"p\">,</span> <span class=\"s2\">&quot;emoml:big6fear&quot;</span><span class=\"p\">]]</span>\n",
".output_html .il { color: #666666 } /* Literal.Number.Integer.Long */</style><div class=\"highlight\"><pre><span></span><span class=\"p\">[[</span><span class=\"s2\">&quot;Senpy is a wonderful service and I love it&quot;</span><span class=\"p\">]]</span>\n",
"</pre></div>\n"
],
"text/latex": [
"\\begin{Verbatim}[commandchars=\\\\\\{\\}]\n",
"\\PY{p}{[}\\PY{p}{[}\\PY{l+s+s2}{\\PYZdq{}Senpy is a wonderful service and I love it\\PYZdq{}}\\PY{p}{,} \\PY{l+s+s2}{\\PYZdq{}emoml:big6fear\\PYZdq{}}\\PY{p}{]}\\PY{p}{]}\n",
"\\PY{p}{[}\\PY{p}{[}\\PY{l+s+s2}{\\PYZdq{}Senpy is a wonderful service and I love it\\PYZdq{}}\\PY{p}{]}\\PY{p}{]}\n",
"\\end{Verbatim}\n"
],
"text/plain": [
"[[\"Senpy is a wonderful service and I love it\", \"emoml:big6fear\"]]"
"[[\"Senpy is a wonderful service and I love it\"]]"
]
},
"execution_count": 16,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res = requests.get(f'{endpoint}/emotion-anew',\n",
" params={\"input\": \"Senpy is a wonderful service and I love it\",\n",
" \"emotion-model\": \"emoml:big6\",\n",
" \"fields\": 'entries[].[[\"nif:isString\",\"onyx:hasEmotionSet\"[].\"onyx:hasEmotion\"[].\"onyx:hasEmotionCategory\"][]][]',\n",
" \"conversion\": \"filtered\"})\n",
"pretty(res.text)"
"query(f'{endpoint}/emotion-anew',\n",
" input=\"Senpy is a wonderful service and I love it\",\n",
" emotionmodel=\"emoml:big6\",\n",
" fields='entries[].[[\"nif:isString\",\"onyx:hasEmotionSet\"[].\"onyx:hasEmotion\"[].\"onyx:hasEmotionCategory\"][]][]',\n",
" conversion=\"filtered\")"
]
},
{
......@@ -793,7 +433,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 6,
"metadata": {},
"outputs": [
{
......@@ -878,7 +518,7 @@
" <span class=\"p\">{</span>\n",
" <span class=\"nd\">&quot;@type&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Sentiment&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;marl:hasPolarity&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;marl:Neutral&quot;</span><span class=\"p\">,</span>\n",
" <span class=\"nt\">&quot;prov:wasGeneratedBy&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;prefix:Analysis_1554382983.2991712&quot;</span>\n",
" <span class=\"nt\">&quot;prov:wasGeneratedBy&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;prefix:Analysis_1563369539.5176148&quot;</span>\n",
" <span class=\"p\">}</span>\n",
" <span class=\"p\">],</span>\n",
" <span class=\"nt\">&quot;nif:isString&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;Senpy is a wonderful service&quot;</span><span class=\"p\">,</span>\n",
......@@ -927,7 +567,7 @@
" <span class=\"nt\">&quot;onyx:hasEmotionIntensity&quot;</span><span class=\"p\">:</span> <span class=\"mf\">0.09950234435617733</span>\n",
" <span class=\"p\">}</span>\n",
" <span class=\"p\">],</span>\n",
" <span class=\"nt\">&quot;prov:wasGeneratedBy&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;prefix:Analysis_1554382983.3010163&quot;</span>\n",
" <span class=\"nt\">&quot;prov:wasGeneratedBy&quot;</span><span class=\"p\">:</span> <span class=\"s2\">&quot;prefix:Analysis_1563369539.5185866&quot;</span>\n",
" <span class=\"p\">}</span>\n",
" <span class=\"p\">]</span>\n",
" <span class=\"p\">}</span>\n",
......@@ -948,7 +588,7 @@