Open wangyingsm opened 5 years ago
Hi,
the error you are receiving is due to the usage of partial functions in the RHS of the rule.
You can solve this using a closure instead of a partial function:
def _add_partial(score, weight):
def _add(self, **kwargs):
s, w = int(score), float(weight)
self.score += s * w
return _add
R = Rule(AND(Fact(**rule, value=MATCH.value &
_cond(rule_item['value'], rule_item['symbol']))),
salience=sal)(_add_partial(score=rule_item['score'],
weight=rule_item['weight']))
Hope this help!
Hi,
the error you are receiving is due to the usage of partial functions in the RHS of the rule.
You can solve this using a closure instead of a partial function:
def _add_partial(score, weight): def _add(self, **kwargs): s, w = int(score), float(weight) self.score += s * w return _add R = Rule(AND(Fact(**rule, value=MATCH.value & _cond(rule_item['value'], rule_item['symbol']))), salience=sal)(_add_partial(score=rule_item['score'], weight=rule_item['weight']))
Hope this help!
Wow. It DOES WORK. THANKS.
Background, I am new to Pyknow. I want to build a expert system to auto calculate a cell quality score based on some parameters. The score algorithm should be loaded from a json data, such like:
Here are my codes for this,
It raises a AttributeError: 'Rule' object has no attribute 'name' when engine.run() on engine.py line 162
I can't find out what the problem is. Wonder if I can get some help here. THANKS.