001: /**
002: *******************************************************************************
003: * Copyright (C) 2001-2004, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: */package com.ibm.icu.dev.test.translit;
007:
008: import com.ibm.icu.text.*;
009: import com.ibm.icu.impl.Utility;
010: import java.util.*;
011:
012: /**
013: * @test
014: * @summary Test the Latin-Jamo transliterator
015: */
016: public class JamoTest extends TransliteratorTest {
017:
018: private static final char SEP = '\'';
019:
020: public static void main(String[] args) throws Exception {
021: new JamoTest().run(args);
022: }
023:
024: public void TestJamo() {
025: Transliterator latinJamo = Transliterator
026: .getInstance("Latin-Jamo");
027: Transliterator jamoLatin = latinJamo.getInverse();
028:
029: String[] CASE = {
030: // Column 1 is the latin text L1 to be fed to Latin-Jamo
031: // to yield output J.
032:
033: // Column 2 is expected value of J. J is fed to
034: // Jamo-Latin to yield output L2.
035:
036: // Column 3 is expected value of L2. If the expected
037: // value of L2 is L1, then L2 is null.
038: "bab", "(Bi)(A)(Bf)", null, "babb",
039: "(Bi)(A)(Bf)(Bi)(EU)", "bab" + SEP + "beu", "babbba",
040: "(Bi)(A)(Bf)(BB)(A)", null, "bagg", "(Bi)(A)(GGf)",
041: null, "baggga", "(Bi)(A)(GGf)(Gi)(A)", null,
042: "bag" + SEP + "gga", "(Bi)(A)(Gf)(GGi)(A)", null,
043: "kabsa", "(Ki)(A)(Bf)(Si)(A)", null,
044: "kabska",
045: "(Ki)(A)(BS)(Ki)(A)",
046: null,
047: "gabsbka",
048: "(Gi)(A)(BS)(Bi)(EU)(Ki)(A)",
049: "gabsbeuka", // not (Kf)
050: "gga", "(GGi)(A)", null, "bsa", "(Bi)(EU)(Si)(A)",
051: "beusa", "agg", "(IEUNG)(A)(GGf)", null, "agga",
052: "(IEUNG)(A)(GGi)(A)", null, "la", "(R)(A)", "ra", "bs",
053: "(Bi)(EU)(Sf)", "beus", "kalgga", "(Ki)(A)(L)(GGi)(A)",
054: null,
055:
056: // 'r' in a final position is treated like 'l'
057: "karka", "(Ki)(A)(L)(Ki)(A)", "kalka", };
058:
059: for (int i = 0; i < CASE.length; i += 3) {
060: String jamo = nameToJamo(CASE[i + 1]);
061: if (CASE[i + 2] == null) {
062: expect(latinJamo, CASE[i], jamo, jamoLatin);
063: } else {
064: // Handle case where round-trip is expected to fail
065: expect(latinJamo, CASE[i], jamo);
066: expect(jamoLatin, jamo, CASE[i + 2]);
067: }
068: }
069: }
070:
071: /**
072: * These are problems turned up by the Hangul-Jamo;Jamo-Latin
073: * round trip test.
074: */
075: public void TestRoundTrip() {
076: String HANGUL[] = { "\uAC03\uC2F8", "\uC544\uC5B4" };
077:
078: Transliterator latinJamo = Transliterator
079: .getInstance("Latin-Jamo");
080: Transliterator jamoLatin = latinJamo.getInverse();
081: Transliterator jamoHangul = Transliterator.getInstance("NFC");
082: Transliterator hangulJamo = Transliterator.getInstance("NFD");
083:
084: StringBuffer buf = new StringBuffer();
085: for (int i = 0; i < HANGUL.length; ++i) {
086: String hangul = HANGUL[i];
087: String jamo = hangulJamo.transliterate(hangul);
088: String latin = jamoLatin.transliterate(jamo);
089: String jamo2 = latinJamo.transliterate(latin);
090: String hangul2 = jamoHangul.transliterate(jamo2);
091: buf.setLength(0);
092: buf.append(hangul + " => " + jamoToName(jamo) + " => "
093: + latin + " => " + jamoToName(jamo2) + " => "
094: + hangul2);
095: if (!hangul.equals(hangul2)) {
096: errln("FAIL: " + Utility.escape(buf.toString()));
097: } else {
098: logln(Utility.escape(buf.toString()));
099: }
100: }
101: }
102:
103: /**
104: * Test various step-at-a-time transformation of hangul to jamo to
105: * latin and back.
106: */
107: public void TestPiecemeal() {
108: String hangul = "\uBC0F";
109: String jamo = nameToJamo("(Mi)(I)(Cf)");
110: String latin = "mic";
111:
112: Transliterator t = null;
113:
114: t = Transliterator.getInstance("NFD"); // was Hangul-Jamo
115: expect(t, hangul, jamo);
116:
117: t = Transliterator.getInstance("NFC"); // was Jamo-Hangul
118: expect(t, jamo, hangul);
119:
120: t = Transliterator.getInstance("Latin-Jamo");
121: expect(t, latin, jamo);
122:
123: t = Transliterator.getInstance("Jamo-Latin");
124: expect(t, jamo, latin);
125:
126: t = Transliterator.getInstance("Hangul-Latin");
127: expect(t, hangul, latin);
128:
129: t = Transliterator.getInstance("Latin-Hangul");
130: expect(t, latin, hangul);
131:
132: t = Transliterator.getInstance("Hangul-Latin; Latin-Jamo");
133: expect(t, hangul, jamo);
134:
135: t = Transliterator.getInstance("Jamo-Latin; Latin-Hangul");
136: expect(t, jamo, hangul);
137:
138: t = Transliterator.getInstance("Hangul-Latin; Latin-Hangul");
139: expect(t, hangul, hangul);
140: }
141:
142: public void TestRealText() {
143: Transliterator latinJamo = Transliterator
144: .getInstance("Latin-Jamo");
145: Transliterator jamoLatin = latinJamo.getInverse();
146: Transliterator jamoHangul = Transliterator.getInstance("NFC");
147: Transliterator hangulJamo = Transliterator.getInstance("NFD");
148: //Transliterator rt = new CompoundTransliterator(new Transliterator[] {
149: // hangulJamo, jamoLatin, latinJamo, jamoHangul });
150: Transliterator rt = Transliterator
151: .getInstance("NFD;Jamo-Latin;Latin-Jamo;NFC");
152:
153: int pos = 0;
154: StringBuffer buf = new StringBuffer();
155: int total = 0;
156: int errors = 0;
157: while (pos < WHAT_IS_UNICODE.length()) {
158: int space = WHAT_IS_UNICODE.indexOf(' ', pos + 1);
159: if (space < 0) {
160: space = WHAT_IS_UNICODE.length();
161: }
162: if (pos < space) {
163: ++total;
164: String hangul = WHAT_IS_UNICODE.substring(pos, space);
165: String hangulX = rt.transliterate(hangul);
166: if (!hangul.equals(hangulX)) {
167: ++errors;
168: String jamo = hangulJamo.transliterate(hangul);
169: String latin = jamoLatin.transliterate(jamo);
170: String jamo2 = latinJamo.transliterate(latin);
171: String hangul2 = jamoHangul.transliterate(jamo2);
172: if (hangul.equals(hangul2)) {
173: buf.setLength(0);
174: buf
175: .append("FAIL (Compound transliterator problem): ");
176: buf.append(hangul + " => " + jamoToName(jamo)
177: + " => " + latin + " => "
178: + jamoToName(jamo2) + " => " + hangul2
179: + "; but " + hangul + " =cpd=> "
180: + jamoToName(hangulX));
181: errln(Utility.escape(buf.toString()));
182: } else if (jamo.equals(jamo2)) {
183: buf.setLength(0);
184: buf.append("FAIL (Jamo<>Hangul problem): ");
185: if (!hangul2.equals(hangulX)) {
186: buf.append("(Weird: " + hangulX + " != "
187: + hangul2 + ")");
188: }
189: buf.append(hangul + " => " + jamoToName(jamo)
190: + " => " + latin + " => "
191: + jamoToName(jamo2) + " => " + hangul2);
192: errln(Utility.escape(buf.toString()));
193: } else {
194: buf.setLength(0);
195: buf.append("FAIL: ");
196: if (!hangul2.equals(hangulX)) {
197: buf.append("(Weird: " + hangulX + " != "
198: + hangul2 + ")");
199: }
200: // The Hangul-Jamo conversion is not usually the
201: // bug here, so we hide it from display.
202: // Uncomment lines to see the Hangul.
203: buf.append(//hangul + " => " +
204: jamoToName(jamo) + " => " + latin
205: + " => " + jamoToName(jamo2)
206: //+ " => " + hangul2
207: );
208: errln(Utility.escape(buf.toString()));
209: }
210: }
211: }
212: pos = space + 1;
213: }
214: if (errors != 0) {
215: errln("Test word failures: " + errors + " out of " + total);
216: } else {
217: logln("All " + total + " test words passed");
218: }
219: }
220:
221: // Test text taken from the Unicode web site
222: static final String WHAT_IS_UNICODE =
223:
224: "\uc720\ub2c8\ucf54\ub4dc\uc5d0 \ub300\ud574 ? "
225: +
226:
227: "\uc5b4\ub5a4 \ud50c\ub7ab\ud3fc, \uc5b4\ub5a4 "
228: + "\ud504\ub85c\uadf8\ub7a8, \uc5b4\ub5a4 \uc5b8\uc5b4\uc5d0\ub3c4 "
229: + "\uc0c1\uad00\uc5c6\uc774 \uc720\ub2c8\ucf54\ub4dc\ub294 \ubaa8\ub4e0 "
230: + "\ubb38\uc790\uc5d0 \ub300\ud574 \uace0\uc720 \ubc88\ud638\ub97c "
231: + "\uc81c\uacf5\ud569\ub2c8\ub2e4. "
232: +
233:
234: "\uae30\ubcf8\uc801\uc73c\ub85c \ucef4\ud4e8\ud130\ub294 "
235: + "\uc22b\uc790\ub9cc \ucc98\ub9ac\ud569\ub2c8\ub2e4. \uae00\uc790\ub098 "
236: + "\ub2e4\ub978 \ubb38\uc790\uc5d0\ub3c4 \uc22b\uc790\ub97c "
237: + "\uc9c0\uc815\ud558\uc5ec "
238: + "\uc800\uc7a5\ud569\ub2c8\ub2e4. \uc720\ub2c8\ucf54\ub4dc\uac00 "
239: + "\uac1c\ubc1c\ub418\uae30 \uc804\uc5d0\ub294 \uc774\ub7ec\ud55c "
240: + "\uc22b\uc790\ub97c \uc9c0\uc815\ud558\uae30 \uc704\ud574 \uc218\ubc31 "
241: + "\uac00\uc9c0\uc758 \ub2e4\ub978 \uae30\ud638\ud654 "
242: + "\uc2dc\uc2a4\ud15c\uc744 "
243: + "\uc0ac\uc6a9\ud588\uc2b5\ub2c8\ub2e4. \ub2e8\uc77c \uae30\ud638\ud654 "
244: + "\ubc29\ubc95\uc73c\ub85c\ub294 \ubaa8\ub4e0 \ubb38\uc790\ub97c "
245: + "\ud3ec\ud568\ud560 \uc218 \uc5c6\uc5c8\uc2b5\ub2c8\ub2e4. \uc608\ub97c "
246: + "\ub4e4\uc5b4 \uc720\ub7fd \uc5f0\ud569\uc5d0\uc11c\ub9cc "
247: + "\ubcf4\ub354\ub77c\ub3c4 \ubaa8\ub4e0 \uac01 \ub098\ub77c\ubcc4 "
248: + "\uc5b8\uc5b4\ub97c \ucc98\ub9ac\ud558\ub824\uba74 \uc5ec\ub7ec "
249: + "\uac1c\uc758 \ub2e4\ub978 \uae30\ud638\ud654 \ubc29\ubc95\uc774 "
250: + "\ud544\uc694\ud569\ub2c8\ub2e4. \uc601\uc5b4\uc640 \uac19\uc740 "
251: + "\ub2e8\uc77c \uc5b8\uc5b4\uc758 \uacbd\uc6b0\ub3c4 "
252: + "\uacf5\ud1b5\uc801\uc73c\ub85c \uc0ac\uc6a9\ub418\ub294 \ubaa8\ub4e0 "
253: + "\uae00\uc790, \ubb38\uc7a5 \ubd80\ud638 \ubc0f "
254: + "\ud14c\ud06c\ub2c8\uceec \uae30\ud638\uc5d0 \ub9de\ub294 \ub2e8\uc77c "
255: + "\uae30\ud638\ud654 \ubc29\ubc95\uc744 \uac16\uace0 \uc788\uc9c0 "
256: + "\ubabb\ud558\uc600\uc2b5\ub2c8\ub2e4. "
257: +
258:
259: "\uc774\ub7ec\ud55c \uae30\ud638\ud654 \uc2dc\uc2a4\ud15c\uc740 "
260: + "\ub610\ud55c \ub2e4\ub978 \uae30\ud638\ud654 \uc2dc\uc2a4\ud15c\uacfc "
261: + "\ucda9\ub3cc\ud569\ub2c8\ub2e4. \uc989 \ub450 \uac00\uc9c0 "
262: + "\uae30\ud638\ud654 \ubc29\ubc95\uc774 \ub450 \uac1c\uc758 \ub2e4\ub978 "
263: + "\ubb38\uc790\uc5d0 \ub300\ud574 \uac19\uc740 \ubc88\ud638\ub97c "
264: + "\uc0ac\uc6a9\ud558\uac70\ub098 \uac19\uc740 \ubb38\uc790\uc5d0 "
265: + "\ub300\ud574 \ub2e4\ub978 \ubc88\ud638\ub97c \uc0ac\uc6a9\ud560 \uc218 "
266: + "\uc788\uc2b5\ub2c8\ub2e4. \uc8fc\uc5b4\uc9c4 \ubaa8\ub4e0 "
267: + "\ucef4\ud4e8\ud130(\ud2b9\ud788 \uc11c\ubc84)\ub294 \uc11c\ub85c "
268: + "\ub2e4\ub978 \uc5ec\ub7ec \uac00\uc9c0 \uae30\ud638\ud654 "
269: + "\ubc29\ubc95\uc744 \uc9c0\uc6d0\ud574\uc57c "
270: + "\ud569\ub2c8\ub2e4. \uadf8\ub7ec\ub098, \ub370\uc774\ud130\ub97c "
271: + "\uc11c\ub85c \ub2e4\ub978 \uae30\ud638\ud654 \ubc29\ubc95\uc774\ub098 "
272: + "\ud50c\ub7ab\ud3fc \uac04\uc5d0 \uc804\ub2ec\ud560 \ub54c\ub9c8\ub2e4 "
273: + "\uadf8 \ub370\uc774\ud130\ub294 \ud56d\uc0c1 \uc190\uc0c1\uc758 "
274: + "\uc704\ud5d8\uc744 \uacaa\uac8c \ub429\ub2c8\ub2e4. "
275: +
276:
277: "\uc720\ub2c8\ucf54\ub4dc\ub85c \ubaa8\ub4e0 \uac83\uc744 "
278: + "\ud574\uacb0\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4! "
279: + "\uc720\ub2c8\ucf54\ub4dc\ub294 \uc0ac\uc6a9 \uc911\uc778 "
280: + "\ud50c\ub7ab\ud3fc, \ud504\ub85c\uadf8\ub7a8, \uc5b8\uc5b4\uc5d0 "
281: + "\uad00\uacc4\uc5c6\uc774 \ubb38\uc790\ub9c8\ub2e4 \uace0\uc720\ud55c "
282: + "\uc22b\uc790\ub97c "
283: + "\uc81c\uacf5\ud569\ub2c8\ub2e4. \uc720\ub2c8\ucf54\ub4dc "
284: + "\ud45c\uc900\uc740 "
285: + // "Apple, HP, IBM, JustSystem, Microsoft, Oracle, SAP, " +
286: // "Sun, Sybase, Unisys " +
287: "\ubc0f \uae30\ud0c0 \uc5ec\ub7ec "
288: + "\ud68c\uc0ac\uc640 \uac19\uc740 \uc5c5\uacc4 "
289: + "\uc120\ub450\uc8fc\uc790\uc5d0 \uc758\ud574 "
290: + "\ucc44\ud0dd\ub418\uc5c8\uc2b5\ub2c8\ub2e4. \uc720\ub2c8\ucf54\ub4dc\ub294 "
291: +
292: // "XML, Java, ECMAScript(JavaScript), LDAP, CORBA 3.0, WML " +
293: "\ub4f1\uacfc "
294: + "\uac19\uc774 \ud604\uc7ac \ub110\ub9ac \uc0ac\uc6a9\ub418\ub294 "
295: + "\ud45c\uc900\uc5d0\uc11c \ud544\uc694\ud558\uba70 \uc774\ub294 "
296: + //ISO/IEC " +
297: "10646\uc744 \uad6c\ud604\ud558\ub294 \uacf5\uc2dd\uc801\uc778 "
298: + "\ubc29\ubc95\uc785\ub2c8\ub2e4. \uc774\ub294 \ub9ce\uc740 \uc6b4\uc601 "
299: + "\uccb4\uc81c, \uc694\uc998 \uc0ac\uc6a9\ub418\ub294 \ubaa8\ub4e0 "
300: + "\ube0c\ub77c\uc6b0\uc800 \ubc0f \uae30\ud0c0 \ub9ce\uc740 "
301: + "\uc81c\ud488\uc5d0\uc11c "
302: + "\uc9c0\uc6d0\ub429\ub2c8\ub2e4. \uc720\ub2c8\ucf54\ub4dc "
303: + "\ud45c\uc900\uc758 \ubd80\uc0c1\uacfc \uc774\ub97c "
304: + "\uc9c0\uc6d0\ud558\ub294 \ub3c4\uad6c\uc758 \uac00\uc6a9\uc131\uc740 "
305: + "\ucd5c\uadfc \uc804 \uc138\uacc4\uc5d0 \ubd88\uace0 \uc788\ub294 "
306: + "\uae30\uc220 \uacbd\ud5a5\uc5d0\uc11c \uac00\uc7a5 \uc911\uc694\ud55c "
307: + "\ubd80\ubd84\uc744 \ucc28\uc9c0\ud558\uace0 \uc788\uc2b5\ub2c8\ub2e4. "
308: +
309:
310: "\uc720\ub2c8\ucf54\ub4dc\ub97c "
311: + "\ud074\ub77c\uc774\uc5b8\ud2b8-\uc11c\ubc84 \ub610\ub294 "
312: + "\ub2e4\uc911-\uc5f0\uacb0 \uc751\uc6a9 \ud504\ub85c\uadf8\ub7a8\uacfc "
313: + "\uc6f9 \uc0ac\uc774\ud2b8\uc5d0 \ud1b5\ud569\ud558\uba74 "
314: + "\ub808\uac70\uc2dc \ubb38\uc790 \uc138\ud2b8 \uc0ac\uc6a9\uc5d0 "
315: + "\uc788\uc5b4\uc11c \uc0c1\ub2f9\ud55c \ube44\uc6a9 \uc808\uac10 "
316: + "\ud6a8\uacfc\uac00 "
317: + "\ub098\ud0c0\ub0a9\ub2c8\ub2e4. \uc720\ub2c8\ucf54\ub4dc\ub97c "
318: + "\ud1b5\ud574 \ub9ac\uc5d4\uc9c0\ub2c8\uc5b4\ub9c1 \uc5c6\uc774 "
319: + "\ub2e4\uc911 \ud50c\ub7ab\ud3fc, \uc5b8\uc5b4 \ubc0f \uad6d\uac00 "
320: + "\uac04\uc5d0 \ub2e8\uc77c \uc18c\ud504\ud2b8\uc6e8\uc5b4 "
321: + "\ud50c\ub7ab\ud3fc \ub610\ub294 \ub2e8\uc77c \uc6f9 "
322: + "\uc0ac\uc774\ud2b8\ub97c \ubaa9\ud45c\ub85c \uc0bc\uc744 \uc218 "
323: + "\uc788\uc2b5\ub2c8\ub2e4. \uc774\ub97c \uc0ac\uc6a9\ud558\uba74 "
324: + "\ub370\uc774\ud130\ub97c \uc190\uc0c1 \uc5c6\uc774 \uc5ec\ub7ec "
325: + "\uc2dc\uc2a4\ud15c\uc744 \ud1b5\ud574 \uc804\uc1a1\ud560 \uc218 "
326: + "\uc788\uc2b5\ub2c8\ub2e4. "
327: +
328:
329: "\uc720\ub2c8\ucf54\ub4dc \ucf58\uc18c\uc2dc\uc5c4\uc5d0 \ub300\ud574 "
330: + "\uc720\ub2c8\ucf54\ub4dc \ucf58\uc18c\uc2dc\uc5c4\uc740 "
331: + "\ube44\uc601\ub9ac \uc870\uc9c1\uc73c\ub85c\uc11c \ud604\ub300 "
332: + "\uc18c\ud504\ud2b8\uc6e8\uc5b4 \uc81c\ud488\uacfc "
333: + "\ud45c\uc900\uc5d0\uc11c \ud14d\uc2a4\ud2b8\uc758 \ud45c\ud604\uc744 "
334: + "\uc9c0\uc815\ud558\ub294 \uc720\ub2c8\ucf54\ub4dc \ud45c\uc900\uc758 "
335: + "\uc0ac\uc6a9\uc744 \uac1c\ubc1c\ud558\uace0 \ud655\uc7a5\ud558\uba70 "
336: + "\uc7a5\ub824\ud558\uae30 \uc704\ud574 "
337: + "\uc138\uc6cc\uc84c\uc2b5\ub2c8\ub2e4. \ucf58\uc18c\uc2dc\uc5c4 "
338: + "\uba64\ubc84\uc27d\uc740 \ucef4\ud4e8\ud130\uc640 \uc815\ubcf4 "
339: + "\ucc98\ub9ac \uc0b0\uc5c5\uc5d0 \uc885\uc0ac\ud558\uace0 \uc788\ub294 "
340: + "\uad11\ubc94\uc704\ud55c \ud68c\uc0ac \ubc0f \uc870\uc9c1\uc758 "
341: + "\ubc94\uc704\ub97c "
342: + "\ub098\ud0c0\ub0c5\ub2c8\ub2e4. \ucf58\uc18c\uc2dc\uc5c4\uc758 "
343: + "\uc7ac\uc815\uc740 \uc804\uc801\uc73c\ub85c \ud68c\ube44\uc5d0 "
344: + "\uc758\ud574 \ucda9\ub2f9\ub429\ub2c8\ub2e4. \uc720\ub2c8\ucf54\ub4dc "
345: + "\ucee8\uc18c\uc2dc\uc5c4\uc5d0\uc11c\uc758 \uba64\ubc84\uc27d\uc740 "
346: + "\uc804 \uc138\uacc4 \uc5b4\ub290 \uacf3\uc5d0\uc11c\ub098 "
347: + "\uc720\ub2c8\ucf54\ub4dc \ud45c\uc900\uc744 \uc9c0\uc6d0\ud558\uace0 "
348: + "\uadf8 \ud655\uc7a5\uacfc \uad6c\ud604\uc744 "
349: + "\uc9c0\uc6d0\ud558\uace0\uc790\ud558\ub294 \uc870\uc9c1\uacfc "
350: + "\uac1c\uc778\uc5d0\uac8c \uac1c\ubc29\ub418\uc5b4 "
351: + "\uc788\uc2b5\ub2c8\ub2e4. "
352: +
353:
354: "\ub354 \uc790\uc138\ud55c \ub0b4\uc6a9\uc740 \uc6a9\uc5b4\uc9d1, "
355: + "\uc608\uc81c \uc720\ub2c8\ucf54\ub4dc \uc0ac\uc6a9 \uac00\ub2a5 "
356: + "\uc81c\ud488, \uae30\uc220 \uc815\ubcf4 \ubc0f \uae30\ud0c0 "
357: + "\uc720\uc6a9\ud55c \uc815\ubcf4\ub97c "
358: + "\ucc38\uc870\ud558\uc2ed\uc2dc\uc624.";
359:
360: // TransliteratorTest override
361: boolean expectAux(String tag, String summary, boolean pass,
362: String expectedResult) {
363: return super .expectAux(tag, jamoToName(summary), pass,
364: jamoToName(expectedResult));
365: }
366:
367: // UTILITIES
368:
369: // Note: The following could more easily be done with a transliterator!
370: static final String[] JAMO_NAMES = { "(Gi)", "\u1100", "(GGi)",
371: "\u1101", "(Ni)", "\u1102", "(Di)", "\u1103", "(DD)",
372: "\u1104", "(R)", "\u1105", "(Mi)", "\u1106", "(Bi)",
373: "\u1107", "(BB)", "\u1108", "(Si)", "\u1109", "(SSi)",
374: "\u110A", "(IEUNG)", "\u110B", "(Ji)", "\u110C", "(JJ)",
375: "\u110D", "(Ci)", "\u110E", "(Ki)", "\u110F", "(Ti)",
376: "\u1110", "(Pi)", "\u1111", "(Hi)", "\u1112",
377:
378: "(A)", "\u1161", "(AE)", "\u1162", "(YA)", "\u1163",
379: "(YAE)", "\u1164", "(EO)", "\u1165", "(E)", "\u1166",
380: "(YEO)", "\u1167", "(YE)", "\u1168", "(O)", "\u1169",
381: "(WA)", "\u116A", "(WAE)", "\u116B", "(OE)", "\u116C",
382: "(YO)", "\u116D", "(U)", "\u116E", "(WEO)", "\u116F",
383: "(WE)", "\u1170", "(WI)", "\u1171", "(YU)", "\u1172",
384: "(EU)", "\u1173", "(YI)", "\u1174", "(I)", "\u1175",
385:
386: "(Gf)", "\u11A8", "(GGf)", "\u11A9", "(GS)", "\u11AA",
387: "(Nf)", "\u11AB", "(NJ)", "\u11AC", "(NH)", "\u11AD",
388: "(Df)", "\u11AE", "(L)", "\u11AF", "(LG)", "\u11B0",
389: "(LM)", "\u11B1", "(LB)", "\u11B2", "(LS)", "\u11B3",
390: "(LT)", "\u11B4", "(LP)", "\u11B5", "(LH)", "\u11B6",
391: "(Mf)", "\u11B7", "(Bf)", "\u11B8", "(BS)", "\u11B9",
392: "(Sf)", "\u11BA", "(SSf)", "\u11BB", "(NG)", "\u11BC",
393: "(Jf)", "\u11BD", "(Cf)", "\u11BE", "(Kf)", "\u11BF",
394: "(Tf)", "\u11C0", "(Pf)", "\u11C1", "(Hf)", "\u11C2", };
395:
396: static Hashtable JAMO_TO_NAME;
397: static Hashtable NAME_TO_JAMO;
398:
399: static {
400: JAMO_TO_NAME = new Hashtable();
401: NAME_TO_JAMO = new Hashtable();
402: for (int i = 0; i < JAMO_NAMES.length; i += 2) {
403: JAMO_TO_NAME.put(JAMO_NAMES[i + 1], JAMO_NAMES[i]);
404: NAME_TO_JAMO.put(JAMO_NAMES[i], JAMO_NAMES[i + 1]);
405: }
406: }
407:
408: /**
409: * Convert short names to actual jamo. E.g., "x(LG)y" returns
410: * "x\u11B0y". See JAMO_NAMES for table of names.
411: */
412: static String nameToJamo(String input) {
413: StringBuffer buf = new StringBuffer();
414: for (int i = 0; i < input.length(); ++i) {
415: char c = input.charAt(i);
416: if (c == '(') {
417: int j = input.indexOf(')', i + 1);
418: if ((j - i) >= 2 && (j - i) <= 6) { // "(A)", "(IEUNG)"
419: String jamo = (String) NAME_TO_JAMO.get(input
420: .substring(i, j + 1));
421: if (jamo != null) {
422: buf.append(jamo);
423: i = j;
424: continue;
425: }
426: }
427: }
428: buf.append(c);
429: }
430: return buf.toString();
431: }
432:
433: /**
434: * Convert jamo to short names. E.g., "x\u11B0y" returns
435: * "x(LG)y". See JAMO_NAMES for table of names.
436: */
437: static String jamoToName(String input) {
438: StringBuffer buf = new StringBuffer();
439: for (int i = 0; i < input.length(); ++i) {
440: char c = input.charAt(i);
441: if (c >= 0x1100 && c <= 0x11C2) {
442: String name = (String) JAMO_TO_NAME.get(input
443: .substring(i, i + 1));
444: if (name != null) {
445: buf.append(name);
446: continue;
447: }
448: }
449: buf.append(c);
450: }
451: return buf.toString();
452: }
453: }
|