Exemple #1
0
 def Score( self, strokelist, max_return = 1, interest = 0.2):
     "Compare these strokes to all templates, and return the best templates with their scores. "
     ROTATIONS = 16
     best_templ = None 
     for stroke_order in itertools.permutations(strokelist):
         pointlist = []
         for s in stroke_order:
             pointlist.extend(s.Points)
         new_stroke = Stroke.Stroke(points=pointlist)
         
         for name, template_set in self._templates.items():
             for template in template_set:
                 for angle in [2 * math.pi / ROTATIONS * i for i in range(ROTATIONS)]:
                     end_template = GeomUtils.rotateStroke(Stroke.Stroke(points=template), angle).Points
                     firstpass_score = _scoreStroke(new_stroke, end_template, 10)
                     if best_templ is not None and firstpass_score - 0.1 > best_templ['score']:
                         continue
                     score = _scoreStroke(new_stroke, end_template, len(end_template))
                     logger.debug("   '%s' ... %s" % (name, score))
             
                     if best_templ is None:
                         best_templ = {'score': score + 1}
                 
                     if score < best_templ['score']:
                         best_templ['name'] = name
                         best_templ['score'] = score
                         best_templ['template'] = end_template
     return best_templ