- int bestmatch_rx=-1;
- current= &ocr_contexts[ctx];
- for (;;) {
- if (x>w) break;
- Pixcol cv= cols[x];
- for (i=0; i<current->nlinks; i++)
- if (current->links[i].col == cv)
- goto found;
- /* not found */
- break;
- found:
- current= current->links[i].then;
- if (current->s[0]) { bestmatch=current; bestmatch_rx=x; }
- x++;
+
+ DatabaseNode *uniquematch= 0;
+ int uniquematch_rx=-1;
+
+ debugf("OCR lx=%d ctxmap=%x ",lx,ctxmap);
+
+ for (ctxi=0; ctxi<NCONTEXTS; ctxi++) {
+ DatabaseNode *current= &rd->contexts[ctxi];;
+ DatabaseNode *bestmatch= 0;
+ int bestmatch_rx=-1;
+
+ x= lx;
+ if (!(ctxmap & (1u << ctxi))) continue;
+ debugf(" || %s",context_names[ctxi]);
+
+ for (;;) {
+ debug_flush();
+ debugf(" | x=%d",x);
+ if (x>w) break;
+ Pixcol cv= cols[x];
+ debugf(" cv=%"PSPIXCOL(PRIx),cv);
+ for (i=0; i<current->nlinks; i++)
+ if (current->links[i].col == cv)
+ goto found;
+ /* not found */
+ debugf(" ?");
+ break;
+
+ found:
+ current= current->links[i].then;
+ if (current->s[0]) {
+ debugf(" \"%s\"%s",current->s,current->endsword?"_":"");
+ bestmatch= current;
+ bestmatch_rx= x;
+ } else {
+ debugf(" ...");
+ }
+
+ x++;
+ }
+
+ if (bestmatch) {
+ if (uniquematch && strcmp(bestmatch->s, uniquematch->s)) {
+ debugf( " ambiguous");
+ uniquematch= 0;
+ break;
+ }
+ uniquematch= bestmatch;
+ uniquematch_rx= bestmatch_rx;
+ }