def get_slot_constraint(self, vrs): """ build rule CE slot constraint for clips as time in a prem """ if utils.varpat.match(self.value): return self.get_var_slot_constraint(vrs, self.value) newvar = utils._newvar() constraint = '?'+newvar for x in ('start', 'end'): x_constraint = getattr(self, x).get_constraint(vrs, newvar, [x]) if x_constraint: constraint += '&:(eq (send ?%s get-%s) %s)' % (newvar, x, x_constraint) return constraint
def get_slot_constraint(self, vrs): """ build rule CE constraint for clips for a slot constraint for a prop in a rule """ if utils.varpat.match(self.value): if self.clsvar and self.clsvar not in vrs: if vrs[self.value]: vrs[self.clsvar] = ( utils.clips_instance(*(vrs[self.value])), [], ['class']) else: vrs[self.clsvar] = (self.value, [], ['class']) return self.get_var_slot_constraint(vrs, self.value) newvar = utils._newvar() if self.clsvar: if self.clsvar in vrs: if vrs[self.clsvar]: constraint = [ '?%(newvar)s&:(eq (class ?%(newvar)s) %(var)s)' % { 'newvar': newvar, 'var': utils.clips_instance(*(vrs[self.clsvar]))}] else: constraint = [ '?%(newvar)s&:(eq (class ?%(newvar)s) %(var)s)' % { 'newvar': newvar, 'var': self.clsvar}] else: vrs[self.clsvar] = (newvar, [], ('class',)) constraint = [class_constraint % {'val': newvar, 'cls': self.__class__.__name__}] else: constraint = [class_constraint % {'val': newvar, 'cls': self.__class__.__name__}] for mod,cls in self.mods.items(): mod_o = getattr(self, mod, _m) if mod_o is not _m: constraint_meth = getattr(mod_o, 'get_constraint_cls', mod_o.get_constraint) constraint.append(constraint_meth(vrs, newvar, (mod,))) return ''.join(constraint)