plugins.py 3.38 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
PARAMS = {"input": {"aliases": ["i", "input"],
                    "required": True,
                    "help": "Input text"
                    },
          "informat": {"aliases": ["f", "informat"],
                       "required": False,
                       "default": "text",
                       "options": ["turtle", "text"],
                       },
          "intype": {"aliases": ["intype", "t"],
                     "required": False,
                     "default": "direct",
                     "options": ["direct", "url", "file"],
                     },
          "outformat": {"aliases": ["outformat", "o"],
                        "default": "json-ld",
                        "required": False,
                        "options": ["json-ld"],
                        },
          "language": {"aliases": ["language", "l"],
                       "required": False,
                       "options": ["es", "en"],
                       },
          "urischeme": {"aliases": ["urischeme", "u"],
                        "required": False,
                        "default": "RFC5147String",
                        "options": "RFC5147String"
                        },
          }

31
class SenpyPlugin(object):
32
33
    def __init__(self, name=None, version=None, extraparams=None, params=None):
        print("Initing {}".format(name))
34
35
        self.name = name
        self.version = version
36
37
38
39
40
41
42
43
        if params:
            self.params = params
        else:
            self.params = PARAMS.copy()
            if extraparams:
                self.params.update(extraparams)
        self.extraparams = extraparams or {}
        self.enabled = True
44
45
46
47

    def analyse(self, *args, **kwargs):
        pass

48
49
    def enable(self):
        self.enabled = True
50

51
52
    def disable(self):
        self.enabled = False
53
54
55
56

    def jsonable(self, parameters=False):
        resp =  {
            "@id": "{}_{}".format(self.name, self.version),
57
            "enabled": self.enabled,
58
        }
59
60
        if self.repo:
            resp["repo"] = self.repo.remotes[0].url
61
        if parameters:
62
63
64
            resp["parameters"] = self.params
        elif self.extraparams:
            resp["extra_parameters"] = self.extraparams
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
        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