1*46439007SCharles.Forsyth# 2*46439007SCharles.Forsyth# Li-Yeung character recognition 3*46439007SCharles.Forsyth# 4*46439007SCharles.ForsythStrokes: module 5*46439007SCharles.Forsyth{ 6*46439007SCharles.Forsyth PATH: con "/dis/lib/strokes/strokes.dis"; 7*46439007SCharles.Forsyth 8*46439007SCharles.Forsyth Penpoint: adt 9*46439007SCharles.Forsyth { 10*46439007SCharles.Forsyth x, y: int; 11*46439007SCharles.Forsyth chaincode: int; 12*46439007SCharles.Forsyth }; 13*46439007SCharles.Forsyth 14*46439007SCharles.Forsyth Stroke: adt 15*46439007SCharles.Forsyth { 16*46439007SCharles.Forsyth npts: int; 17*46439007SCharles.Forsyth pts: array of Penpoint; 18*46439007SCharles.Forsyth xrange, yrange: int; 19*46439007SCharles.Forsyth 20*46439007SCharles.Forsyth new: fn(n: int): ref Stroke; 21*46439007SCharles.Forsyth copy: fn(nil: self ref Stroke): ref Stroke; 22*46439007SCharles.Forsyth trim: fn(nil: self ref Stroke, n: int); 23*46439007SCharles.Forsyth bbox: fn(nil: self ref Stroke): (int, int, int, int); 24*46439007SCharles.Forsyth scaleup: fn(nil: self ref Stroke): int; 25*46439007SCharles.Forsyth translate: fn(nil: self ref Stroke, minx: int, miny: int, scalex: int, scaley: int); 26*46439007SCharles.Forsyth center: fn(nil: self ref Stroke); 27*46439007SCharles.Forsyth regions: fn(nil: self ref Stroke): ref Region; 28*46439007SCharles.Forsyth dominant: fn(nil: self ref Stroke): ref Stroke; 29*46439007SCharles.Forsyth interpolate: fn(points: self ref Stroke): ref Stroke; 30*46439007SCharles.Forsyth length: fn(nil: self ref Stroke): int; 31*46439007SCharles.Forsyth pathlen: fn(nil: self ref Stroke, first: int, last: int): int; 32*46439007SCharles.Forsyth contourangles: fn(nil: self ref Stroke, regions: ref Region): array of int; 33*46439007SCharles.Forsyth filter: fn(nil: self ref Stroke): ref Stroke; 34*46439007SCharles.Forsyth }; 35*46439007SCharles.Forsyth 36*46439007SCharles.Forsyth # ordered list of regions 37*46439007SCharles.Forsyth Region: adt 38*46439007SCharles.Forsyth { 39*46439007SCharles.Forsyth rtype: int; 40*46439007SCharles.Forsyth start: int; 41*46439007SCharles.Forsyth end: int; 42*46439007SCharles.Forsyth next: cyclic ref Region; 43*46439007SCharles.Forsyth }; 44*46439007SCharles.Forsyth 45*46439007SCharles.Forsyth # region types 46*46439007SCharles.Forsyth Rconvex, Rconcave, Rplain, Rpseudo: con iota; 47*46439007SCharles.Forsyth 48*46439007SCharles.Forsyth Classifier: adt 49*46439007SCharles.Forsyth { 50*46439007SCharles.Forsyth nclasses: int; # number of symbols in class 51*46439007SCharles.Forsyth examples: array of list of ref Stroke; # optional training examples 52*46439007SCharles.Forsyth cnames: array of string; # the class names 53*46439007SCharles.Forsyth canonex: array of ref Stroke; # optional canonical versions of the strokes 54*46439007SCharles.Forsyth dompts: array of ref Stroke; # dominant points 55*46439007SCharles.Forsyth 56*46439007SCharles.Forsyth match: fn(nil: self ref Classifier, stroke: ref Stroke): (int, string); 57*46439007SCharles.Forsyth }; 58*46439007SCharles.Forsyth 59*46439007SCharles.Forsyth init: fn(); 60*46439007SCharles.Forsyth 61*46439007SCharles.Forsyth preprocess_stroke: fn(nil: ref Stroke); 62*46439007SCharles.Forsyth score_stroke: fn(a: ref Stroke, b: ref Stroke): (int, int); 63*46439007SCharles.Forsyth 64*46439007SCharles.Forsyth compute_similarity: fn(a: ref Stroke, b: ref Stroke): int; 65*46439007SCharles.Forsyth compute_distance: fn(a: ref Stroke, b: ref Stroke): int; 66*46439007SCharles.Forsyth compute_chain_code: fn(nil: ref Stroke); 67*46439007SCharles.Forsyth compute_unit_chain_code: fn(pts: ref Stroke); 68*46439007SCharles.Forsyth 69*46439007SCharles.Forsyth regiontype: fn(ang: int): int; 70*46439007SCharles.Forsyth 71*46439007SCharles.Forsyth sqrt: fn(n: int): int; 72*46439007SCharles.Forsyth likeatan: fn(top: int, bot: int): int; 73*46439007SCharles.Forsyth quadr: fn(t: int): int; 74*46439007SCharles.Forsyth 75*46439007SCharles.Forsyth printpoints: fn(fd: ref Sys->FD, nil: ref Stroke, sep: string); 76*46439007SCharles.Forsyth 77*46439007SCharles.Forsyth MAXDIST: con 16r7FFFFFFF; 78*46439007SCharles.Forsyth}; 79*46439007SCharles.Forsyth 80*46439007SCharles.ForsythReadstrokes: module 81*46439007SCharles.Forsyth{ 82*46439007SCharles.Forsyth PATH: con "/dis/lib/strokes/readstrokes.dis"; 83*46439007SCharles.Forsyth 84*46439007SCharles.Forsyth init: fn(nil: Strokes); 85*46439007SCharles.Forsyth read_classifier: fn(file: string, build: int, needex: int): (string, ref Strokes->Classifier); 86*46439007SCharles.Forsyth read_digest: fn(fd: ref Sys->FD): (string, array of string, array of ref Strokes->Stroke); 87*46439007SCharles.Forsyth read_examples: fn(fd: ref Sys->FD): (string, array of string, array of list of ref Strokes->Stroke); 88*46439007SCharles.Forsyth}; 89*46439007SCharles.Forsyth 90*46439007SCharles.ForsythWritestrokes: module 91*46439007SCharles.Forsyth{ 92*46439007SCharles.Forsyth PATH: con "/dis/lib/strokes/writestrokes.dis"; 93*46439007SCharles.Forsyth 94*46439007SCharles.Forsyth init: fn(nil: Strokes); 95*46439007SCharles.Forsyth write_digest: fn(fd: ref Sys->FD, nil: array of string, nil: array of ref Strokes->Stroke): string; 96*46439007SCharles.Forsyth write_examples: fn(fd: ref Sys->FD, nil: array of string, nil: array of list of ref Strokes->Stroke): string; 97*46439007SCharles.Forsyth}; 98*46439007SCharles.Forsyth 99*46439007SCharles.ForsythBuildstrokes: module 100*46439007SCharles.Forsyth{ 101*46439007SCharles.Forsyth PATH: con "/dis/lib/strokes/buildstrokes.dis"; 102*46439007SCharles.Forsyth 103*46439007SCharles.Forsyth init: fn(nil: Strokes); 104*46439007SCharles.Forsyth canonical_example: fn(n: int, cnames: array of string, nil: array of list of ref Strokes->Stroke): (string, array of ref Strokes->Stroke, array of ref Strokes->Stroke); 105*46439007SCharles.Forsyth canonical_stroke: fn(points: ref Strokes->Stroke): ref Strokes->Stroke; 106*46439007SCharles.Forsyth compute_equipoints: fn(nil: ref Strokes->Stroke): ref Strokes->Stroke; 107*46439007SCharles.Forsyth}; 108*46439007SCharles.Forsyth 109*46439007SCharles.Forsyth# special characters and gestures 110*46439007SCharles.Forsyth# in digits.cl: BNASRPUVWX 111*46439007SCharles.Forsyth# in punc.cl: TFGHIJK 112*46439007SCharles.Forsyth# in letters.cl: ABNPRSUVWX 113*46439007SCharles.Forsyth 114*46439007SCharles.Forsyth# L caps lock 115*46439007SCharles.Forsyth# N num lock 116*46439007SCharles.Forsyth# P ctrl (Unix), punc shift (orig) 117*46439007SCharles.Forsyth# S shift 118*46439007SCharles.Forsyth 119*46439007SCharles.Forsyth# A space 120*46439007SCharles.Forsyth# B backspace 121*46439007SCharles.Forsyth# R return 122*46439007SCharles.Forsyth# . puncshift 123