Commit 02739ece authored by J. Fernando Sánchez's avatar J. Fernando Sánchez
Browse files

Better indexing, added README

parent e14ffc63
![GSI Logo](
[EUROSENTIMETN Endpoint example](
Example endpoint that yields results compatible with the EUROSENTIMENT format and exposes the NIF API.
It can be used as a template to adapt existing services to EUROSENTIMENT or to create new services.
[DEMO on Heroku](
This endpoint serves as bootcampt for any developer wishing to build applications that use the EUROSENTIMENT services.
Grant Agreement no: 296277
Starting date: 01/09/2012
Project duration: 24 months
![Eurosentiment Logo](logo_grande.png)
![FP7 logo](logo_fp7.gif)
......@@ -19,17 +19,21 @@ Simple Sentiment Analysis server for EUROSENTIMENT
This class shows how to use the nif_server module to create custom services.
import config
import re
from flask import Flask
from random import random
from nif_server import *
import config
app = Flask(__name__)
rgx = re.compile("(\w[\w']*\w|\w)", re.U)
def hard_analysis(params):
response = basic_analysis(params)
response["analysis"][0]["marl:algorithm"] = "SimpleAlgorithm"
for i in response["entries"]:
contextid = i["@id"]
polValue = random()
if polValue > 0.5:
pol = "marl:Positive"
......@@ -41,6 +45,15 @@ def hard_analysis(params):
"marl:hasPolarity": pol
i["strings"] = []
for m in rgx.finditer(i["nif:isString"]):
"@id": "{}#char={},{}".format(contextid, m.start(), m.end()),
"nif:beginIndex": m.start(),
"nif:endIndex": m.end(),
return response
app.analyse = hard_analysis
......@@ -43,7 +43,6 @@ PARAMS = {"input": {"aliases": ["i", "input"],
"options": ["json-ld"],
"language": {"aliases": ["language", "l"],
"default": None,
"required": False,
"options": ["es", "en"],
......@@ -88,7 +87,11 @@ def get_params(req):
return outdict
def basic_analysis(params):
response = {"@context": "",
response = {"@context": ["",
"@base": "{}#".format(request.url.encode('utf-8'))
"analysis": [{
"@type": "marl:SentimentAnalysis"
......@@ -96,8 +99,9 @@ def basic_analysis(params):
if "language" in params:
response["language"] = params["language"]
for sentence in params["input"].split("."):
for idx, sentence in enumerate(params["input"].split(".")):
"@id": "Sentence{}".format(idx),
"nif:isString": sentence
return response
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment