From 60ef304108423e554f20dd7f19bbecf318fcea9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Fernando=20S=C3=A1nchez?= Date: Fri, 5 May 2017 17:05:17 +0200 Subject: [PATCH] Analysis set as a python list Closes senpy/senpy#31 --- senpy/extensions.py | 6 +++--- tests/test_extensions.py | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/senpy/extensions.py b/senpy/extensions.py index e30fa14..9326adb 100644 --- a/senpy/extensions.py +++ b/senpy/extensions.py @@ -195,7 +195,7 @@ class Senpy(object): def convert_emotions(self, resp, plugins, params): """ - Conversion of all emotions in a response. + Conversion of all emotions in a response **in place**. In addition to converting from one model to another, it has to include the conversion plugin to the analysis list. Needless to say, this is far from an elegant solution, but it works. @@ -220,7 +220,6 @@ class Senpy(object): e.parameters = params raise e newentries = [] - resp.analysis = set(resp.analysis) for i in resp.entries: if output == "full": newemotions = copy.deepcopy(i.emotions) @@ -229,7 +228,7 @@ class Senpy(object): for j in i.emotions: plugname = j['prov:wasGeneratedBy'] candidate = candidates[plugname] - resp.analysis.add(candidate.id) + resp.analysis.append(candidate.id) for k in candidate.convert(j, fromModel, toModel, params): k.prov__wasGeneratedBy = candidate.id if output == 'nested': @@ -238,6 +237,7 @@ class Senpy(object): i.emotions = newemotions newentries.append(i) resp.entries = newentries + resp.analysis = list(set(resp.analysis)) @property def default_plugin(self): diff --git a/tests/test_extensions.py b/tests/test_extensions.py index 067f697..9293fde 100644 --- a/tests/test_extensions.py +++ b/tests/test_extensions.py @@ -205,6 +205,7 @@ class ExtensionsTest(TestCase): [plugin, ], params) assert len(r3.entries[0].emotions) == 1 + r3.jsonld() # def test_async_plugin(self): # """ We should accept multiprocessing plugins with async=False"""