1
0
mirror of https://github.com/gsi-upm/senpy synced 2024-11-22 00:02:28 +00:00

Better indexing, added README

This commit is contained in:
J. Fernando Sánchez 2014-07-13 16:28:01 +02:00
parent e14ffc63fa
commit 02739ece39
3 changed files with 40 additions and 4 deletions

19
README.md Normal file
View File

@ -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)

15
app.py
View File

@ -19,17 +19,21 @@ Simple Sentiment Analysis server for EUROSENTIMENT
This class shows how to use the nif_server module to create custom services. This class shows how to use the nif_server module to create custom services.
''' '''
import config
import re
from flask import Flask from flask import Flask
from random import random from random import random
from nif_server import * from nif_server import *
import config
app = Flask(__name__) app = Flask(__name__)
rgx = re.compile("(\w[\w']*\w|\w)", re.U)
def hard_analysis(params): def hard_analysis(params):
response = basic_analysis(params) response = basic_analysis(params)
response["analysis"][0]["marl:algorithm"] = "SimpleAlgorithm" response["analysis"][0]["marl:algorithm"] = "SimpleAlgorithm"
for i in response["entries"]: for i in response["entries"]:
contextid = i["@id"]
polValue = random() polValue = random()
if polValue > 0.5: if polValue > 0.5:
pol = "marl:Positive" pol = "marl:Positive"
@ -41,6 +45,15 @@ def hard_analysis(params):
"marl:hasPolarity": pol "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 return response
app.analyse = hard_analysis app.analyse = hard_analysis

View File

@ -43,7 +43,6 @@ PARAMS = {"input": {"aliases": ["i", "input"],
"options": ["json-ld"], "options": ["json-ld"],
}, },
"language": {"aliases": ["language", "l"], "language": {"aliases": ["language", "l"],
"default": None,
"required": False, "required": False,
"options": ["es", "en"], "options": ["es", "en"],
}, },
@ -88,7 +87,11 @@ def get_params(req):
return outdict return outdict
def basic_analysis(params): 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": [{ "analysis": [{
"@type": "marl:SentimentAnalysis" "@type": "marl:SentimentAnalysis"
}], }],
@ -96,8 +99,9 @@ def basic_analysis(params):
} }
if "language" in params: if "language" in params:
response["language"] = params["language"] response["language"] = params["language"]
for sentence in params["input"].split("."): for idx, sentence in enumerate(params["input"].split(".")):
response["entries"].append({ response["entries"].append({
"@id": "Sentence{}".format(idx),
"nif:isString": sentence "nif:isString": sentence
}) })
return response return response