@@ -330,14 +330,16 @@ def _cond(value, symbol):
330
330
if symbol == '>=' : return GE (value )
331
331
332
332
# 计算分值的闭包方法
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
338
338
# 构建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' ]))
341
343
setattr (EmbryoScore , f'rule{ index } ' , R )
342
344
343
345
index += 1 # Rule序号递增
0 commit comments