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