Esempio n. 1
0
    def from_dict(cls, dic):
        # convert to Speaker and Message object from dictionary
        if dic.get("speaker"):
            speaker = Speaker.from_dict(dic["speaker"])
        else:
            speaker = None
        if dic.get("message"):
            message = Speaker.from_dict(dic["message"])
        else:
            message = None

        return cls(text=dic["text"],
                   score=dic["score"],
                   id_=dic.get("id_"),
                   speaker=speaker,
                   message=message,
                   source=dic.get("source"))
Esempio n. 2
0
    def from_dict(cls, dic):
        speaker = dic.get("speaker")
        if speaker:
            speaker = Speaker.from_dict(speaker)

        m = Message(text=dic["text"],   
                    id_=dic.get("id_"),
                    speaker=speaker)
        return m
Esempio n. 3
0
    def test_from_dict(self):
        dic = {"name": "太郎"}

        self.assertEqual(Speaker.from_dict(dic), Speaker(name="太郎"))