Commit 45421f46 authored by J. Fernando Sánchez's avatar J. Fernando Sánchez
Browse files

Small tweaks in docs

parent 7aa69e3d
...@@ -6,10 +6,10 @@ services: ...@@ -6,10 +6,10 @@ services:
language: python language: python
env: env:
- PYV=3.3
- PYV=3.4 - PYV=3.4
- PYV=3.5 - PYV=3.5
- PYV=3.6 - PYV=3.6
- PYV=3.7 - PYV=3.7
# - PYV=3.3 # Apt fails in this docker image
# run nosetests - Tests # run nosetests - Tests
script: make test-$PYV script: make test-$PYV
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
# Senpy in 10 minutes # Senpy in 10 minutes
This tutorial assumes you have completed the [1 minute tutorial](Quickstart-1minute.ipynb) and you know how to access the API. This tutorial assumes you have completed the [1 minute tutorial](Quickstart-1minute.ipynb) and you know how to access the API.
It covers: It covers:
* Annotating entiment with a sentiment analysis service * Annotating entiment with a sentiment analysis service
* Annotating emotions * Annotating emotions
* Interoperability of services * Interoperability of services
* Using other semantic formats (RDF) * Using other semantic formats (RDF)
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Requirements ## Requirements
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Once again, we will use the demo server at http://senpy.gsi.upm.es. Once again, we will use the demo server at http://senpy.gsi.upm.es.
This time, we will use the requests library. This time, we will use the requests library.
We will use a variable for our endpoint, so you can try this examples on a different senpy instance: We will use a variable for our endpoint, so you can try this examples on a different senpy instance:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
endpoint = 'http://senpy.gsi.upm.es/api' endpoint = 'http://senpy.gsi.upm.es/api'
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
We will also add a function to get syntax highlighting for the JSON-LD/Turtle results: We will also add a function to get syntax highlighting for the JSON-LD/Turtle results:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
try: try:
from IPython.display import Code from IPython.display import Code
def pretty(txt, language='json-ld'): def pretty(txt, language='json-ld'):
return Code(txt, language=language) return Code(txt, language=language)
except ImportError: except ImportError:
def pretty(txt, **kwargs): def pretty(txt, **kwargs):
print(txt) print(txt)
``` ```
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Sentiment Analysis of Text ## Sentiment Analysis of Text
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
To start, let us analyse the sentiment in the following sentence: *senpy is awesome*. To start, let us analyse the sentiment in the following sentence: *senpy is awesome*.
For now, we will use the [sentiment140](http://www.sentiment140.com/) service, through the sentiment140 plugin. For now, we will use the [sentiment140](http://www.sentiment140.com/) service, through the sentiment140 plugin.
We will later cover how to use a different service. We will later cover how to use a different service.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import requests import requests
res = requests.get(f'{endpoint}/sentiment140', res = requests.get(f'{endpoint}/sentiment140',
params={"input": "Senpy is awesome",}) params={"input": "Senpy is awesome",})
pretty(res.text) pretty(res.text)
``` ```
%%%% Output: execute_result %%%% Output: execute_result
\begin{Verbatim}[commandchars=\\\{\}] \begin{Verbatim}[commandchars=\\\{\}]
\PY{p}{\PYZob{}} \PY{p}{\PYZob{}}
\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}{,} \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}{,}
\PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Results\PYZdq{}}\PY{p}{,} \PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Results\PYZdq{}}\PY{p}{,}
\PY{n+nt}{\PYZdq{}entries\PYZdq{}}\PY{p}{:} \PY{p}{[} \PY{n+nt}{\PYZdq{}entries\PYZdq{}}\PY{p}{:} \PY{p}{[}
\PY{p}{\PYZob{}} \PY{p}{\PYZob{}}
\PY{n+nd}{\PYZdq{}@id\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}prefix:\PYZdq{}}\PY{p}{,} \PY{n+nd}{\PYZdq{}@id\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}prefix:\PYZdq{}}\PY{p}{,}
\PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Entry\PYZdq{}}\PY{p}{,} \PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Entry\PYZdq{}}\PY{p}{,}
\PY{n+nt}{\PYZdq{}marl:hasOpinion\PYZdq{}}\PY{p}{:} \PY{p}{[} \PY{n+nt}{\PYZdq{}marl:hasOpinion\PYZdq{}}\PY{p}{:} \PY{p}{[}
\PY{p}{\PYZob{}} \PY{p}{\PYZob{}}
\PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Sentiment\PYZdq{}}\PY{p}{,} \PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Sentiment\PYZdq{}}\PY{p}{,}
\PY{n+nt}{\PYZdq{}marl:hasPolarity\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}marl:Positive\PYZdq{}}\PY{p}{,} \PY{n+nt}{\PYZdq{}marl:hasPolarity\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}marl:Positive\PYZdq{}}\PY{p}{,}
\PY{n+nt}{\PYZdq{}prov:wasGeneratedBy\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}prefix:Analysis\PYZus{}1554391718.7649393\PYZdq{}} \PY{n+nt}{\PYZdq{}prov:wasGeneratedBy\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}prefix:Analysis\PYZus{}1554396807.629645\PYZdq{}}
\PY{p}{\PYZcb{}} \PY{p}{\PYZcb{}}
\PY{p}{]}\PY{p}{,} \PY{p}{]}\PY{p}{,}
\PY{n+nt}{\PYZdq{}nif:isString\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Senpy is awesome\PYZdq{}}\PY{p}{,} \PY{n+nt}{\PYZdq{}nif:isString\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Senpy is awesome\PYZdq{}}\PY{p}{,}
\PY{n+nt}{\PYZdq{}onyx:hasEmotionSet\PYZdq{}}\PY{p}{:} \PY{p}{[}\PY{p}{]} \PY{n+nt}{\PYZdq{}onyx:hasEmotionSet\PYZdq{}}\PY{p}{:} \PY{p}{[}\PY{p}{]}
\PY{p}{\PYZcb{}} \PY{p}{\PYZcb{}}
\PY{p}{]} \PY{p}{]}
\PY{p}{\PYZcb{}} \PY{p}{\PYZcb{}}
\end{Verbatim} \end{Verbatim}
{ {
"@context": "http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudDE0MD9pbnB1dD1TZW5weStpcythd2Vzb21lIw%3D%3D", "@context": "http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudDE0MD9pbnB1dD1TZW5weStpcythd2Vzb21lIw%3D%3D",
"@type": "Results", "@type": "Results",
"entries": [ "entries": [
{ {
"@id": "prefix:", "@id": "prefix:",
"@type": "Entry", "@type": "Entry",
"marl:hasOpinion": [ "marl:hasOpinion": [
{ {
"@type": "Sentiment", "@type": "Sentiment",
"marl:hasPolarity": "marl:Positive", "marl:hasPolarity": "marl:Positive",
"prov:wasGeneratedBy": "prefix:Analysis_1554391718.7649393" "prov:wasGeneratedBy": "prefix:Analysis_1554396807.629645"
} }
], ],
"nif:isString": "Senpy is awesome", "nif:isString": "Senpy is awesome",
"onyx:hasEmotionSet": [] "onyx:hasEmotionSet": []
} }
] ]
} }
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
Senpy services always return an object of type `senpy:Results`, with a list of entries. Senpy services always return an object of type `senpy:Results`, with a list of entries.
You can think of an entry as a self-contained textual context (`nif:Context` and `senpy:Entry`). You can think of an entry as a self-contained textual context (`nif:Context` and `senpy:Entry`).
Entries can be as short as a sentence, or as long as a news article. Entries can be as short as a sentence, or as long as a news article.
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. 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.
For instance, sentiment annotations are provided through `marl:hasOpinion`. For instance, sentiment annotations are provided through `marl:hasOpinion`.
The annotations are semantic. The annotations are semantic.
We can ask Senpy for the expanded JSON-LD output to reveal the full URIs of each property and entity: We can ask Senpy for the expanded JSON-LD output to reveal the full URIs of each property and entity:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import requests import requests
res = requests.get(f'{endpoint}/sentiment140', res = requests.get(f'{endpoint}/sentiment140',
params={"input": "Senpy is awesome", params={"input": "Senpy is awesome",
"expanded": True}) "expanded": True})
pretty(res.text) pretty(res.text)
``` ```
%%%% Output: execute_result %%%% Output: execute_result
\begin{Verbatim}[commandchars=\\\{\}] \begin{Verbatim}[commandchars=\\\{\}]
\PY{p}{\PYZob{}} \PY{p}{\PYZob{}}
\PY{n+nd}{\PYZdq{}@context\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudDE0MD9pbnB1dD1TZW5weStpcythd2Vzb21lJmV4cGFuZGVkPVRydWUj\PYZdq{}}\PY{p}{,} \PY{n+nd}{\PYZdq{}@context\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudDE0MD9pbnB1dD1TZW5weStpcythd2Vzb21lJmV4cGFuZGVkPVRydWUj\PYZdq{}}\PY{p}{,}
\PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{p}{[} \PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{p}{[}
\PY{l+s+s2}{\PYZdq{}http://www.gsi.upm.es/onto/senpy/ns\PYZsh{}Results\PYZdq{}} \PY{l+s+s2}{\PYZdq{}http://www.gsi.upm.es/onto/senpy/ns\PYZsh{}Results\PYZdq{}}
\PY{p}{]}\PY{p}{,} \PY{p}{]}\PY{p}{,}
\PY{n+nt}{\PYZdq{}http://www.w3.org/ns/prov\PYZsh{}used\PYZdq{}}\PY{p}{:} \PY{p}{[} \PY{n+nt}{\PYZdq{}http://www.w3.org/ns/prov\PYZsh{}used\PYZdq{}}\PY{p}{:} \PY{p}{[}
\PY{p}{\PYZob{}} \PY{p}{\PYZob{}}
\PY{n+nd}{\PYZdq{}@id\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}http://senpy.invalid/\PYZdq{}}\PY{p}{,} \PY{n+nd}{\PYZdq{}@id\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}http://senpy.invalid/\PYZdq{}}\PY{p}{,}
\PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{p}{[} \PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{p}{[}
\PY{l+s+s2}{\PYZdq{}http://www.gsi.upm.es/onto/senpy/ns\PYZsh{}Entry\PYZdq{}} \PY{l+s+s2}{\PYZdq{}http://www.gsi.upm.es/onto/senpy/ns\PYZsh{}Entry\PYZdq{}}
\PY{p}{]}\PY{p}{,} \PY{p}{]}\PY{p}{,}
\PY{n+nt}{\PYZdq{}http://persistence.uni\PYZhy{}leipzig.org/nlp2rdf/ontologies/nif\PYZhy{}core\PYZsh{}isString\PYZdq{}}\PY{p}{:} \PY{p}{[} \PY{n+nt}{\PYZdq{}http://persistence.uni\PYZhy{}leipzig.org/nlp2rdf/ontologies/nif\PYZhy{}core\PYZsh{}isString\PYZdq{}}\PY{p}{:} \PY{p}{[}
\PY{p}{\PYZob{}} \PY{p}{\PYZob{}}
\PY{n+nd}{\PYZdq{}@value\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Senpy is awesome\PYZdq{}} \PY{n+nd}{\PYZdq{}@value\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Senpy is awesome\PYZdq{}}
\PY{p}{\PYZcb{}} \PY{p}{\PYZcb{}}
\PY{p}{]}\PY{p}{,} \PY{p}{]}\PY{p}{,}
\PY{n+nt}{\PYZdq{}http://www.gsi.dit.upm.es/ontologies/marl/ns\PYZsh{}hasOpinion\PYZdq{}}\PY{p}{:} \PY{p}{[} \PY{n+nt}{\PYZdq{}http://www.gsi.dit.upm.es/ontologies/marl/ns\PYZsh{}hasOpinion\PYZdq{}}\PY{p}{:} \PY{p}{[}
\PY{p}{\PYZob{}} \PY{p}{\PYZob{}}
\PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{p}{[} \PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{p}{[}
\PY{l+s+s2}{\PYZdq{}http://www.gsi.upm.es/onto/senpy/ns\PYZsh{}Sentiment\PYZdq{}} \PY{l+s+s2}{\PYZdq{}http://www.gsi.upm.es/onto/senpy/ns\PYZsh{}Sentiment\PYZdq{}}
\PY{p}{]}\PY{p}{,} \PY{p}{]}\PY{p}{,}
\PY{n+nt}{\PYZdq{}http://www.gsi.dit.upm.es/ontologies/marl/ns\PYZsh{}hasPolarity\PYZdq{}}\PY{p}{:} \PY{p}{[} \PY{n+nt}{\PYZdq{}http://www.gsi.dit.upm.es/ontologies/marl/ns\PYZsh{}hasPolarity\PYZdq{}}\PY{p}{:} \PY{p}{[}
\PY{p}{\PYZob{}} \PY{p}{\PYZob{}}
\PY{n+nd}{\PYZdq{}@value\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}marl:Positive\PYZdq{}} \PY{n+nd}{\PYZdq{}@value\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}marl:Positive\PYZdq{}}
\PY{p}{\PYZcb{}} \PY{p}{\PYZcb{}}
\PY{p}{]}\PY{p}{,} \PY{p}{]}\PY{p}{,}
\PY{n+nt}{\PYZdq{}http://www.w3.org/ns/prov\PYZsh{}wasGeneratedBy\PYZdq{}}\PY{p}{:} \PY{p}{[} \PY{n+nt}{\PYZdq{}http://www.w3.org/ns/prov\PYZsh{}wasGeneratedBy\PYZdq{}}\PY{p}{:} \PY{p}{[}
\PY{p}{\PYZob{}} \PY{p}{\PYZob{}}
\PY{n+nd}{\PYZdq{}@id\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}http://senpy.invalid/Analysis\PYZus{}1554389672.269198\PYZdq{}} \PY{n+nd}{\PYZdq{}@id\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}http://senpy.invalid/Analysis\PYZus{}1554389672.269198\PYZdq{}}
\PY{p}{\PYZcb{}} \PY{p}{\PYZcb{}}
\PY{p}{]} \PY{p}{]}
\PY{p}{\PYZcb{}} \PY{p}{\PYZcb{}}
\PY{p}{]}\PY{p}{,} \PY{p}{]}\PY{p}{,}
\PY{n+nt}{\PYZdq{}http://www.gsi.dit.upm.es/ontologies/onyx/ns\PYZsh{}hasEmotionSet\PYZdq{}}\PY{p}{:} \PY{p}{[}\PY{p}{]} \PY{n+nt}{\PYZdq{}http://www.gsi.dit.upm.es/ontologies/onyx/ns\PYZsh{}hasEmotionSet\PYZdq{}}\PY{p}{:} \PY{p}{[}\PY{p}{]}
\PY{p}{\PYZcb{}} \PY{p}{\PYZcb{}}
\PY{p}{]} \PY{p}{]}
\PY{p}{\PYZcb{}} \PY{p}{\PYZcb{}}
\end{Verbatim} \end{Verbatim}
{ {
"@context": "http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudDE0MD9pbnB1dD1TZW5weStpcythd2Vzb21lJmV4cGFuZGVkPVRydWUj", "@context": "http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudDE0MD9pbnB1dD1TZW5weStpcythd2Vzb21lJmV4cGFuZGVkPVRydWUj",
"@type": [ "@type": [
"http://www.gsi.upm.es/onto/senpy/ns#Results" "http://www.gsi.upm.es/onto/senpy/ns#Results"
], ],
"http://www.w3.org/ns/prov#used": [ "http://www.w3.org/ns/prov#used": [
{ {
"@id": "http://senpy.invalid/", "@id": "http://senpy.invalid/",
"@type": [ "@type": [
"http://www.gsi.upm.es/onto/senpy/ns#Entry" "http://www.gsi.upm.es/onto/senpy/ns#Entry"
], ],
"http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#isString": [ "http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#isString": [
{ {
"@value": "Senpy is awesome" "@value": "Senpy is awesome"
} }
], ],
"http://www.gsi.dit.upm.es/ontologies/marl/ns#hasOpinion": [ "http://www.gsi.dit.upm.es/ontologies/marl/ns#hasOpinion": [
{ {
"@type": [ "@type": [
"http://www.gsi.upm.es/onto/senpy/ns#Sentiment" "http://www.gsi.upm.es/onto/senpy/ns#Sentiment"
], ],
"http://www.gsi.dit.upm.es/ontologies/marl/ns#hasPolarity": [ "http://www.gsi.dit.upm.es/ontologies/marl/ns#hasPolarity": [
{ {
"@value": "marl:Positive" "@value": "marl:Positive"
} }
], ],
"http://www.w3.org/ns/prov#wasGeneratedBy": [ "http://www.w3.org/ns/prov#wasGeneratedBy": [
{ {
"@id": "http://senpy.invalid/Analysis_1554389672.269198" "@id": "http://senpy.invalid/Analysis_1554389672.269198"
} }
] ]
} }
], ],
"http://www.gsi.dit.upm.es/ontologies/onyx/ns#hasEmotionSet": [] "http://www.gsi.dit.upm.es/ontologies/onyx/ns#hasEmotionSet": []
} }
] ]
} }
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Service interoperability ## Service interoperability
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
All senpy plugins use the same API, which makes moving from one service to another a breeze. All senpy plugins use the same API, which makes moving from one service to another a breeze.
Let us go back to our simple example, which uses the `sentiment140` service. Let us go back to our simple example, which uses the `sentiment140` service.
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import requests import requests
res = requests.get(f'{endpoint}/sentiment140', res = requests.get(f'{endpoint}/sentiment140',
params={"input": "Senpy is awesome"}) params={"input": "Senpy is awesome"})
pretty(res.text) pretty(res.text)
``` ```
%%%% Output: execute_result %%%% Output: execute_result
\begin{Verbatim}[commandchars=\\\{\}] \begin{Verbatim}[commandchars=\\\{\}]
\PY{p}{\PYZob{}} \PY{p}{\PYZob{}}
\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}{,} \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}{,}
\PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Results\PYZdq{}}\PY{p}{,} \PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Results\PYZdq{}}\PY{p}{,}
\PY{n+nt}{\PYZdq{}entries\PYZdq{}}\PY{p}{:} \PY{p}{[} \PY{n+nt}{\PYZdq{}entries\PYZdq{}}\PY{p}{:} \PY{p}{[}
\PY{p}{\PYZob{}} \PY{p}{\PYZob{}}
\PY{n+nd}{\PYZdq{}@id\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}prefix:\PYZdq{}}\PY{p}{,} \PY{n+nd}{\PYZdq{}@id\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}prefix:\PYZdq{}}\PY{p}{,}
\PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Entry\PYZdq{}}\PY{p}{,} \PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Entry\PYZdq{}}\PY{p}{,}
\PY{n+nt}{\PYZdq{}marl:hasOpinion\PYZdq{}}\PY{p}{:} \PY{p}{[} \PY{n+nt}{\PYZdq{}marl:hasOpinion\PYZdq{}}\PY{p}{:} \PY{p}{[}
\PY{p}{\PYZob{}} \PY{p}{\PYZob{}}
\PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Sentiment\PYZdq{}}\PY{p}{,} \PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Sentiment\PYZdq{}}\PY{p}{,}
\PY{n+nt}{\PYZdq{}marl:hasPolarity\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}marl:Positive\PYZdq{}}\PY{p}{,} \PY{n+nt}{\PYZdq{}marl:hasPolarity\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}marl:Positive\PYZdq{}}\PY{p}{,}
\PY{n+nt}{\PYZdq{}prov:wasGeneratedBy\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}prefix:Analysis\PYZus{}1554389675.2303865\PYZdq{}} \PY{n+nt}{\PYZdq{}prov:wasGeneratedBy\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}prefix:Analysis\PYZus{}1554389675.2303865\PYZdq{}}
\PY{p}{\PYZcb{}} \PY{p}{\PYZcb{}}
\PY{p}{]}\PY{p}{,} \PY{p}{]}\PY{p}{,}
\PY{n+nt}{\PYZdq{}nif:isString\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Senpy is awesome\PYZdq{}}\PY{p}{,} \PY{n+nt}{\PYZdq{}nif:isString\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Senpy is awesome\PYZdq{}}\PY{p}{,}
\PY{n+nt}{\PYZdq{}onyx:hasEmotionSet\PYZdq{}}\PY{p}{:} \PY{p}{[}\PY{p}{]} \PY{n+nt}{\PYZdq{}onyx:hasEmotionSet\PYZdq{}}\PY{p}{:} \PY{p}{[}\PY{p}{]}
\PY{p}{\PYZcb{}} \PY{p}{\PYZcb{}}
\PY{p}{]} \PY{p}{]}
\PY{p}{\PYZcb{}} \PY{p}{\PYZcb{}}
\end{Verbatim} \end{Verbatim}
{ {
"@context": "http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudDE0MD9pbnB1dD1TZW5weStpcythd2Vzb21lIw%3D%3D", "@context": "http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudDE0MD9pbnB1dD1TZW5weStpcythd2Vzb21lIw%3D%3D",
"@type": "Results", "@type": "Results",
"entries": [ "entries": [
{ {
"@id": "prefix:", "@id": "prefix:",
"@type": "Entry", "@type": "Entry",
"marl:hasOpinion": [ "marl:hasOpinion": [
{ {
"@type": "Sentiment", "@type": "Sentiment",
"marl:hasPolarity": "marl:Positive", "marl:hasPolarity": "marl:Positive",
"prov:wasGeneratedBy": "prefix:Analysis_1554389675.2303865" "prov:wasGeneratedBy": "prefix:Analysis_1554389675.2303865"
} }
], ],
"nif:isString": "Senpy is awesome", "nif:isString": "Senpy is awesome",
"onyx:hasEmotionSet": [] "onyx:hasEmotionSet": []
} }
] ]
} }
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
If we wanted to use a different service (e.g. the `sentiment-basic` plugin), we can do it just by changing the URL of the service: If we wanted to use a different service (e.g. the `sentiment-basic` plugin), we can do it just by changing the URL of the service:
%% Cell type:code id: tags: %% Cell type:code id: tags:
``` python ``` python
import requests import requests
res = requests.get(f'{endpoint}/sentiment-basic', res = requests.get(f'{endpoint}/sentiment-basic',
params={"input": "Senpy is awesome"}) params={"input": "Senpy is awesome"})
pretty(res.text) pretty(res.text)
``` ```
%%%% Output: execute_result %%%% Output: execute_result
\begin{Verbatim}[commandchars=\\\{\}] \begin{Verbatim}[commandchars=\\\{\}]
\PY{p}{\PYZob{}} \PY{p}{\PYZob{}}
\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}{,} \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}{,}
\PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Results\PYZdq{}}\PY{p}{,} \PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Results\PYZdq{}}\PY{p}{,}
\PY{n+nt}{\PYZdq{}entries\PYZdq{}}\PY{p}{:} \PY{p}{[} \PY{n+nt}{\PYZdq{}entries\PYZdq{}}\PY{p}{:} \PY{p}{[}
\PY{p}{\PYZob{}} \PY{p}{\PYZob{}}
\PY{n+nd}{\PYZdq{}@id\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}prefix:\PYZdq{}}\PY{p}{,} \PY{n+nd}{\PYZdq{}@id\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}prefix:\PYZdq{}}\PY{p}{,}
\PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Entry\PYZdq{}}\PY{p}{,} \PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Entry\PYZdq{}}\PY{p}{,}
\PY{n+nt}{\PYZdq{}marl:hasOpinion\PYZdq{}}\PY{p}{:} \PY{p}{[} \PY{n+nt}{\PYZdq{}marl:hasOpinion\PYZdq{}}\PY{p}{:} \PY{p}{[}
\PY{p}{\PYZob{}} \PY{p}{\PYZob{}}
\PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Sentiment\PYZdq{}}\PY{p}{,} \PY{n+nd}{\PYZdq{}@type\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Sentiment\PYZdq{}}\PY{p}{,}
\PY{n+nt}{\PYZdq{}marl:hasPolarity\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}marl:Neutral\PYZdq{}}\PY{p}{,} \PY{n+nt}{\PYZdq{}marl:hasPolarity\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}marl:Neutral\PYZdq{}}\PY{p}{,}
\PY{n+nt}{\PYZdq{}prov:wasGeneratedBy\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}prefix:Analysis\PYZus{}1554389675.9911203\PYZdq{}} \PY{n+nt}{\PYZdq{}prov:wasGeneratedBy\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}prefix:Analysis\PYZus{}1554389675.9911203\PYZdq{}}
\PY{p}{\PYZcb{}} \PY{p}{\PYZcb{}}
\PY{p}{]}\PY{p}{,} \PY{p}{]}\PY{p}{,}
\PY{n+nt}{\PYZdq{}nif:isString\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Senpy is awesome\PYZdq{}}\PY{p}{,} \PY{n+nt}{\PYZdq{}nif:isString\PYZdq{}}\PY{p}{:} \PY{l+s+s2}{\PYZdq{}Senpy is awesome\PYZdq{}}\PY{p}{,}
\PY{n+nt}{\PYZdq{}onyx:hasEmotionSet\PYZdq{}}\PY{p}{:} \PY{p}{[}\PY{p}{]} \PY{n+nt}{\PYZdq{}onyx:hasEmotionSet\PYZdq{}}\PY{p}{:} \PY{p}{[}\PY{p}{]}
\PY{p}{\PYZcb{}} \PY{p}{\PYZcb{}}
\PY{p}{]} \PY{p}{]}
\PY{p}{\PYZcb{}} \PY{p}{\PYZcb{}}
\end{Verbatim} \end{Verbatim}
{ {
"@context": "http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudC1iYXNpYz9pbnB1dD1TZW5weStpcythd2Vzb21lIw%3D%3D", "@context": "http://senpy.gsi.upm.es/api/contexts/YXBpL3NlbnRpbWVudC1iYXNpYz9pbnB1dD1TZW5weStpcythd2Vzb21lIw%3D%3D",
"@type": "Results", "@type": "Results",
"entries": [ "entries": [
{ {
"@id": "prefix:", "@id": "prefix:",
"@type": "Entry", "@type": "Entry",
"marl:hasOpinion": [ "marl:hasOpinion": [
{ {
"@type": "Sentiment", "@type": "Sentiment",
"marl:hasPolarity": "marl:Neutral", "marl:hasPolarity": "marl:Neutral",
"prov:wasGeneratedBy": "prefix:Analysis_1554389675.9911203" "prov:wasGeneratedBy": "prefix:Analysis_1554389675.9911203"
} }
], ],
"nif:isString": "Senpy is awesome", "nif:isString": "Senpy is awesome",
"onyx:hasEmotionSet": [] "onyx:hasEmotionSet": []
} }
] ]
} }
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
As you can see, the structure and annotation schema of the response is the same. As you can see, the structure and annotation schema of the response is the same.
This makes it very easy to compare and migrate to different services. This makes it very easy to compare and migrate to different services.
Service interoperability is not only useful for users. Service interoperability is not only useful for users.
It is also key for other features such as [automated evaluation](#Evaluation). It is also key for other features such as [automated evaluation](#Evaluation).
This is a compelling reason to adapt existing services to use the Senpy API. This is a compelling reason to adapt existing services to use the Senpy API.
In fact, the `sentiment140` senpy service is proxy to the public [Sentiment 140 service](http://www.sentiment140.com/). In fact, the `sentiment140` senpy service is proxy to the public [Sentiment 140 service](http://www.sentiment140.com/).
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
## Emotion analysis ## Emotion analysis