Better indexing, added README

yapsy
J. Fernando Sánchez 10 years ago
parent e14ffc63fa
commit 02739ece39

@ -0,0 +1,19 @@
![GSI Logo](http://gsi.dit.upm.es/templates/jgsi/images/logo.png)
[EUROSENTIMETN Endpoint example](http://eurosentiment-resources.herokuapp.com)
=========================================
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](http://eurosentiment-endpoint.herokuapp.com)
This endpoint serves as bootcampt for any developer wishing to build applications that use the EUROSENTIMENT services.
Acknowledgement
---------------
EUROSENTIMENT PROJECT
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"]):
i["strings"].append({
"@id": "{}#char={},{}".format(contextid, m.start(), m.end()),
"nif:beginIndex": m.start(),
"nif:endIndex": m.end(),
"nif:anchorOf": m.group(0)
})
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": "http://demos.gsi.dit.upm.es/eurosentiment/static/context.jsonld",
response = {"@context": ["http://demos.gsi.dit.upm.es/eurosentiment/static/context.jsonld",
{
"@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(".")):
response["entries"].append({
"@id": "Sentence{}".format(idx),
"nif:isString": sentence
})
return response

Loading…
Cancel
Save