conversion.rst 3.14 KB
Newer Older
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
1
2
Conversion
----------
3
4
5
6
7

Senpy includes experimental support for emotion/sentiment conversion plugins.


Use
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
8
===
9

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
10
Consider the original query: http://127.0.0.1:5000/api/?i=hello&algo=emoRand
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

The requested plugin (emoRand) returns emotions using Ekman's model (or big6 in EmotionML):

.. code:: json


          ... rest of the document ...
          {
            "@type": "emotionSet",
            "onyx:hasEmotion": {
                "@type": "emotion",
                "onyx:hasEmotionCategory": "emoml:big6anger"
            },
            "prov:wasGeneratedBy": "plugins/emoRand_0.1"
          }

          

To get these emotions in VAD space (FSRE dimensions in EmotionML), we'd do this:

J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
31
http://127.0.0.1:5000/api/?i=hello&algo=emoRand&emotionModel=emoml:fsre-dimensions
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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

This call, provided there is a valid conversion plugin from Ekman's to VAD, would return something like this:

.. code:: json


          ... rest of the document ...
          {
            "@type": "emotionSet",
            "onyx:hasEmotion": {
                "@type": "emotion",
                "onyx:hasEmotionCategory": "emoml:big6anger"
                },
            "prov:wasGeneratedBy": "plugins/emoRand_0.1"
          }, {
            "@type": "emotionSet",
            "onyx:hasEmotion": {
                "@type": "emotion",
                "A": 7.22,
                "D": 6.28,
                "V": 8.6
            },
            "prov:wasGeneratedBy": "plugins/Ekman2VAD_0.1"

          }


That is called a *full* response, as it simply adds the converted emotion alongside.
It is also possible to get the original emotion nested within the new converted emotion, using the `conversion=nested` parameter:

.. code:: json


          ... rest of the document ...
          {
            "@type": "emotionSet",
            "onyx:hasEmotion": {
                "@type": "emotion",
                "onyx:hasEmotionCategory": "emoml:big6anger"
                },
            "prov:wasGeneratedBy": "plugins/emoRand_0.1"
            "onyx:wasDerivedFrom": {
                "@type": "emotionSet",
                "onyx:hasEmotion": {
                    "@type": "emotion",
                    "A": 7.22,
                    "D": 6.28,
                    "V": 8.6
                },
                "prov:wasGeneratedBy": "plugins/Ekman2VAD_0.1"
             }

          }


Lastly, `conversion=filtered` would only return the converted emotions.

Developing a conversion plugin
J. Fernando Sánchez's avatar
J. Fernando Sánchez committed
90
================================
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

Conversion plugins are discovered by the server just like any other plugin.
The difference is the slightly different API, and the need to specify the `source` and `target` of the conversion.
For instance, an emotion conversion plugin needs the following:


.. code:: yaml
          

          ---
          onyx:doesConversion:
            - onyx:conversionFrom: emoml:big6
              onyx:conversionTo: emoml:fsre-dimensions
            - onyx:conversionFrom: emoml:fsre-dimensions
              onyx:conversionTo: emoml:big6




.. code:: python


          class MyConversion(EmotionConversionPlugin):

              def convert(self, emotionSet, fromModel, toModel, params):
                  pass