mirror of https://github.com/gsi-upm/senpy
parent
8405e5deef
commit
e06fc2e671
@ -1,7 +1,7 @@
|
|||||||
from flask import Flask
|
from flask import Flask
|
||||||
from extensions import Senpy
|
from extensions import Senpy
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.debug = True
|
|
||||||
sp = Senpy()
|
sp = Senpy()
|
||||||
sp.init_app(app)
|
sp.init_app(app)
|
||||||
|
app.debug = True
|
||||||
app.run()
|
app.run()
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"dc": "http://purl.org/dc/terms/",
|
||||||
|
"dc:subject": {
|
||||||
|
"@type": "@id"
|
||||||
|
},
|
||||||
|
"xsd": "http://www.w3.org/2001/XMLSchema#",
|
||||||
|
"marl": "http://www.gsi.dit.upm.es/ontologies/marl/ns#",
|
||||||
|
"nif": "http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#",
|
||||||
|
"onyx": "http://www.gsi.dit.upm.es/ontologies/onyx/ns#",
|
||||||
|
"emotions": {
|
||||||
|
"@id": "onyx:hasEmotionSet",
|
||||||
|
"@type": "onyx:EmotionSet"
|
||||||
|
},
|
||||||
|
"opinions": {
|
||||||
|
"@container": "@list",
|
||||||
|
"@id": "marl:hasOpinion",
|
||||||
|
"@type": "marl:Opinion"
|
||||||
|
},
|
||||||
|
"prov": "http://www.w3.org/ns/prov#",
|
||||||
|
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
|
||||||
|
"analysis": {
|
||||||
|
"@id": "prov:wasInformedBy"
|
||||||
|
},
|
||||||
|
"entries": {
|
||||||
|
"@id": "prov:generated"
|
||||||
|
},
|
||||||
|
"strings": {
|
||||||
|
"@reverse": "nif:hasContext",
|
||||||
|
"@type": "nif:String"
|
||||||
|
},
|
||||||
|
"date":
|
||||||
|
{
|
||||||
|
"@id": "dc:date",
|
||||||
|
"@type": "xsd:dateTime"
|
||||||
|
},
|
||||||
|
"wnaffect": "http://www.gsi.dit.upm.es/ontologies/wnaffect#",
|
||||||
|
"xsd": "http://www.w3.org/2001/XMLSchema#"
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
class Leaf(defaultdict):
|
||||||
|
def __init__(self, ofclass=list):
|
||||||
|
super(Leaf, self).__init__(ofclass)
|
||||||
|
|
||||||
|
def __getattr__(self, name):
|
||||||
|
return super(Leaf, self).__getitem__(name)
|
||||||
|
|
||||||
|
def __setattr__(self, name, value):
|
||||||
|
self[name] = value
|
||||||
|
|
||||||
|
def __delattr__(self, name):
|
||||||
|
return super(Leaf, self).__delitem__(name)
|
||||||
|
|
||||||
|
class Response(Leaf):
|
||||||
|
def __init__(self, context=None):
|
||||||
|
super(Response, self).__init__()
|
||||||
|
self["analysis"] = []
|
||||||
|
self["entries"] = []
|
||||||
|
if context is None:
|
||||||
|
context = "{}/context.jsonld".format(os.path.dirname(
|
||||||
|
os.path.realpath(__file__)))
|
||||||
|
if isinstance(context, dict):
|
||||||
|
self["@context"] = context
|
||||||
|
if isinstance(context, basestring):
|
||||||
|
try:
|
||||||
|
with open(context) as f:
|
||||||
|
self["@context"] = json.loads(f.read())
|
||||||
|
except IOError:
|
||||||
|
self["@context"] = context
|
||||||
|
|
||||||
|
|
||||||
|
class Entry(Leaf):
|
||||||
|
def __init__(self, text=None, emotionSets=None, opinions=None, **kwargs):
|
||||||
|
super(Entry, self).__init__(**kwargs)
|
||||||
|
if text:
|
||||||
|
self.text = text
|
||||||
|
if emotionSets:
|
||||||
|
self.emotionSets = emotionSets
|
||||||
|
if opinions:
|
||||||
|
self.opinions = opinions
|
||||||
|
|
||||||
|
class Opinion(Leaf):
|
||||||
|
def __init__(self, polarityValue=None, polarity=None, **kwargs):
|
||||||
|
super(Opinion, self).__init__(**kwargs)
|
||||||
|
if polarityValue is not None:
|
||||||
|
self.polarityValue = polarityValue
|
||||||
|
if polarity is not None:
|
||||||
|
self.polarity = polarity
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class EmotionSet(Leaf):
|
||||||
|
def __init__(self, emotions=[], **kwargs):
|
||||||
|
super(EmotionSet, self).__init__(**kwargs)
|
||||||
|
self.emotions = emotions or []
|
@ -1,34 +0,0 @@
|
|||||||
class SenpyPlugin(object):
|
|
||||||
def __init__(self, name=None, version=None, params=None):
|
|
||||||
self.name = name
|
|
||||||
self.version = version
|
|
||||||
self.params = params or []
|
|
||||||
|
|
||||||
def analyse(self, *args, **kwargs):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def activate(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def deactivate(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class SentimentPlugin(SenpyPlugin):
|
|
||||||
def __init__(self,
|
|
||||||
minPolarity=0,
|
|
||||||
maxPolarity=1,
|
|
||||||
**kwargs):
|
|
||||||
super(SentimentPlugin, self).__init__(**kwargs)
|
|
||||||
self.minPolarity = minPolarity
|
|
||||||
self.maxPolarity = maxPolarity
|
|
||||||
|
|
||||||
class EmotionPlugin(SenpyPlugin):
|
|
||||||
def __init__(self,
|
|
||||||
minEmotionValue=0,
|
|
||||||
maxEmotionValue=1,
|
|
||||||
emotionCategory=None,
|
|
||||||
**kwargs):
|
|
||||||
super(EmotionPlugin, self).__init__(**kwargs)
|
|
||||||
self.minEmotionValue = minEmotionValue
|
|
||||||
self.maxEmotionValue = maxEmotionValue
|
|
||||||
self.emotionCategory = emotionCategory
|
|
@ -0,0 +1,54 @@
|
|||||||
|
class SenpyPlugin(object):
|
||||||
|
def __init__(self, name=None, version=None, params=None):
|
||||||
|
self.name = name
|
||||||
|
self.version = version
|
||||||
|
self.params = params or []
|
||||||
|
|
||||||
|
def analyse(self, *args, **kwargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def activate(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def deactivate(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def jsonable(self, parameters=False):
|
||||||
|
resp = {
|
||||||
|
"@id": "{}_{}".format(self.name, self.version),
|
||||||
|
}
|
||||||
|
if parameters:
|
||||||
|
resp["parameters"] = self.params,
|
||||||
|
return resp
|
||||||
|
|
||||||
|
class SentimentPlugin(SenpyPlugin):
|
||||||
|
def __init__(self,
|
||||||
|
minPolarityValue=0,
|
||||||
|
maxPolarityValue=1,
|
||||||
|
**kwargs):
|
||||||
|
super(SentimentPlugin, self).__init__(**kwargs)
|
||||||
|
self.minPolarityValue = minPolarityValue
|
||||||
|
self.maxPolarityValue = maxPolarityValue
|
||||||
|
|
||||||
|
def jsonable(self, *args, **kwargs):
|
||||||
|
resp = super(SentimentPlugin, self).jsonable(*args, **kwargs)
|
||||||
|
resp["marl:maxPolarityValue"] = self.maxPolarityValue
|
||||||
|
resp["marl:minPolarityValue"] = self.minPolarityValue
|
||||||
|
return resp
|
||||||
|
|
||||||
|
class EmotionPlugin(SenpyPlugin):
|
||||||
|
def __init__(self,
|
||||||
|
minEmotionValue=0,
|
||||||
|
maxEmotionValue=1,
|
||||||
|
emotionCategory=None,
|
||||||
|
**kwargs):
|
||||||
|
super(EmotionPlugin, self).__init__(**kwargs)
|
||||||
|
self.minEmotionValue = minEmotionValue
|
||||||
|
self.maxEmotionValue = maxEmotionValue
|
||||||
|
self.emotionCategory = emotionCategory
|
||||||
|
|
||||||
|
def jsonable(self, *args, **kwargs):
|
||||||
|
resp = super(EmotionPlugin, self).jsonable(*args, **kwargs)
|
||||||
|
resp["onyx:minEmotionValue"] = self.minEmotionValue
|
||||||
|
resp["onyx:maxEmotionValue"] = self.maxEmotionValue
|
||||||
|
return resp
|
Loading…
Reference in New Issue