(linenum→info "unix/slp.c:2238")

NOKUBI Takatsugu

Bio:Debian developer
URL:http://www.daionet.gr.jp/~knok/trac
Location:日本、東京

2008-02-28

_ anthy/9100e/src-main/context.c:260-265

  260: void
  261: anthy_init_contexts(void)
  262: {
  263:   context_ator = anthy_create_allocator(sizeof(struct anthy_context),
  264:                                         context_dtor);
  265: }

コンテキストの初期化?

_ anthy/9100e/src-main/context.c:556-609

  556: void
  557: anthy_print_candidate(struct cand_ent *ce)
  558: {
  559:   int mod = (ce->score % 1000);
  560:   int seg_score = 0;
  561: 
  562:   if (ce->mw) {
  563:     seg_score = ce->mw->score;
  564:   }
  565:   anthy_putxstr(&ce->str);
  566:   printf(":(");
  567:   /*if (ce->nr_words == 1) {printf("%d,", ce->elm[0].id);    }*/
  568:   if (ce->flag & CEF_OCHAIRE) {
  569:     putchar('o');
  570:   }
  571:   if (ce->flag & CEF_SINGLEWORD) {
  572:     putchar('1');
  573:   }
  574:   if (ce->flag & CEF_GUESS) {
  575:     putchar('g');
  576:   }
  577:   if (ce->flag & (CEF_KATAKANA | CEF_HIRAGANA)) {
  578:     putchar('N');
  579:   }
  580:   if (ce->flag & CEF_USEDICT) {
  581:     putchar('U');
  582:   }
  583:   if (ce->flag & CEF_CONTEXT) {
  584:     putchar('C');
  585:   }
  586:   printf(",%d,", seg_score);
  587: 
  588:     
  589:   if (ce->mw) {
  590:     printf("%s,%d", anthy_seg_class_sym(ce->mw->seg_class),
  591:            ce->mw->struct_score);
  592:   } else {
  593:     putchar('-');
  594:   }
  595:   printf(")");
  596: 
  597:   if (ce->score >= 1000) {
  598:     printf("%d,", ce->score/1000);
  599:     if (mod < 100) {
  600:       printf("0");
  601:     }
  602:     if (mod < 10) {
  603:       printf("0");
  604:     }
  605:     printf("%d ", mod);
  606:   } else {
  607:     printf("%d ", ce->score);
  608:   }
  609: }

表示形式は以下のような感じ:

このあたり(この辺:(1,1000,N,59892)183,420 ,このあたり:(1N,1000,N,59892)177,805 ,この辺り:(1,1000,N,59892)177,571 ,コノアタリ:(N,0,-)1 ,):

_ anthy/9100e/src-main/context.c:682-686

  682: void
  683: anthy_init_personality(void)
  684: {
  685:   current_personality = NULL;
  686: }

personality(おそらく個人向け変換履歴情報)の初期化。

~/.anthy/record[12]_default

_ anthy/9100e/src-ordering/infosort.c:142-146

  142: void
  143: anthy_infosort_init(void)
  144: {
  145:   cand_info_array = anthy_file_dic_get_section("cand_info");
  146: }

候補の順序付け情報を取り扱うようだ(要確認)

_ anthy/9100e/src-ordering/relation.c:415-437

  415: void
  416: anthy_relation_init(void)
  417: {
  418:   corpus_info.corpus_array = anthy_file_dic_get_section("corpus_array");
  419:   corpus_info.corpus_bucket = anthy_file_dic_get_section("corpus_bucket");
  420:   if (!corpus_info.corpus_array ||
  421:       !corpus_info.corpus_array) {
  422:     return ;
  423:   }
  424:   corpus_info.array_size = ntohl(((int *)corpus_info.corpus_array)[1]);
  425:   corpus_info.bucket_size = ntohl(((int *)corpus_info.corpus_bucket)[1]);
  426:   corpus_info.array = &(((int *)corpus_info.corpus_array)[16]);
  427:   corpus_info.bucket = &(((int *)corpus_info.corpus_bucket)[16]);
  428:   /*
  429:   {
  430:     int i;
  431:     for (i = 0; i < corpus_info.array_size; i++) {
  432:       int v = ntohl(corpus_info.array[i * 2]);
  433:       printf("%d: %d %d\n", i, v, v & CORPUS_KEY_MASK);
  434:     }
  435:   }
  436:   */
  437: }

コーパスの関連性情報を取り扱うらしい?

