本文整理匯總了Python中rule.Rule.add_python_action方法的典型用法代碼示例。如果您正苦於以下問題:Python Rule.add_python_action方法的具體用法?Python Rule.add_python_action怎麽用?Python Rule.add_python_action使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rule.Rule
的用法示例。
在下文中一共展示了Rule.add_python_action方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _add_debug_rule
# 需要導入模塊: from rule import Rule [as 別名]
# 或者: from rule.Rule import add_python_action [as 別名]
def _add_debug_rule(self, salience, preceding_rules):
rule_names = ', '.join(rule.name or '->{}'.format(rule.target._name) for rule in preceding_rules)
def debug_func(*args, **kwargs):
self.logger.debug('Ran rule(s): {} at salience: {}.'.format(rule_names, salience))
rule = Rule()
rule.set_salience(salience-1)
rule.add_python_action(debug_func)
rule.build(self.engine)
示例2: RuleDef
# 需要導入模塊: from rule import Rule [as 別名]
# 或者: from rule.Rule import add_python_action [as 別名]
class RuleDef(FactReference, ConvertibleToExpr):
_all_instances = []
def __init__(self, *modifiers):
self._rule = Rule()
for modifier in modifiers:
modifier(self._rule)
self._fields = dict(self._rule.get_target_fields() or {})
self.__dict__.update(self._fields)
self._all_instances.append(self)
def _set_name(self, name):
self._rule.set_name(name)
def _build(self, engine):
self._rule.build(engine)
def _python_action(self, function):
self._rule.add_python_action(function)
def _aggregator(self, aggregator_cls):
self._rule.add_aggregator_cls(aggregator_cls)
def _groupby(self, *keys):
return lambda func : self._rule.add_aggregator_cls(grouping_aggregator(keys, func))
def __getitem__(self, key):
return self._rule.target[key]
def _to_expr(self):
return self._rule.target._to_expr()
@property
def _name(self):
return self._rule.get_target_name()
def _update_python_param(self, params, value):
return self._rule.target._update_python_param(params, value)
def _from_python_params(self, params):
return self._rule.target._from_python_params(params)