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