def onStrokeAdded(self, stroke): """ Attempts to classify a stroke using the given training data """ bbox1 = (stroke.BoundTopLeft, stroke.BoundBottomRight) s1_eps = (stroke.Points[0], stroke.Points[-1]) #Stroke 1 endpoints matchStks = set() for stk2, connectStrokes in self.allStrokes.items(): bbox2 = (stroke.BoundTopLeft, stroke.BoundBottomRight) s2_eps = (stk2.Points[0], stk2.Points[-1]) #Stroke 2 endpoints for ep in s1_eps: #Do any of the stroke's endpoints overlap stroke2? if GeomUtils.pointInBox(ep, bbox2[0], bbox2[1]): if ep in stk2.Points: matchStks.update(connectStrokes) break if len(connectStrokes) > 0: break for ep in s2_eps: #Do any of stroke2's endpoints overlap stroke? if GeomUtils.pointInBox(ep, bbox1[0], bbox1[1]): if ep in stroke.Points: matchStks.update(connectStrokes) break if len(connectStrokes) > 0: break matchStks.add(stroke) #Update the connected strokes list for stk in matchStks: self.allStrokes[stk] = matchStks strokeList = list(matchStks) scores = self.classifier.classifyStrokeList(strokeList) #Remove the previous annotations for stk in strokeList: annotations = stk.findAnnotations(annoType = RubineAnnotation) for anno in annotations: self.getBoard().RemoveAnnotation(anno) if len(scores) > 0: height = stroke.BoundTopLeft.Y - stroke.BoundBottomRight.Y best = scores[0]['symbol'] self.getBoard().AnnotateStrokes( strokeList, RubineAnnotation(scores))