-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_model.py
39 lines (31 loc) · 1.06 KB
/
data_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import json
class Dialog(object):
ACTOR_SYSTEM = 0
ACTOR_USER = 1
def __init__(self, object_id, session_id):
self.messages = []
self.states = [] # Each message has one state.
self.actors = [] # Each message has an actor id associated.
self.object_id = object_id
self.session_id = session_id
def add_message(self, text, state, actor):
self.messages.append(text)
self.states.append(state)
self.actors.append(actor)
def serialize(self):
return json.dumps(
{
'messages': self.messages,
'states': self.states,
'actors': self.actors,
'object_id': self.object_id,
'session_id': self.session_id
}, indent=4)
@classmethod
def deserialize(cls, input_data):
data = json.loads(input_data)
obj = Dialog(data['object_id'], data['session_id'])
obj.messages = data['messages']
obj.states = data['states']
obj.actors= data['actors']
return obj