Skip to content

Commit 4c9d666

Browse files
committed
根据github上原作者的解决方案
buguroo/pyknow#39 修改自动评分实现
1 parent d4d0ea4 commit 4c9d666

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

code/python/knowledge/embryo_score.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,16 @@ def _cond(value, symbol):
330330
if symbol == '>=': return GE(value)
331331

332332
# 计算分值的闭包方法
333-
def _add(self, **kwargs):
334-
if 'score' not in kwargs or 'weight' not in kwargs:
335-
raise ValueError('参数中没有分值和权重,无法计算里程碑分值')
336-
s, w = int(kwargs['score']), float(kwargs['weight'])
337-
self.score += s * w
333+
def _add_partial(score, weight):
334+
def _add(self, **kwargs):
335+
s, w = int(score), float(weight)
336+
self.score += s * w
337+
return _add
338338
# 构建Rule处理方法,并将其添加到EmbryoScore类中
339-
R = Rule(AND(Fact(**rule, value=MATCH.value & _cond(rule_item['value'], rule_item['symbol']))),
340-
salience=sal)(partial(_add, score=rule_item['score'], weight=rule_item['weight']))
339+
R = Rule(AND(Fact(**rule, value=MATCH.value &
340+
_cond(rule_item['value'], rule_item['symbol']))),
341+
salience=sal)(_add_partial(score=rule_item['score'],
342+
weight=rule_item['weight']))
341343
setattr(EmbryoScore, f'rule{index}', R)
342344

343345
index += 1 # Rule序号递增

0 commit comments

Comments
 (0)