plugins.py 3.18 KB
Newer Older
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
1
import logging
2
import ConfigParser
3
from .models import Leaf
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
4
5
6

logger = logging.getLogger(__name__)

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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"],
                       },
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
30
31
32
33
          "prefix": {"aliases": ["prefix", "p"],
                     "required": True,
                     "default": "",
          },
34
35
36
37
38
39
40
          "urischeme": {"aliases": ["urischeme", "u"],
                        "required": False,
                        "default": "RFC5147String",
                        "options": "RFC5147String"
                        },
          }

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
41

42
43
44
45
46
47
48
49
50
51
class SenpyPlugin(Leaf):
    _context = {"@vocab": "http://www.gsi.dit.upm.es/ontologies/senpy/ns#",
                "info": None}
    _frame = { "@context": _context,
              "name": {},
              "@explicit": False,
              "version": {},
              "repo": None,
              "info": None,
              }
52
53
54
55
    def __init__(self, info=None):
        if not info:
            raise ValueError("You need to provide configuration information for the plugin.")
        logger.debug("Initialising {}".format(info))
56
        super(SenpyPlugin, self).__init__()
57
58
        self.name = info["name"]
        self.version = info["version"]
59
        self.id="{}_{}".format(self.name, self.version)
60
61
62
63
64
        self.params = info.get("params", PARAMS.copy())
        self.extra_params = info.get("extra_params", {})
        self.params.update(self.extra_params)
        self.is_activated = False
        self.info = info
65
66

    def analyse(self, *args, **kwargs):
67
        logger.debug("Analysing with: {} {}".format(self.name, self.version))
68
69
        pass

70
71
72
73
74
    def activate(self):
        pass

    def deactivate(self):
        pass
75
76


J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
77
78
79
80
    @property
    def id(self):
        return "{}_{}".format(self.name, self.version)

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
81

82
class SentimentPlugin(SenpyPlugin):
83
84
85
86
    def __init__(self, info, *args, **kwargs):
        super(SentimentPlugin, self).__init__(info, *args, **kwargs)
        self.minPolarityValue = float(info.get("minPolarityValue", 0))
        self.maxPolarityValue = float(info.get("maxPolarityValue", 1))
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
87

88
class EmotionPlugin(SenpyPlugin):
89
90
91
92
    def __init__(self, info, *args, **kwargs):
        resp = super(EmotionPlugin, self).__init__(info, *args, **kwargs)
        self.minEmotionValue = float(info.get("minEmotionValue", 0))
        self.maxEmotionValue = float(info.get("maxEmotionValue", 0))