scribbleimpl.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * scribble.h: User-Level API for Handwriting Recognition
  11. * Author: James Kempf
  12. * Created On: Mon Nov 2 14:01:25 1992
  13. * Last Modified By: Sape Mullender
  14. * Last Modified On: Fri Aug 25 10:24:50 EDT 2000
  15. * Copyright (c) 1994 by Sun Microsystems Computer Company
  16. * All rights reserved.
  17. *
  18. * Use and copying of this software and preparation of
  19. * derivative works based upon this software are permitted.
  20. * Any distribution of this software or derivative works
  21. * must comply with all applicable United States export control
  22. * laws.
  23. *
  24. * This software is made available as is, and Sun Microsystems
  25. * Computer Company makes no warranty about the software, its
  26. * performance, or its conformity to any specification
  27. */
  28. /*
  29. * Opaque type for the recognizer. The toolkit must access through
  30. * appropriate access functions.
  31. */
  32. //#pragma incomplete struct _Recognizer
  33. typedef struct _Recognizer* recognizer;
  34. /*
  35. * Opaque type for recognizers to implement dictionaries.
  36. */
  37. typedef struct _wordset *wordset;
  38. typedef struct rc rc;
  39. typedef struct rec_correlation rec_correlation;
  40. typedef struct rec_alternative rec_alternative;
  41. typedef struct rec_element rec_element;
  42. typedef struct gesture gesture;
  43. typedef uint wchar_t;
  44. /* Scalar Type Definitions */
  45. /* For better readibility.*/
  46. typedef int bool;
  47. #define true 1
  48. #define false 0
  49. /*For pointers to extra functions on recognizer.*/
  50. typedef void (*rec_fn)();
  51. /*
  52. * rec_confidence is an integer between 0-100 giving the confidence of the
  53. * recognizer in a particular result.
  54. */
  55. typedef unsigned char rec_confidence;
  56. /**************** RECOGNIZER CONFIGURATION INFORMATION *******************/
  57. /*
  58. * Recognizer information. Gives the locale, category of the character
  59. * set returned by the recognizer, and any subsets to which the
  60. * recognition can be limited. The locale and category should be
  61. * suitable for the setlocale(3). Those recognizers which don't do text
  62. * can simply report a blank locale and category, and report the
  63. * graphics types they recognize in the subset.
  64. */
  65. typedef struct {
  66. char* ri_locale; /*The locale of the character set.*/
  67. char* ri_name; /*Complete pathname to the recognizer.*/
  68. char** ri_subset; /*Null terminated list of subsets supported*/
  69. } rec_info;
  70. /*These define a set of common character subset names.*/
  71. #define GESTURE "GESTURE" /* gestures only */
  72. #define MATHSET "MATHSET" /* %^*()_+={}<>,/. */
  73. #define MONEYSET "MONEYSET" /* $, maybe cent, pound, and yen */
  74. #define WHITESPACE "WHITESPACE" /* gaps are recognized as space */
  75. #define KANJI_JIS1 "KANJI_JIS1" /* the JIS1 kanji only */
  76. #define KANJI_JIS1_PLUS "KANJI_JIS1_PLUS" /* JIS1 plus some JIS2 */
  77. #define KANJI_JIS2 "KANJI_JIS2" /* the JIS1 + JIS2 kanji */
  78. #define HIRIGANA "HIRIGANA" /* the hirigana */
  79. #define KATAKANA "KATAKANA" /* the katakana */
  80. #define UPPERCASE "UPPERCASE" /* upper case alphabetics, no digits */
  81. #define LOWERCASE "LOWERCASE" /* lower case alphabetics, no digits */
  82. #define DIGITS "DIGITS" /* digits 0-9 only */
  83. #define PUNCTUATION "PUNCTUATION" /* \!-;'"?()&., */
  84. #define NONALPHABETIC "NONALPHABETIC" /* all nonalphabetics, no digits */
  85. #define ASCII "ASCII" /* the ASCII character set */
  86. #define ISO_LATIN12 "ISO_LATIN12" /* The ISO Latin 12 characters */
  87. /******************** RECOGNITION INPUT STRUCTURES ***********************/
  88. /*
  89. * WINDOW SYSTEM INTERFACE
  90. */
  91. /*Bounding box. Structurally identical to Rectangle.*/
  92. typedef Rectangle pen_rect;
  93. /*
  94. * RECOGNITION CONTEXT
  95. */
  96. /* Structure for reporting writing area geometric constraints. */
  97. typedef struct {
  98. pen_rect pr_area;
  99. short pr_row, pr_col;
  100. } pen_frame;
  101. /*
  102. * Structure for describing a set of letters to constrain recognition.
  103. * ls_type is the same as the re_type field for rec_element below.
  104. */
  105. typedef struct _letterset {
  106. char ls_type;
  107. union _ls_set {
  108. char* aval;
  109. wchar_t* wval;
  110. } ls_set;
  111. } letterset;
  112. /********************* RECOGNITION RETURN VALUES *************************/
  113. /*Different types in union. "Other" indicates a cast is needed.*/
  114. #define REC_NONE 0x0 /*No return value*/
  115. #define REC_GESTURE 0x1 /*Gesture.*/
  116. #define REC_ASCII 0x2 /*Array of 8 bit ASCII*/
  117. #define REC_VAR 0x4 /*Array of variable width characters. */
  118. #define REC_WCHAR 0x8 /*Array of Unicode (wide) characters. */
  119. #define REC_OTHER 0x10 /*Undefined type.*/
  120. #define REC_CORR 0x20 /*rec_correlation struct*/
  121. /*
  122. * Recognition elements. A recognition element is a structure having a
  123. * confidence level member, and a union, along with a flag indicating
  124. * the union type. The union contains a pointer to the result. This
  125. * is the basic recognition return value, corresponding to one
  126. * recognized word, letter, or group of letters.
  127. */
  128. struct rec_element {
  129. char re_type; /*Union type flag.*/
  130. union {
  131. gesture * gval; /*Gesture.*/
  132. char* aval; /*ASCII and variable width.*/
  133. wchar_t* wval; /*Unicode.*/
  134. rec_correlation* rcval; /*rec_correlation*/
  135. } re_result;
  136. rec_confidence re_conf; /*Confidence (0-100).*/
  137. };
  138. /*
  139. * Recognition alternative. The recognition alternative gives
  140. * a translated element for a particular segmentation, and
  141. * a pointer to an array of alternatives for the next position
  142. * in the segmentation thread.
  143. */
  144. struct rec_alternative {
  145. rec_element ra_elem; /*the translated element*/
  146. uint ra_nalter; /*number of next alternatives*/
  147. rec_alternative* ra_next; /*the array of next alternatives*/
  148. };
  149. /************************** GESTURES **************************/
  150. /*
  151. * Gestures. The toolkit initializes the recognizer with a
  152. * set of gestures having appropriate callbacks.
  153. * When a gesture is recognized, it is returned as part of a
  154. * recognition element. The recognizer fills in the bounding
  155. * box and hotspots. The toolkit fills in any additional values,
  156. * such as the current window, and calls the callback.
  157. */
  158. struct gesture {
  159. char* g_name; /*The gesture's name.*/
  160. uint g_nhs; /*Number of hotspots.*/
  161. pen_point* g_hspots; /*The hotspots.*/
  162. pen_rect g_bbox; /*The bounding box.*/
  163. void (*g_action)(gesture*); /*Pointer to execution function.*/
  164. void* g_wsinfo; /*For toolkit to fill in.*/
  165. };
  166. typedef void (*xgesture)(gesture*);
  167. /*
  168. * Recognition correlation. A recognition correlation is a recognition
  169. * of the stroke input along with a correlation between the stroke
  170. * input and the recognized text. The rec_correlation struct contains
  171. * a pointer to an arrray of pointers to strokes, and
  172. * two arrays of integers, giving the starting point and
  173. * stopping point of each corresponding recogition element returned
  174. * in the strokes.
  175. */
  176. struct rec_correlation {
  177. rec_element ro_elem; /*The recognized alternative.*/
  178. uint ro_nstrokes; /*Number of strokes.*/
  179. Stroke* ro_strokes; /*Array of strokes.*/
  180. uint* ro_start; /*Starting index of points.*/
  181. uint* ro_stop; /*Stopping index of points.*/
  182. };
  183. /*
  184. * ADMINISTRATION
  185. */
  186. /*
  187. * recognizer_load - If directory is not NULL, then use it as a pathname
  188. * to find the recognizer. Otherwise, use the default naming conventions
  189. * to find the recognizer having file name name. The subset argument
  190. * contains a null-terminated array of names for character subsets which
  191. * the recognizer should translate.
  192. */
  193. recognizer recognizer_load(char*, char*, char**);
  194. /*
  195. * recognizer_unload - Unload the recognizer.
  196. */
  197. int recognizer_unload(recognizer);
  198. /*
  199. * recognizer_get_info-Get a pointer to a rec_info
  200. * giving the locale and subsets supported by the recognizer, and shared
  201. * library pathname.
  202. */
  203. const rec_info* recognizer_get_info(recognizer);
  204. /*
  205. * recognizer_manager_version-Return the version number string of the
  206. * recognition manager.
  207. */
  208. const char* recognizer_manager_version(recognizer);
  209. /*
  210. * recognizer_load_state-Get any recognizer state associated with name
  211. * in dir. Note that name may not be simple file name, since
  212. * there may be more than one file involved. Return 0 if successful,
  213. * -1 if not.
  214. */
  215. int recognizer_load_state(recognizer, char*, char*);
  216. /*
  217. * recognizer_save_state-Save any recognizer state to name
  218. * in dir. Note that name may not be a simple file name, since
  219. * there may be more than one file involved. Return 0 if successful,
  220. * -1 if not.
  221. */
  222. int recognizer_save_state(recognizer, char*, char*);
  223. /*
  224. * recognizer_error-Return the last error message, or NULL if none.
  225. */
  226. char* recognizer_error(recognizer);
  227. /*
  228. * DICTIONARIES
  229. */
  230. /* recognizer_load_dictionary-Load a dictionary from the directory
  231. * dir and file name. Return the dictionary pointer if successful,
  232. * otherwise NULL.
  233. */
  234. wordset recognizer_load_dictionary(recognizer, char*, char*);
  235. /* recoginzer_save_dictionary-Save the dictionary to the file. Return 0
  236. * successful, -1 if error occurs.
  237. */
  238. int recognizer_save_dictionary(recognizer, char*, char*, wordset);
  239. /*
  240. * recognizer_free_dictionary-Free the dictionary. Return 0 if successful,
  241. * -1 if error occurs.
  242. */
  243. int recognizer_free_dictionary(recognizer, wordset);
  244. /*
  245. * recognizer_add_to_dictionary-Add the word to the dictionary. Return 0
  246. * if successful, -1 if error occurs.
  247. */
  248. int recognizer_add_to_dictionary(recognizer, letterset*, wordset);
  249. /*
  250. * recognizer_delete_from_dictionary-Delete the word from the dictionary.
  251. * Return 0 if successful, -1 if error occurs.
  252. */
  253. int recognizer_delete_from_dictionary(recognizer, letterset*, wordset);
  254. /*
  255. * TRANSLATION
  256. */
  257. /* recognizer_set/get_context - Set/get the recognition context for
  258. * subsequent buffering and translation. recognizer_set_context()
  259. * returns -1 if an error occurs, otherwise 0. recognizer_get_context()
  260. * returns NULL if no context has been set. The context is copied to avoid
  261. * potential memory deallocation problems.
  262. */
  263. int recognizer_set_context(recognizer, rc*);
  264. rc* recognizer_get_context(recognizer);
  265. /* recognizer_clear - Set stroke buffer to NULL and clear the context.
  266. * Returns -1 if an error occurred, otherwise 0. Both the context and the
  267. * stroke buffer are deallocated. If delete_points_p is true, delete the
  268. * points also.
  269. */
  270. int recognizer_clear(recognizer, bool);
  271. /* recognizer_get/set_buffer - Get/set the stroke buffer. The stroke buffer
  272. * is copied to avoid potential memory allocation problems. Returns -1 if
  273. * an error occurs, otherwise 0.
  274. */
  275. int recognizer_get_buffer(recognizer, uint*, Stroke**);
  276. int recognizer_set_buffer(recognizer, uint, Stroke*);
  277. /* recognizer_translate - Copy the strokes argument into the stroke buffer and
  278. * translate the buffer. If correlate_p is true, then provide stroke
  279. * correlations as well. If either nstrokes is 0 or strokes is NULL, then
  280. * just translate the stroke buffer and return the translation. Return an
  281. * array of alternative translation segmentations in the ret pointer and the
  282. * number of alternatives in nret, or NULL and 0 if there is no translation.
  283. * The direction of segmentation is as specified by the rc_direction field in
  284. * the buffered recognition context. Returns -1 if an error occurred,
  285. * otherwise 0.
  286. */
  287. int recognizer_translate(recognizer, uint, Stroke*, bool,
  288. int*, rec_alternative**);
  289. /*
  290. * recognizer_get_extension_functions-Return a null terminated array
  291. * of functions providing extended functionality. Their interfaces
  292. * will change depending on the recognizer.
  293. */
  294. rec_fn* recognizer_get_extension_functions(recognizer);
  295. /*
  296. * GESTURE SUPPORT
  297. */
  298. /*
  299. * recognizer_get_gesture_names - Return a null terminated array of
  300. * character strings containing the gesture names.
  301. */
  302. char** recognizer_get_gesture_names(recognizer);
  303. /*
  304. * recognizer_set_gesture_action-Set the action function associated with the
  305. * name.
  306. */
  307. xgesture recognizer_set_gesture_action(recognizer, char*, xgesture, void*);
  308. /*
  309. * The following functions are for deleting data structures returned
  310. * by the API functions.
  311. */
  312. void delete_rec_alternative_array(uint, rec_alternative*, bool);
  313. void delete_rec_correlation(rec_correlation*, bool);
  314. /*
  315. * These are used by clients to create arrays for passing to API
  316. * functions.
  317. */
  318. Stroke* make_Stroke_array(uint);
  319. void delete_Stroke_array(uint, Stroke*, bool);
  320. pen_point* make_pen_point_array(uint);
  321. void delete_pen_point_array(pen_point*);
  322. Stroke* copy_Stroke_array(uint, Stroke*);
  323. /*Extension function interfaces and indices.*/
  324. #define LI_ISA_LI 0 /*Is this a li recognizer?.*/
  325. #define LI_TRAIN 1 /*Train recognizer*/
  326. #define LI_CLEAR 2 /* ari's clear-state extension fn. */
  327. #define LI_GET_CLASSES 3 /* ari's get-classes extension fn. */
  328. #define LI_NUM_EX_FNS 4 /*Number of extension functions*/
  329. typedef bool (*li_isa_li)(recognizer r);
  330. typedef int (*li_recognizer_train)(recognizer, rc*, uint,
  331. Stroke*, rec_element*, bool);
  332. typedef int (*li_recognizer_clearState)(recognizer);
  333. typedef int (*li_recognizer_getClasses)(recognizer, char ***, int *);