4 * Copyright (C) 2003-2005 TABATA Yusuke
10 #include <anthy/matrix.h>
18 struct use_case *next;
24 struct use_case uc_head;
28 /* ÍÑÎãÄêµÁ¤Î¹Ô¤«¤éñ¸ì¤Îid¤òµá¤á¤ë
31 get_id_from_word_line(char *buf)
40 res = sscanf(buf, "%s %s %s %s", yomi, okuri, wt, kanji);
44 xs = anthy_cstr_to_xstr(kanji, 0);
45 id = anthy_xstr_hash(xs);
51 commit_uc(struct uc_dict *dict, int x, int y)
57 uc = malloc(sizeof(struct use_case));
61 uc->next = dict->uc_head.next;
62 dict->uc_head.next = uc;
66 /* ÍÑÎã¥Ç¡¼¥¿¥Ù¡¼¥¹¤òºî¤ë */
70 struct uc_dict *dict = malloc(sizeof(struct uc_dict));
72 dict->uc_head.next = NULL;
78 /* ÍÑÎã¥Õ¥¡¥¤¥ë¤òÆɤ߹þ¤à */
80 read_uc_file(struct uc_dict *dict, const char *fn)
84 int off, base = 0, cur;
87 uc_file = fopen(fn, "r");
93 * off=1,2..n : ¤½¤ì¤È´Ø·¸¤¢¤ëñ¸ì
96 while (fgets(buf, LINE_LEN, uc_file)) {
109 cur = get_id_from_word_line(buf);
111 fprintf(stderr, "Invalid line(%d):%s\n", line_number, buf);
118 /* Æó¤Ä¤á°Ê¹ß¤Î¹àÌÜ */
119 commit_uc(dict, cur, base);
125 /* ÍÑÎã¼½ñ¤ò¥Õ¥¡¥¤¥ë¤Ë½ñ¤½Ð¤¹ */
127 make_ucdict(FILE *uc_out, struct uc_dict *dict)
130 struct sparse_matrix *sm;
131 struct matrix_image *mi;
133 /* Á¹ÔÎó¤ËµÍ¤á¹þ¤à */
134 sm = anthy_sparse_matrix_new();
136 for (uc = dict->uc_head.next; uc; uc = uc->next) {
137 anthy_sparse_matrix_set(sm, uc->id[0], uc->id[1], 1, NULL);
140 anthy_sparse_matrix_make_matrix(sm);
141 /* Á¹ÔÎó¤Î¥¤¥á¡¼¥¸¤òºîÀ®¤·¤Æ¥Õ¥¡¥¤¥ë¤Ë½ñ¤½Ð¤¹ */
142 mi = anthy_matrix_image_new(sm);
143 for (i = 0; i < mi->size; i++) {
144 write_nl(uc_out, mi->image[i]);
147 printf("udic: %d use examples.\n", dict->nr_ucs);
149 printf("udic: no use examples.\n");