_ anthy/9100e/src-splitter/splitter.c:276-323

  276: int
  277: anthy_init_splitter(void)
  278: {
  279:   /* デバッグプリントの設定 */
  280:   char *en = getenv("ANTHY_ENABLE_DEBUG_PRINT");
  281:   char *dis = getenv("ANTHY_DISABLE_DEBUG_PRINT");
  282:   splitter_debug_flags = SPLITTER_DEBUG_NONE;
  283:   if (!dis && en && strlen(en)) {
  284:     char *fs = getenv("ANTHY_SPLITTER_PRINT");
  285:     if (fs) {
  286:       if (strchr(fs, 'w')) {
  287:         splitter_debug_flags |= SPLITTER_DEBUG_WL;
  288:       }
  289:       if (strchr(fs, 'm')) {
  290:         splitter_debug_flags |= SPLITTER_DEBUG_MW;
  291:       }
  292:       if (strchr(fs, 'l')) {
  293:         splitter_debug_flags |= SPLITTER_DEBUG_LN;
  294:       }
  295:       if (strchr(fs, 'i')) {
  296:         splitter_debug_flags |= SPLITTER_DEBUG_ID;
  297:       }
  298:       if (strchr(fs, 'c')) {
  299:         splitter_debug_flags |= SPLITTER_DEBUG_CAND;
  300:       }
  301:     }
  302:   }
  303:   /* 付属語グラフの初期化 */
  304:   if (anthy_init_depword_tab()) {
  305:     anthy_log(0, "Failed to init dependent word table.\n");
  306:     return -1;
  307:   }
  308:   /**/
  309:   anthy_wtype_noun = anthy_init_wtype_by_name("名詞35");
  310:   anthy_wtype_name_noun = anthy_init_wtype_by_name("人名");
  311:   anthy_wtype_num_noun = anthy_init_wtype_by_name("数詞");
  312:   anthy_wtype_a_tail_of_v_renyou = anthy_init_wtype_by_name("形容詞化接尾語");
  313:   anthy_wtype_v_renyou = anthy_init_wtype_by_name("動詞連用形");
  314:   anthy_wtype_noun_tail = anthy_init_wtype_by_name("名詞化接尾語");
  315:   anthy_wtype_prefix = anthy_init_wtype_by_name("名詞接頭辞");
  316:   anthy_wtype_num_prefix = anthy_init_wtype_by_name("数接頭辞");
  317:   anthy_wtype_num_postfix = anthy_init_wtype_by_name("数接尾辞");
  318:   anthy_wtype_name_postfix = anthy_init_wtype_by_name("人名接尾辞");
  319:   anthy_wtype_sv_postfix = anthy_init_wtype_by_name("サ変接尾辞");
  320:   anthy_wtype_n1 = anthy_init_wtype_by_name("数詞1");
  321:   anthy_wtype_n10 = anthy_init_wtype_by_name("数詞10");
  322:   return 0;
  323: }

splitterサブシステムの初期化

_ anthy/9100e/src-util/agent.c:1051-1068

 1051: static void
 1052: main_loop(void)
 1053: {
 1054:   struct anthy_input_context* ictx;
 1055:   struct command* cmd;
 1056: 
 1057:   while (1) {
 1058:     cmd = read_command();
 1059:     if (!cmd) 
 1060:       break;
 1061:     ictx = get_current_input_context();
 1062: 
 1063:     dispatch_command(ictx, cmd);
 1064:     fflush(stdout);
 1065: 
 1066:     free_command(cmd);
 1067:   }
 1068: }

anthy-agentのメインループ処理

_ anthy/9100e/src-util/agent.c:1121-1153

 1121: int
 1122: main(int argc, char **argv)
 1123: {
 1124:   parse_args(argc, argv);
 1125:   if (anthy_input_init()) {
 1126:     printf("Failed to init anthy\n");
 1127:     exit(0);
 1128:   }
 1129:   if (anonymous) {
 1130:     anthy_input_set_personality("");
 1131:   } else if (personality) {
 1132:     anthy_input_set_personality(personality);
 1133:   }
 1134: 
 1135:   if (egg) {
 1136:     egg_main();
 1137:     anthy_quit();
 1138:   } else {
 1139:     config = anthy_input_create_config();
 1140:     conn = (struct connection*) malloc(sizeof(struct connection));
 1141:     conn->rbuf = NULL;
 1142:     conn->n_rbuf = 0;
 1143:     conn->s_rbuf = 0;
 1144:     conn->rfd = 0;
 1145:     conn->wbuf = NULL;
 1146:     conn->n_wbuf = 0;
 1147:     conn->s_wbuf = 0;
 1148:     conn->wfd = 1;
 1149: 
 1150:     main_loop();
 1151:   }
 1152:   return 0;
 1153: }

anthy-agentのmain

