1 from Keys import *
2
4 keyType = 'message'
5 slots = {'sact_type':Key.ACTION,
6 'sender':Key.ENTITY,
7 'addressee':Key.ENTITIES,
8 'lhs':Key.STATE,
9 }
10 decayRate = 0.5
11
13 """Utility method that takes a mapping from entity references (e.g., 'self', 'actor') to actual entity names (e.g., 'Bill', 'agent0'). It returns a new key string with the substitution applied. It also reduces any 'identity' keys to be either constant or null depending on whether the key matches the identity of the entity represented in the dictionary provided. Subclasses should override this method for more instantiation of more specialized fields.
14 @param table: A dictionary of label-value pairs. Any slot in the key whose filler matches a label in the given table will be replaced by the associated value.
15 @type table: C{dict}
16 @return: A new L{Key} instance with the appropriate label substitutions
17 @rtype: L{Key}
18 """
19 keys=[]
20 if not self['sact_type'] or self['sact_type'] == 'wait':
21
22 for addressee in table['addressee']:
23 feature='obs-'+table['actor']+'-'+table['sact_type']+'-to-'+addressee
24
25 if table['sact_type'] in ['enquiry','inform','accept','reject','inform_info']:
26 feature += '-about-'+table['factors'][0]['lhs'][1]+ '-'+table['factors'][0]['lhs'][3]
27
28 key = StateKey({'entity':table['self'].name,
29 'feature':feature})
30
31 keys.append(key)
32 else:
33
34 for addressee in table['addressee']:
35 feature='obs-'+table['actor']+'-'+self['sact_type']+'-to-'+addressee
36
37 if table['sact_type'] in ['enquiry','inform','accept','reject','inform_info']:
38 feature += '-about-'+table['factors'][0]['lhs'][1]+ '-'+table['factors'][0]['lhs'][3]
39
40 key = StateKey({'entity':table['self'].name,
41 'feature':feature})
42
43 keys.append(key)
44 if len(keys) > 0:
45 return keys
46 else:
47 return keyDelete
48
49 - def simpleText(self):
50 content = self['sact_type']
51 if self['addressee']:
52 for add in self['addressee']:
53 content += add+' ,'
54 if self['sender']:
55 content += ' by %s' % (self['sender'])
56 if self['lhs']:
57 content += ' about %s' % (self['lhs'])
58 return content
59
67
75
76
78 keyType = 'equal'
79 slots = {'messageAttr':Key.STATE,
80 'value':Key.VALUE}
81
83 """Utility method that takes a mapping from entity references (e.g., 'self', 'actor') to actual entity names (e.g., 'Bill', 'agent0'). It returns a new key string with the substitution applied. It also reduces any 'identity' keys to be either constant or null depending on whether the key matches the identity of the entity represented in the dictionary provided. Subclasses should override this method for more instantiation of more specialized fields.
84 @param table: A dictionary of label-value pairs. Any slot in the key whose filler matches a label in the given table will be replaced by the associated value.
85 @type table: C{dict}
86 @return: A new L{Key} instance with the appropriate label substitutions
87 @rtype: L{Key}
88 """
89 if table[self['messageAttr']] == table[self['value']]:
90 return keyConstant
91 else:
92 return keyDelete
93
94 - def simpleText(self):
95 return 'action['+self['messageAttr']+'] equals to '+self['value']
96
98 keyType = 'checkApply'
99 slots = {'obligation':Key.STATE,
100 'role':Key.VALUE}
101
103 """Utility method that takes a mapping from entity references (e.g., 'self', 'actor') to actual entity names (e.g., 'Bill', 'agent0'). It returns a new key string with the substitution applied. It also reduces any 'identity' keys to be either constant or null depending on whether the key matches the identity of the entity represented in the dictionary provided. Subclasses should override this method for more instantiation of more specialized fields.
104 @param table: A dictionary of label-value pairs. Any slot in the key whose filler matches a label in the given table will be replaced by the associated value.
105 @type table: C{dict}
106 @return: A new L{Key} instance with the appropriate label substitutions
107 @rtype: L{Key}
108 """
109
110
111
112
113 try:
114 dummy1,sact_type,dummy2,toobject,dummy3,entity,feature = string.split(self['obligation'],'-')
115 except ValueError:
116 try:
117 dummy1,sact_type,dummy2,toobject = string.split(self['obligation'],'-')
118 except:
119 print self
120 print table
121 raise 'Illegal obligation name: ',self['obligation']
122
123 try:
124 actor = table['actor'].name
125 except AttributeError:
126 actor = table['actor']
127
128 assert(isinstance(actor,str))
129
130 if actor == toobject:
131 if table['sact_type']=='greet_init' and sact_type == 'greet_resp':
132 return keyConstant
133 elif table['sact_type']=='greet2_init' and sact_type == 'greet2_resp':
134 return keyConstant
135 elif table['sact_type']=='bye_init' and sact_type == 'bye_resp':
136 return keyConstant
137 elif table['sact_type']=='thank' and sact_type == 'urwelcome':
138 return keyConstant
139 elif table['sact_type']=='inform_info' and sact_type == 'OK':
140 return keyConstant
141 elif table['sact_type']=='request' and sact_type == 'accept':
142 return keyConstant
143
144
145
146
147
148
149
150
151
152
153 elif table['sact_type']=='enquiry' and sact_type == 'inform':
154 topic = table['factors'][0]['lhs'][1]+ '-'+table['factors'][0]['lhs'][3]
155 try:
156 entity = entity.name
157 except AttributeError:
158 pass
159 if topic == entity+'-'+feature:
160 return keyConstant
161 else:
162 pass
163
164 return keyDelete
165
166 - def simpleText(self):
167 return 'I have the obligation '+self['obligation']+' as an '+self['role']
168
170 keyType = 'checkExistOblig'
171 slots = {'entity':Key.ENTITY,}
172
174 """Utility method that takes a mapping from entity references (e.g., 'self', 'actor') to actual entity names (e.g., 'Bill', 'agent0'). It returns a new key string with the substitution applied. It also reduces any 'identity' keys to be either constant or null depending on whether the key matches the identity of the entity represented in the dictionary provided. Subclasses should override this method for more instantiation of more specialized fields.
175 @param table: A dictionary of label-value pairs. Any slot in the key whose filler matches a label in the given table will be replaced by the associated value.
176 @type table: C{dict}
177 @return: A new L{Key} instance with the appropriate label substitutions
178 @rtype: L{StateKey}
179 """
180 keys = []
181 for addressee in table['addressee']:
182 feature = 'obli-'+table['sact_type']+'-to-'+addressee
183 if table['sact_type'] in ['inform','accept','reject']:
184 feature += '-about-'+table['factors'][0]['lhs'][1]+ '-'+table['factors'][0]['lhs'][3]
185
186 keys.append(StateKey({'entity':table['self'].name,
187 'feature':feature}))
188
189 return keys
190
191 - def simpleText(self):
192 return 'I have the obligation to make this response'
193
195 keyType = 'checkGroupExistOblig'
196 slots = {'entity':Key.ENTITY,}
197
199 """Utility method that takes a mapping from entity references (e.g., 'self', 'actor') to actual entity names (e.g., 'Bill', 'agent0'). It returns a new key string with the substitution applied. It also reduces any 'identity' keys to be either constant or null depending on whether the key matches the identity of the entity represented in the dictionary provided. Subclasses should override this method for more instantiation of more specialized fields.
200 @param table: A dictionary of label-value pairs. Any slot in the key whose filler matches a label in the given table will be replaced by the associated value.
201 @type table: C{dict}
202 @return: A new L{Key} instance with the appropriate label substitutions
203 @rtype: L{StateKey}
204 """
205 keys = []
206 for addressee in table['addressee']:
207 feature = 'obli-'+table['sact_type']+'-to-'+addressee
208
209 if table['sact_type'] in ['inform','accept','reject']:
210 feature += '-about-'+table['factors'][0]['lhs'][1]+ '-'+table['factors'][0]['lhs'][3]
211
212 for entity1 in table['self'].getEntityBeliefs():
213 if entity1.getState('group') == table['self'].getState('group'):
214 keys.append(StateKey({'entity':entity1.name,
215 'feature':feature}))
216 if len(keys) > 0:
217 return keys
218 else:
219 return keyDelete
220
221 - def simpleText(self):
222 return 'Somebody in the group have the obligation to make this response'
223
225 keyType = 'checkExistUnFinOblig'
226 slots = {'entity':Key.ENTITY,}
227
229 """Utility method that takes a mapping from entity references (e.g., 'self', 'actor') to actual entity names (e.g., 'Bill', 'agent0'). It returns a new key string with the substitution applied. It also reduces any 'identity' keys to be either constant or null depending on whether the key matches the identity of the entity represented in the dictionary provided. Subclasses should override this method for more instantiation of more specialized fields.
230 @param table: A dictionary of label-value pairs. Any slot in the key whose filler matches a label in the given table will be replaced by the associated value.
231 @type table: C{dict}
232 @return: A new L{Key} instance with the appropriate label substitutions
233 @rtype: L{Key}
234 """
235 keys = []
236 for feature in table['self'].getStateFeatures():
237 if string.find(feature,'obli')==0 and feature != 'obligNorm':
238 keys.append(StateKey({'entity':table['self'].name,
239 'feature':feature}))
240 if len(keys) > 0:
241 return keys
242 else:
243 return keyDelete
244
245 - def simpleText(self):
246 return 'I have unfinished obligation'
247
249 keyType = 'checkGroupExistUnFinOblig'
250 slots = {'entity':Key.ENTITY,}
251
253 """Utility method that takes a mapping from entity references (e.g., 'self', 'actor') to actual entity names (e.g., 'Bill', 'agent0'). It returns a new key string with the substitution applied. It also reduces any 'identity' keys to be either constant or null depending on whether the key matches the identity of the entity represented in the dictionary provided. Subclasses should override this method for more instantiation of more specialized fields.
254 @param table: A dictionary of label-value pairs. Any slot in the key whose filler matches a label in the given table will be replaced by the associated value.
255 @type table: C{dict}
256 @return: A new L{Key} instance with the appropriate label substitutions
257 @rtype: L{Key}
258 """
259 keys = []
260 for entity1 in table['self'].getEntityBeliefs():
261 for feature in entity1.getStateFeatures():
262 if string.find(feature,'obli')==0 and not feature == 'obligNorm':
263 key = StateKey({'entity':entity1.name,
264 'feature':feature})
265 keys.append(key)
266 if len(keys) > 0:
267 return keys
268 else:
269 return keyDelete
270
271 - def simpleText(self):
272 return 'Somebody in the group still have unfinished obligation'
273
275 """Helper function for creating GroupStateKey objects
276 @param entity: The group of entity to be pointed to by this key
277 @type entity: string
278 @param feature: The state feature to be pointed to by this key
279 @type feature: string
280 @return: the corresponding GroupStateKey object"""
281 return GroupStateKey({'entity':entity,'feature':feature})
282
283
285 """Returns a key correspond to the value of the given action"""
286 try:
287 return MessageKey({'sact_type':action['sact_type'],
288 'sender':action['sender'],
289 'addressee':action['addressee'],
290 'lhs':action['factors'][0]['lhs'],})
291 except:
292 return MessageKey({'sact_type':action['sact_type'],
293 'sender':action['sender'],
294 'addressee':action['addressee'],
295 'lhs':'dummy',})
296
298 return IdentityKey({'relationship':'in',
299 'entity':entity})
300
302 return EqualKey({'messageAttr':'attr',
303 'value':value})
304
305
307 return ObligKey({'obligation':feature,
308 'role':role})
309
314
315
318
319
322
323
326
327
330