0
|
1 /*
|
|
2 * $Id: hindo.c,v 1.3 2001/06/14 18:15:55 ura Exp $
|
|
3 */
|
|
4
|
|
5 /*
|
|
6 * FreeWnn is a network-extensible Kana-to-Kanji conversion system.
|
|
7 * This file is part of FreeWnn.
|
|
8 *
|
|
9 * Copyright Kyoto University Research Institute for Mathematical Sciences
|
|
10 * 1987, 1988, 1989, 1990, 1991, 1992
|
|
11 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
|
|
12 * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992
|
|
13 * Copyright FreeWnn Project 1999, 2000
|
|
14 *
|
|
15 * Maintainer: FreeWnn Project <freewnn@tomo.gr.jp>
|
|
16 *
|
|
17 * This program is free software; you can redistribute it and/or modify
|
|
18 * it under the terms of the GNU General Public License as published by
|
|
19 * the Free Software Foundation; either version 2 of the License, or
|
|
20 * (at your option) any later version.
|
|
21 *
|
|
22 * This program is distributed in the hope that it will be useful,
|
|
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
25 * GNU General Public License for more details.
|
|
26 *
|
|
27 * You should have received a copy of the GNU General Public License
|
|
28 * along with this program; if not, write to the Free Software
|
|
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
30 */
|
|
31
|
|
32 /*
|
|
33 修正 9/1/89
|
|
34
|
|
35 a=実頻度, b=仮頻度(共に非負整数)のとき
|
|
36
|
|
37 b=[a÷x]+2(x−1) where x=[( sqrt(1+2a)+1 )÷2]
|
|
38 (計算結果が126を越えた場合は126とする。)
|
|
39
|
|
40 (min)a=(b−2y)(y+1) where y=[b÷4]
|
|
41 (mid)a=(b−2y)(y+1)+[y÷2] where y=[b÷4]
|
|
42 (b≦126とする。)
|
|
43
|
|
44 ここで[ ]はガウス記号
|
|
45 bを与えてのaの推測値には幅があり、(min)aとはその最小値、
|
|
46 (mid)aはその中間値
|
|
47 b≦4 なら、(min)a=(mid)a=b
|
|
48
|
|
49 仮頻度がbのとき、頻度の更新の確率は 1 / ([b÷4]+1)
|
|
50 但し b=0の時は、頻度更新確率 0
|
|
51
|
|
52
|
|
53 a == -1 <==> b == 0x7f = 127;
|
|
54 この時、このエントリーは、変換に決して用いられない
|
|
55 (コメントアウトされている)ことを表す。
|
|
56 9/1/89 H.T.
|
|
57 */
|
|
58
|
|
59 /** 整数引数の平方根関数。但し引数<0の時のエラーチェックはなし(0を返す)。*/
|
|
60 static int
|
|
61 isqrt (i)
|
|
62 int i;
|
|
63 {
|
|
64 register int a, b;
|
|
65
|
|
66 if (i <= 0)
|
|
67 return (0);
|
|
68 for (a = i, b = 1; b <<= 1, a >>= 2;);
|
|
69 while ((a = i / b) < b)
|
|
70 b = (b + a) >> 1;
|
|
71 return (b);
|
|
72 }
|
|
73
|
|
74 /** 実頻度a→仮頻度b */
|
|
75 int
|
|
76 asshuku (hin)
|
|
77 int hin;
|
|
78 {
|
|
79 register int c;
|
|
80
|
|
81 if (hin == -1)
|
|
82 return (127);
|
|
83 if (hin <= 4)
|
|
84 return (hin);
|
|
85 /* 大半は頻度0と想定してのスピードアップ。motoni1,2でも同じ */
|
|
86
|
|
87 c = (isqrt ((hin <<= 1) + 1) + 1) & ~1;
|
|
88 c += hin / c - 2;
|
|
89 return (c < 126 ? c : 126);
|
|
90 }
|
|
91
|
|
92 /** 仮頻度b→実頻度(min)a */
|
|
93 /*
|
|
94 int
|
|
95 motoni1(hin)
|
|
96 int hin;
|
|
97 {
|
|
98 register int c;
|
|
99
|
|
100 if(hin == 127) return(-1);
|
|
101 if(hin <= 4) return(hin);
|
|
102 c = hin >> 2;
|
|
103 return( (hin - (c << 1)) * (c + 1) );
|
|
104 }
|
|
105 */
|
|
106
|
|
107 /** 仮頻度b→実頻度(mid)a */
|
|
108 int
|
|
109 motoni2 (hin)
|
|
110 int hin;
|
|
111 {
|
|
112 register int c;
|
|
113
|
|
114 if (hin == 127)
|
|
115 return (-1);
|
|
116 if (hin <= 4)
|
|
117 return (hin);
|
|
118 c = hin >> 2;
|
|
119 return ((hin - (c << 1)) * (c + 1) + (c >> 1));
|
|
120 }
|