_ anthy/9100e/src-util/agent.c:1125-1125

 1125:   if (anthy_input_init()) {

各種サブシステムなどの初期化

* anthy_splitter_init http://linenum.info/notes/122 splitterサブシステム初期化
* anthy_init_dic http://linenum.info/notes/121 辞書サブシステム初期化
* anthy_init_context http://linenum.info/notes/123
* anthy_init_personality http://linenum.inf

_ anthy/9100e/src-worddic/word_dic.c:736-761

  736: int
  737: anthy_init_dic(void)
  738: {
  739:   if (dic_init_count) {
  740:     dic_init_count ++;
  741:     return 0;
  742:   }
  743:   if (anthy_init_diclib() == -1) {
  744:     return -1;
  745:   }
  746: 
  747:   anthy_init_wtypes();
  748:   anthy_init_mem_dic();
  749:   anthy_init_record();
  750:   anthy_init_ext_ent();
  751:   anthy_init_features();
  752: 
  753:   anthy_init_word_dic();
  754:   master_dic_file = anthy_create_word_dic();
  755:   if (!master_dic_file) {
  756:     anthy_log(0, "Failed to create file dic.\n");
  757:     return -1;
  758:   }
  759:   dic_init_count ++;
  760:   return 0;
  761: }

辞書サブシステム初期化

_ anthy/9100e/src-util/agent.c:1140-1148

 1140:     conn = (struct connection*) malloc(sizeof(struct connection));
 1141:     conn->rbuf = NULL;
 1142:     conn->n_rbuf = 0;
 1143:     conn->s_rbuf = 0;
 1144:     conn->rfd = 0;
 1145:     conn->wbuf = NULL;
 1146:     conn->n_wbuf = 0;
 1147:     conn->s_wbuf = 0;
 1148:     conn->wfd = 1;

struct connectionの実体をここで生成

_ anthy/9100e/src-worddic/wtype.c:45-48

   45: /* 辞書中の品詞の名前を品詞に変換するテーブル */
   46: static struct wttable wt_name_tab[]= {
   47: #include "wtab.h"
   48: };

cannadic形式の品詞定義文字列と品詞情報を対応させたテーブル。 wtab.hによって定義される。

{"#T",POS_NOUN,COS_NONE,SCOS_T35,CC_NONE,CT_NONE,WF_INDEP   /* "名詞(語幹,格助接続)"*/},
{"#B5",POS_V,COS_NONE,SCOS_NONE,CC_B5,CT_HEAD

_ anthy/9100e/src-worddic/wtab.h:1-6

    1: /*
    2:  * 前半は cannadic-0.90からコピーしてきた。
    3:  * 後の方にAnthy独自の品詞が追加してある。
    4:  */
    5: /* リニアサーチで速く見付かるようによく使う品詞を先頭で定義する */
    6: {"#T",POS_NOUN,COS_NONE,SCOS_T35,CC_NONE,CT_NONE,WF_INDEP   /* "名詞(語幹,格助接続)"*/},

struct wttableとして内容が定義される。wtype.c中でincludeされる。

_ anthy/9100e/anthy/wtype.h:19-39

   19: /*品詞 Part Of Speech */
   20: #define POS_NONE 0
   21: #define POS_NOUN 1
   22: #define POS_PRT 2
   23: #define POS_XV 3
   24: #define POS_V 4
   25: #define POS_A 5
   26: #define POS_AJV 6
   27: #define POS_AV 7
   28: #define POS_ME 8
   29: #define POS_CONJ 9
   30: #define POS_IJ 10
   31: #define POS_PRE 11
   32: #define POS_SUC 12
   33: #define POS_TANKANJI 13
   34: #define POS_N2T 14
   35: #define POS_D2KY 15
   36: #define POS_NUMBER 16
   37: #define POS_INVAL 17
   38: #define POS_OPEN 18
   39: #define POS_CLOSE 19

品詞のマクロ定義

_ anthy/9100e/anthy/wtype.h:76-90

   76: /* 副品詞 Class Of Speech */
   77: #define COS_NONE 0
   78: /* 地名 */
   79: #define COS_CN 1
   80: /* 数詞 */
   81: #define COS_NN 2
   82: /* 人名 */
   83: #define COS_JN 3
   84: /* 団体名 */
   85: #define COS_KK 4
   86: /* 一般接頭辞・接尾辞 */
   87: #define COS_SUFFIX 5
   88: /* サ変の接尾辞 */
   89: #define COS_SVSUFFIX 6
   90: /**/

副品詞のマクロ定義

_ anthy/9100e/anthy/wtype.h:92-150

   92: /* 副々品詞 Sub Class Of Speech*/
   93: #define SCOS_NONE 0
   94: #define SCOS_FAMNAME 1
   95: #define SCOS_FSTNAME 2
   96: #define SCOS_T0 10
   97: #define SCOS_T2 12
   98: #define SCOS_T3 13
   99: #define SCOS_T4 14
  100: #define SCOS_T5 15
  101: #define SCOS_T7 17
  102: #define SCOS_T8 18
  103: #define SCOS_T9 19
  104: #define SCOS_T10 20
  105: #define SCOS_T12 22
  106: #define SCOS_T13 23
  107: #define SCOS_T14 24
  108: #define SCOS_T15 25
  109: #define SCOS_T17 27
  110: #define SCOS_T18 28
  111: #define SCOS_T19 29
  112: #define SCOS_T20 30
  113: #define SCOS_T22 32
  114: #define SCOS_T23 33
  115: #define SCOS_T24 34
  116: #define SCOS_T25 35
  117: #define SCOS_T27 37
  118: #define SCOS_T28 38
  119: #define SCOS_T29 39
  120: #define SCOS_T30 40
  121: #define SCOS_T32 42
  122: #define SCOS_T33 43
  123: #define SCOS_T34 44
  124: #define SCOS_T35 45
  125: #define SCOS_T37 47
  126: #define SCOS_T38 48
  127: #define SCOS_T39 49
  128: #define SCOS_T40 50
  129: #define SCOS_F0 60
  130: #define SCOS_F1 61
  131: #define SCOS_F2 62
  132: #define SCOS_F3 63
  133: #define SCOS_F4 64
  134: #define SCOS_F5 65
  135: #define SCOS_F6 66
  136: #define SCOS_F7 67
  137: #define SCOS_F8 68
  138: #define SCOS_F9 69
  139: #define SCOS_F10 70
  140: #define SCOS_F11 71
  141: #define SCOS_F12 72
  142: #define SCOS_F13 73
  143: #define SCOS_F14 74
  144: #define SCOS_A0 80
  145: #define SCOS_A1 81
  146: #define SCOS_N1 90
  147: #define SCOS_N10 91
  148: #define SCOS_N100 92
  149: #define SCOS_N1000 93
  150: #define SCOS_N10000 94

副副品詞のマクロ定義

_ anthy/9100e/anthy/wtype.h:52-74

   52: /* 活用クラス Conjugate Class */
   53: #define CC_NONE 0
   54: #define CC_K5 1
   55: #define CC_C5 2
   56: #define CC_G5 3
   57: #define CC_S5 4
   58: #define CC_T5 5
   59: #define CC_N5 6
   60: #define CC_M5 7
   61: #define CC_B5 8
   62: #define CC_R5 9
   63: #define CC_L5 10
   64: #define CC_W5 11
   65: #define CC_U5 12
   66: #define CC_KS1 13
   67: #define CC_RV 14
   68: #define CC_KV 15
   69: #define CC_SV 16
   70: #define CC_ZV 17
   71: #define CC_A 18
   72: #define CC_A_U 19
   73: #define CC_AJV 20
   74: #define CC_SRV 21

活用クラスのマクロ定義

_ anthy/9100e/anthy/wtype.h:41-50

   41: /* 活用形 Conjugate Type */
   42: #define CT_NONE 0
   43: #define CT_SYUSI 1
   44: #define CT_MIZEN 2
   45: #define CT_RENYOU 3
   46: #define CT_RENTAI 4
   47: #define CT_KATEI 5
   48: #define CT_MEIREI 6
   49: #define CT_HEAD 7
   50: #define CT_MEISIKA 8

活用形のマクロ定義

_ anthy/9100e/anthy/wtype.h:152-161

  152: /* FLAGS */
  153: #define WF_NONE 0
  154: /* この動詞は連体詞が名詞化する */
  155: #define WF_MEISI 1
  156: /* サ変名詞 */
  157: #define WF_SV 2
  158: /* 自立語、文節のコアとなる */
  159: #define WF_INDEP 4
  160: /* 形容動詞 */
  161: #define WF_AJV 8

フラグのマクロ定義

_ anthy/9100e/src-worddic/ptab.h:1-3

    1: /* POS(Part of Speech) table */
    2: {"名詞",POS_NOUN,COS_NONE,SCOS_NONE,CC_NONE,CT_NONE,WF_INDEP},
    3: {"名詞0",POS_NOUN,COS_NONE,SCOS_T0,CC_NONE,CT_NONE,WF_INDEP|WF_SV},

品詞と対応するマクロ定義値を定める。wtype.cにてstruct wttable型で定義。

  • POS_*: 品詞
  • COS_*: 副品詞
  • SCOS_*: [副副品詞](http://linenum.info/p/anthy/9100e/a

_ anthy/9100e/src-worddic/wtype.c:40-43

   40: /* 品詞の日本語の名前を品詞に変換するテーブル */
   41: static struct wttable pos_name_tab[]= {
   42: #include "ptab.h"
   43: };

文字列の品詞名と品詞情報の対応テーブル

ptab.hによって定義される。