1 { Find a Japanese word, and convert to an English word }
2 function FindWord(var cur : integer; var cat : integer; var index : integer; var word : Str16) : boolean;
3 var i, j, s, l, fs, fl : integer;
12 while s < Length(Line) do
14 { Numbers or alphabets (as noun) }
15 if Line[s] < Chr($80) then
19 while (Chr($0) < Line[cur]) and (Line[cur] < Chr($80)) do
21 word := word + Line[cur];
36 if Copy(Line, s, l) = d[i, j] then
56 if Copy(Line, s, l) = m[i, j] then
68 { Japanese 'NI' (TO, IN, etc.) }
70 if (l > fl) and (Copy(Line, s, l) = '
\82É') then
78 { Janapese 'DE' (WITH) }
80 if (l > fl) and (Copy(Line, s, l) = '
\82Å') then
95 if Line[s] < Chr($80) then
105 { Parse a Janapese sentence, and convert to English words }
106 procedure ParseJ(var verb : Str16; var noun1 : Str16; var prepos : Str16; var noun2 : Str16);
107 var cur, cat, index, v, n1, n2 : integer;
118 if not FindWord(cur, cat, index, word) then
120 else if cat = 0 then { verb }
122 verb := word; v := index;
125 else if cat = 1 then { noun }
127 noun1 := word; n1 := index;
131 if not FindWord(cur, cat, index, word) then
133 else if cat = 0 then { verb }
135 verb := word; v := index;
138 else if cat = 1 then { noun }
140 noun2 := word; n2 := index;
142 else if cat = 2 then { prep }
145 noun2 := noun1; n2 := n1;
146 noun1 := ''; n1 := 0;
150 if not FindWord(cur, cat, index, word) then
152 if cat = 0 then {verb }
154 if (noun2 <> '') and (prepos = '') then
156 prepos := prep[index];
158 verb := word; v := index;
161 else if cat = 1 then { noun }
163 noun1 := word; n1 := index;
165 else if cat = 2 then { prep }
171 if not FindWord(cur, cat, index, word) then
173 else if cat = 0 then { verb }
176 prepos := prep[index];
177 verb := word; v := index;
178 if (v = 37{TIE}) and (n2 = 57{ROPE}) then { If 'ROPE NI X WO MUSUBU' }
180 { Convert to 'ROPE WO X NI MUSUBU' }
188 { Parse 'X TO IU'(SAY X) }
189 procedure ParseSayJ(var message : Str16);
193 i := Pos(d[31, 1]{ TO IU }, Line);
197 message := Copy(Line, 1, i - 1);
198 if (message = '
\83P
\83\89\83q
\83\88\83`
\83~') or (message = '
\83P
\83\89\83q
\83\88\83`
\83~') or (message = '
\82¯
\82ç
\82Ð
\82æ
\82¿
\82Ý') or (message = '
\82¯
\82ç
\82Ð
\82æ
\82¿
\82Ý') then
199 message := 'nepo egassap'
200 else if message = '
\82±
\82ñ
\82É
\82¿
\82Í' then
202 else if message = '
\82³
\82æ
\82¤
\82È
\82ç' then
206 { Convert full width numbers/alphabets to half width }
207 procedure FullToHalf;
211 while i < Length(Line) do
213 if Line[i] < Chr($80) then
217 c := Pos(Copy(Line, i, 2), '
\82O
\82P
\82Q
\82R
\82S
\82T
\82U
\82V
\82W
\82X
\82`
\82a
\82b
\82c
\82d
\82e
\82f
\82g
\82h
\82i
\82j
\82k
\82l
\82m
\82n
\82o
\82p
\82q
\82r
\82s
\82t
\82u
\82v
\82w
\82x
\82y
\82\81\82\82\82\83\82\84\82\85\82\86\82\87\82\88\82\89\82\8a\82\8b\82\8c\82\8d\82\8e\82\8f\82\90\82\91\82\92\82\93\82\94\82\95\82\96\82\97\82\98\82\99\82\9a') - 1;
218 if (c < 0) or (c mod 2 > 0) then
223 Insert('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'[Trunc(c / 2) + 1], Line, i);
230 { Translate a Japanese sentence to English }
232 var message, verb, noun1, prepos, noun2 : Str16;
234 if ('A' <= Line[1]) and (Line[1] <= 'z') then
238 if message <> '' then
240 Line := 'say ' + message;
245 ParseJ(verb, noun1, prepos, noun2);
256 Line := verb + ' ' + noun1 + ' ' + prepos + ' ' + noun2;
262 Line := verb + ' ' + noun1;