本文整理匯總了Python中rule.Rule.set_name方法的典型用法代碼示例。如果您正苦於以下問題:Python Rule.set_name方法的具體用法?Python Rule.set_name怎麽用?Python Rule.set_name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rule.Rule
的用法示例。
在下文中一共展示了Rule.set_name方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: AssertAggregate
# 需要導入模塊: from rule import Rule [as 別名]
# 或者: from rule.Rule import set_name [as 別名]
class AssertAggregate(Assert):
def __init__(self, **kwargs):
self.map_reduce_values = {}
for key, value in kwargs.items():
if isinstance(value, MapReduceFunc):
del kwargs[key]
subkeys = []
for n, map_value in enumerate(value.map_values):
subkey = key if n == 0 else '{}_{}'.format(key, n+1)
kwargs[subkey] = map_value
subkeys.append(subkey)
self.map_reduce_values[key] = (value, subkeys)
super(AssertAggregate, self).__init__(**kwargs)
def prepare_rule(self, rule):
self.data.update({key : normalize_expr(value) for key, value in rule.groupby.iteritems()})
self.data[UNIQUE_INDEX_FIELD] = gensym()
super(AssertAggregate, self).prepare_rule(rule)
self._create_reduce_rule(rule)
def _create_reduce_rule(self, map_rule):
r1 = map_rule.target[0]
r2 = map_rule.target[1]
self.reduce_rule = Rule()
self.reduce_rule.set_name('_Reduce')
for field_name in map_rule.groupby:
self.reduce_rule.add_variable(getattr(r1, field_name), getattr(r2, field_name))
self.reduce_rule.add_condition(fact_index(r1) != fact_index(r2))
reduce_kwargs = {}
for field_name, (value, subfields) in self.map_reduce_values.iteritems():
v1 = [getattr(r1, field_name) for field_name in subfields]
v2 = [getattr(r2, field_name) for field_name in subfields]
if len(subfields) == 1:
v1 = v1[0]
v2 = v2[0]
reduced = value._reduce(v1, v2)
if len(subfields) == 1:
reduced = [reduced]
reduce_kwargs.update(dict(zip(subfields, reduced)))
self.reduce_rule.add_action(Delete(r2))
self.reduce_rule.add_action(Update(r1, **reduce_kwargs))
self.reduce_rule.set_salience(map_rule.salience)
map_rule.add_secondary_rule(self.reduce_rule)
示例2: RuleDef
# 需要導入模塊: from rule import Rule [as 別名]
# 或者: from rule.Rule import set_name [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)