selectors.py
changeset 3293 69c0ba095536
parent 3023 7864fee8b4ec
parent 3276 4480887772a3
child 3369 7b88d12b4ee2
equal deleted inserted replaced
3230:1d25e928c299 3293:69c0ba095536
   959     :param scorefunc: callable expected to take an entity as argument and to
   959     :param scorefunc: callable expected to take an entity as argument and to
   960                       return a score >= 0
   960                       return a score >= 0
   961     """
   961     """
   962     def __init__(self, scorefunc, once_is_enough=False):
   962     def __init__(self, scorefunc, once_is_enough=False):
   963         super(score_entity, self).__init__(once_is_enough)
   963         super(score_entity, self).__init__(once_is_enough)
   964         self.score_entity = scorefunc
   964         def intscore(*args, **kwargs):
       
   965             score = scorefunc(*args, **kwargs)
       
   966             if not score:
       
   967                 return 0
       
   968             if isinstance(score, (int, long)):
       
   969                 return score
       
   970             return 1
       
   971         self.score_entity = intscore