plugins.py 1.71 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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