1
0
mirror of https://github.com/gsi-upm/senpy synced 2024-11-22 00:02:28 +00:00

Added serialization of sets

This commit is contained in:
J. Fernando Sánchez 2017-06-16 12:44:25 +02:00
parent 312e7f7f12
commit 24c97256e8
2 changed files with 7 additions and 2 deletions

View File

@ -140,7 +140,7 @@ class SenpyMixin(object):
vp = item[kp] vp = item[kp]
temp[kp] = ser_or_down(vp) temp[kp] = ser_or_down(vp)
return temp return temp
elif isinstance(item, list): elif isinstance(item, list) or isinstance(item, set):
return list(ser_or_down(i) for i in item) return list(ser_or_down(i) for i in item)
else: else:
return item return item
@ -184,7 +184,7 @@ class SenpyMixin(object):
jsonschema.validate(obj, self.schema) jsonschema.validate(obj, self.schema)
def __str__(self): def __str__(self):
return str(self.to_JSON()) return str(self.serialize())
class BaseModel(SenpyMixin, dict): class BaseModel(SenpyMixin, dict):

View File

@ -175,6 +175,7 @@ class PluginsTest(TestCase):
"centroids_direction": ["emoml:big6", "emoml:fsre-dimensions"] "centroids_direction": ["emoml:big6", "emoml:fsre-dimensions"]
} }
c = CentroidConversion(info) c = CentroidConversion(info)
print(c.serialize())
es1 = EmotionSet() es1 = EmotionSet()
e1 = Emotion() e1 = Emotion()
@ -183,6 +184,7 @@ class PluginsTest(TestCase):
res = c._forward_conversion(es1) res = c._forward_conversion(es1)
assert res["X-dimension"] == 0.5 assert res["X-dimension"] == 0.5
assert res["Y-dimension"] == 0.5 assert res["Y-dimension"] == 0.5
print(res)
e2 = Emotion() e2 = Emotion()
e2.onyx__hasEmotionCategory = "c2" e2.onyx__hasEmotionCategory = "c2"
@ -190,15 +192,18 @@ class PluginsTest(TestCase):
res = c._forward_conversion(es1) res = c._forward_conversion(es1)
assert res["X-dimension"] == 0 assert res["X-dimension"] == 0
assert res["Y-dimension"] == 1 assert res["Y-dimension"] == 1
print(res)
e = Emotion() e = Emotion()
e["X-dimension"] = -0.2 e["X-dimension"] = -0.2
e["Y-dimension"] = -0.3 e["Y-dimension"] = -0.3
res = c._backwards_conversion(e) res = c._backwards_conversion(e)
assert res["onyx:hasEmotionCategory"] == "c3" assert res["onyx:hasEmotionCategory"] == "c3"
print(res)
e = Emotion() e = Emotion()
e["X-dimension"] = -0.2 e["X-dimension"] = -0.2
e["Y-dimension"] = 0.3 e["Y-dimension"] = 0.3
res = c._backwards_conversion(e) res = c._backwards_conversion(e)
assert res["onyx:hasEmotionCategory"] == "c2" assert res["onyx:hasEmotionCategory"] == "c2"
print(res)