Initial revision
[old-projects.git] / ekit / com / swabunga / spell / engine / DoubleMeta.java
1 /* This class is based on Lawrence Phillips original c++ code for this class.
2 * Found here: http://aspell.sourceforge.net/metaphone/
3 *
4 */
5
6
7 package com.swabunga.spell.engine;
8
9
10 /**
11 * Double Meta class
12 * <p>
13 * Things that were changed:
14 * The alternate flag could be set to true but was never checked so why bother with it. REMOVED
15 * Why was this class serializable?
16 * The primary, in, length and last variables could be initialized and local to the
17 * process method and references passed arround the appropriate methods. As such there are
18 * no class variables and this class becomes firstly threadsafe and secondly could be static final.
19 * The function call SlavoGermaic was called repeatedly in the process function, it is now only called once.
20 *
21 */
22 class DoubleMeta implements Transformator{
23
24 private static final String[] myList = {
25 "GN", "KN", "PN", "WR", "PS", ""
26 };
27 private static final String[] list1 = {
28 "ACH", ""
29 };
30 private static final String[] list2 = {
31 "BACHER", "MACHER", ""
32 };
33 private static final String[] list3 = {
34 "CAESAR", ""
35 };
36 private static final String[] list4 = {
37 "CHIA", ""
38 };
39 private static final String[] list5 = {
40 "CH", ""
41 };
42 private static final String[] list6 = {
43 "CHAE", ""
44 };
45 private static final String[] list7 = {
46 "HARAC", "HARIS", ""
47 };
48 private static final String[] list8 = {
49 "HOR", "HYM", "HIA", "HEM", ""
50 };
51 private static final String[] list9 = {
52 "CHORE", ""
53 };
54 private static final String[] list10 = {
55 "VAN ", "VON ", ""
56 };
57 private static final String[] list11 = {
58 "SCH", ""
59 };
60 private static final String[] list12 = {
61 "ORCHES", "ARCHIT", "ORCHID", ""
62 };
63 private static final String[] list13 = {
64 "T", "S", ""
65 };
66 private static final String[] list14 = {
67 "A", "O", "U", "E", ""
68 };
69 private static final String[] list15 = {
70 "L", "R", "N", "M", "B", "H", "F", "V", "W", " ", ""
71 };
72 private static final String[] list16 = {
73 "MC", ""
74 };
75 private static final String[] list17 = {
76 "CZ", ""
77 };
78 private static final String[] list18 = {
79 "WICZ", ""
80 };
81 private static final String[] list19 = {
82 "CIA", ""
83 };
84 private static final String[] list20 = {
85 "CC", ""
86 };
87 private static final String[] list21 = {
88 "I", "E", "H", ""
89 };
90 private static final String[] list22 = {
91 "HU", ""
92 };
93 private static final String[] list23 = {
94 "UCCEE", "UCCES", ""
95 };
96 private static final String[] list24 = {
97 "CK", "CG", "CQ", ""
98 };
99 private static final String[] list25 = {
100 "CI", "CE", "CY", ""
101 };
102 private static final String[] list26 = {
103 "CIO", "CIE", "CIA", ""
104 };
105 private static final String[] list27 = {
106 " C", " Q", " G", ""
107 };
108 private static final String[] list28 = {
109 "C", "K", "Q", ""
110 };
111 private static final String[] list29 = {
112 "CE", "CI", ""
113 };
114 private static final String[] list30 = {
115 "DG", ""
116 };
117 private static final String[] list31 = {
118 "I", "E", "Y", ""
119 };
120 private static final String[] list32 = {
121 "DT", "DD", ""
122 };
123 private static final String[] list33 = {
124 "B", "H", "D", ""
125 };
126 private static final String[] list34 = {
127 "B", "H", "D", ""
128 };
129 private static final String[] list35 = {
130 "B", "H", ""
131 };
132 private static final String[] list36 = {
133 "C", "G", "L", "R", "T", ""
134 };
135 private static final String[] list37 = {
136 "EY", ""
137 };
138 private static final String[] list38 = {
139 "LI", ""
140 };
141 private static final String[] list39 = {
142 "ES", "EP", "EB", "EL", "EY", "IB", "IL", "IN", "IE", "EI", "ER",
143 ""
144 };
145 private static final String[] list40 = {
146 "ER", ""
147 };
148 private static final String[] list41 = {
149 "DANGER", "RANGER", "MANGER", ""
150 };
151 private static final String[] list42 = {
152 "E", "I", ""
153 };
154 private static final String[] list43 = {
155 "RGY", "OGY", ""
156 };
157 private static final String[] list44 = {
158 "E", "I", "Y", ""
159 };
160 private static final String[] list45 = {
161 "AGGI", "OGGI", ""
162 };
163 private static final String[] list46 = {
164 "VAN ", "VON ", ""
165 };
166 private static final String[] list47 = {
167 "SCH", ""
168 };
169 private static final String[] list48 = {
170 "ET", ""
171 };
172 private static final String[] list49 = {
173 "IER ", ""
174 };
175 private static final String[] list50 = {
176 "JOSE", ""
177 };
178 private static final String[] list51 = {
179 "SAN ", ""
180 };
181 private static final String[] list52 = {
182 "SAN ", ""
183 };
184 private static final String[] list53 = {
185 "JOSE", ""
186 };
187 private static final String[] list54 = {
188 "L", "T", "K", "S", "N", "M", "B", "Z", ""
189 };
190 private static final String[] list55 = {
191 "S", "K", "L", ""
192 };
193 private static final String[] list56 = {
194 "ILLO", "ILLA", "ALLE", ""
195 };
196 private static final String[] list57 = {
197 "AS", "OS", ""
198 };
199 private static final String[] list58 = {
200 "A", "O", ""
201 };
202 private static final String[] list59 = {
203 "ALLE", ""
204 };
205 private static final String[] list60 = {
206 "UMB", ""
207 };
208 private static final String[] list61 = {
209 "ER", ""
210 };
211 private static final String[] list62 = {
212 "P", "B", ""
213 };
214 private static final String[] list63 = {
215 "IE", ""
216 };
217 private static final String[] list64 = {
218 "ME", "MA", ""
219 };
220 private static final String[] list65 = {
221 "ISL", "YSL", ""
222 };
223 private static final String[] list66 = {
224 "SUGAR", ""
225 };
226 private static final String[] list67 = {
227 "SH", ""
228 };
229 private static final String[] list68 = {
230 "HEIM", "HOEK", "HOLM", "HOLZ", ""
231 };
232 private static final String[] list69 = {
233 "SIO", "SIA", ""
234 };
235 private static final String[] list70 = {
236 "SIAN", ""
237 };
238 private static final String[] list71 = {
239 "M", "N", "L", "W", ""
240 };
241 private static final String[] list72 = {
242 "Z", ""
243 };
244 private static final String[] list73 = {
245 "Z", ""
246 };
247 private static final String[] list74 = {
248 "SC", ""
249 };
250 private static final String[] list75 = {
251 "OO", "ER", "EN", "UY", "ED", "EM", ""
252 };
253 private static final String[] list76 = {
254 "ER", "EN", ""
255 };
256 private static final String[] list77 = {
257 "I", "E", "Y", ""
258 };
259 private static final String[] list78 = {
260 "AI", "OI", ""
261 };
262 private static final String[] list79 = {
263 "S", "Z", ""
264 };
265 private static final String[] list80 = {
266 "TION", ""
267 };
268 private static final String[] list81 = {
269 "TIA", "TCH", ""
270 };
271 private static final String[] list82 = {
272 "TH", ""
273 };
274 private static final String[] list83 = {
275 "TTH", ""
276 };
277 private static final String[] list84 = {
278 "OM", "AM", ""
279 };
280 private static final String[] list85 = {
281 "VAN ", "VON ", ""
282 };
283 private static final String[] list86 = {
284 "SCH", ""
285 };
286 private static final String[] list87 = {
287 "T", "D", ""
288 };
289 private static final String[] list88 = {
290 "WR", ""
291 };
292 private static final String[] list89 = {
293 "WH", ""
294 };
295 private static final String[] list90 = {
296 "EWSKI", "EWSKY", "OWSKI", "OWSKY", ""
297 };
298 private static final String[] list91 = {
299 "SCH", ""
300 };
301 private static final String[] list92 = {
302 "WICZ", "WITZ", ""
303 };
304 private static final String[] list93 = {
305 "IAU", "EAU", ""
306 };
307 private static final String[] list94 = {
308 "AU", "OU", ""
309 };
310 private static final String[] list95 = {
311 "C", "X", ""
312 };
313 private static final String[] list96 = {
314 "ZO", "ZI", "ZA", ""
315 };
316
317 /**
318 * put your documentation comment here
319 * @return
320 */
321 private final static boolean SlavoGermanic (String in) {
322 if ((in.indexOf("W") > -1) || (in.indexOf("K") > -1) || (in.indexOf("CZ") > -1)
323 || (in.indexOf("WITZ") > -1))
324 return true;
325 return false;
326 }
327
328 /**
329 * put your documentation comment here
330 * @param main
331 */
332 private final static void MetaphAdd (StringBuffer primary, String main) {
333 if (main != null) {
334 primary.append(main);
335 }
336 }
337
338 private final static void MetaphAdd (StringBuffer primary, char main) {
339 primary.append(main);
340 }
341
342 /**
343 * put your documentation comment here
344 * @param at
345 * @return
346 */
347 private final static boolean isVowel (String in, int at, int length) {
348 if ((at < 0) || (at >= length))
349 return false;
350 char it = in.charAt(at);
351 if ((it == 'A') || (it == 'E') || (it == 'I') || (it == 'O') || (it ==
352 'U') || (it == 'Y'))
353 return true;
354 return false;
355 }
356
357 /**
358 * put your documentation comment here
359 * @param string
360 * @param start
361 * @param length
362 * @param list
363 * @return
364 */
365 private final static boolean stringAt (String string, int start, int length, String[] list) {
366 if ((start < 0) || (start >= string.length()) || list.length == 0 )
367 return false;
368 String substr = string.substring(start, start + length);
369 for (int i = 0; i < list.length; i++) {
370 if (list[i].equals(substr))
371 return true;
372 }
373 return false;
374 }
375
376 /**
377 * put your documentation comment here
378 * @param word The word to process.
379 * @return
380 */
381 public final String transform (String word) {
382 StringBuffer primary = new StringBuffer( word.length() + 5 );
383 String in = word.toUpperCase() + " ";
384 int current = 0;
385 int length = in.length();
386 if (length < 1)
387 return "";
388 int last = length - 1;
389 boolean isSlavoGermaic = SlavoGermanic(in);
390 if (stringAt(in, 0, 2, myList))
391 current += 1;
392 if (in.charAt(0) == 'X') {
393 MetaphAdd(primary, 'S');
394 current += 1;
395 }
396 while (current < length ) {
397 switch (in.charAt(current)) {
398 case 'A':case 'E':case 'I':case 'O':case 'U':case 'Y':
399 if (current == 0)
400 MetaphAdd(primary, 'A');
401 current += 1;
402 break;
403 case 'B':
404 MetaphAdd(primary, 'P');
405 if (in.charAt(current + 1) == 'B')
406 current += 2;
407 else
408 current += 1;
409 break;
410 case 'Ç':
411 MetaphAdd(primary, 'S');
412 current += 1;
413 break;
414 case 'C':
415 if ((current > 1) && !isVowel(in, current - 2, length) && stringAt(in, (current
416 - 1), 3, list1) && (in.charAt(current + 2) != 'I') && (in.charAt(
417 current + 2) != 'E') || stringAt(in, (current - 2), 6, list2)) {
418 MetaphAdd(primary, 'K');
419 current += 2;
420 break;
421 }
422 if ((current == 0) && stringAt(in, current, 6, list3)) {
423 MetaphAdd(primary, 'S');
424 current += 2;
425 break;
426 }
427 if (stringAt(in, current, 4, list4)) {
428 MetaphAdd(primary, 'K');
429 current += 2;
430 break;
431 }
432 if (stringAt(in, current, 2, list5)) {
433 if ((current > 0) && stringAt(in, current, 4, list6)) {
434 MetaphAdd(primary, 'K' );
435 current += 2;
436 break;
437 }
438 if ((current == 0) && stringAt(in, (current + 1), 5, list7) ||
439 stringAt(in, current + 1, 3, list8) && !stringAt(in, 0, 5,
440 list9)) {
441 MetaphAdd(primary, 'K' );
442 current += 2;
443 break;
444 }
445 if (stringAt(in, 0, 4, list10) || stringAt(in, 0, 3, list11) ||
446 stringAt(in, current - 2, 6, list12) || stringAt(in, current
447 + 2, 1, list13) || (stringAt(in, current - 1, 1, list14) ||
448 (current == 0)) && stringAt(in, current + 2, 1, list15)) {
449 MetaphAdd(primary, 'K');
450 }
451 else {
452 if (current > 0) {
453 if (stringAt(in, 0, 2, list16))
454 MetaphAdd(primary, 'K');
455 else
456 MetaphAdd(primary, 'X');
457 }
458 else {
459 MetaphAdd(primary, 'X');
460 }
461 }
462 current += 2;
463 break;
464 }
465 if (stringAt(in, current, 2, list17) && !stringAt(in, current, 4,
466 list18)) {
467 MetaphAdd(primary, 'S');
468 current += 2;
469 break;
470 }
471 if (stringAt(in, current, 2, list19)) {
472 MetaphAdd(primary, 'X');
473 current += 2;
474 break;
475 }
476 if (stringAt(in, current, 2, list20) && !((current == 1) && in.charAt(0)
477 == 'M')) {
478 if (stringAt(in, current + 2, 1, list21) && !stringAt(in, current
479 + 2, 2, list22)) {
480 if (((current == 1) && (in.charAt(current - 1) == 'A')) || stringAt(in,
481 (current - 1), 5, list23))
482 MetaphAdd(primary, "KS");
483 else
484 MetaphAdd(primary, 'X');
485 current += 3;
486 break;
487 }
488 else {
489 MetaphAdd(primary, 'K');
490 current += 2;
491 break;
492 }
493 }
494 if (stringAt(in, current, 2, list24)) {
495 MetaphAdd(primary, 'K');
496 current += 2;
497 break;
498 }
499 else if (stringAt(in, current, 2, list25)) {
500 MetaphAdd(primary, 'S');
501 current += 2;
502 break;
503 }
504
505 MetaphAdd(primary, 'K');
506 if (stringAt(in, current + 1, 2, list27))
507 current += 3;
508 else if (stringAt(in, current + 1, 1, list28) && !stringAt(in, current
509 + 1, 2, list29))
510 current += 2;
511 else
512 current += 1;
513 break;
514 case 'D':
515 if (stringAt(in, current, 2, list30)) {
516 if (stringAt(in, current + 2, 1, list31)) {
517 MetaphAdd(primary, 'J');
518 current += 3;
519 break;
520 }
521 else {
522 MetaphAdd(primary, "TK");
523 current += 2;
524 break;
525 }
526 }
527 MetaphAdd(primary, 'T');
528 if (stringAt(in, current, 2, list32)) {
529 current += 2;
530 } else {
531 current += 1;
532 }
533 break;
534 case 'F':
535 if (in.charAt(current + 1) == 'F')
536 current += 2;
537 else
538 current += 1;
539 MetaphAdd(primary, 'F');
540 break;
541 case 'G':
542 if (in.charAt(current + 1) == 'H') {
543 if ((current > 0) && !isVowel(in, current - 1, length)) {
544 MetaphAdd(primary, 'K');
545 current += 2;
546 break;
547 }
548 if (current < 3) {
549 if (current == 0) {
550 if (in.charAt(current + 2) == 'I')
551 MetaphAdd(primary, 'J');
552 else
553 MetaphAdd(primary, 'K');
554 current += 2;
555 break;
556 }
557 }
558 if ((current > 1) && stringAt(in, current - 2, 1, list33) || ((current > 2)
559 && stringAt(in, current - 3, 1, list34)) || ((current > 3) &&
560 stringAt(in, current - 4, 1, list35))) {
561 current += 2;
562 break;
563 }
564 else {
565 if ((current > 2) && (in.charAt(current - 1) == 'U') && stringAt(in,
566 current - 3, 1, list36)) {
567 MetaphAdd(primary, 'F');
568 }
569 else {
570 if ((current > 0) && (in.charAt(current - 1) != 'I'))
571 MetaphAdd(primary, 'K');
572 }
573 current += 2;
574 break;
575 }
576 }
577 if (in.charAt(current + 1) == 'N') {
578 if ((current == 1) && isVowel(in, 0, length) && !isSlavoGermaic) {
579 MetaphAdd(primary, "KN");
580 }
581 else {
582 if (!stringAt(in, current + 2, 2, list37) && (in.charAt(current
583 + 1) != 'Y') && !isSlavoGermaic) {
584 MetaphAdd(primary, "N");
585 }
586 else {
587 MetaphAdd(primary, "KN");
588 }
589 }
590 current += 2;
591 break;
592 }
593 if (stringAt(in, current + 1, 2, list38) && !isSlavoGermaic) {
594 MetaphAdd(primary, "KL");
595 current += 2;
596 break;
597 }
598 if ((current == 0) && ((in.charAt(current + 1) == 'Y') || stringAt(in,
599 current + 1, 2, list39))) {
600 MetaphAdd(primary, 'K');
601 current += 2;
602 break;
603 }
604 if ((stringAt(in, current + 1, 2, list40) || (in.charAt(current +
605 1) == 'Y')) && !stringAt(in, 0, 6, list41) && !stringAt(in, current
606 - 1, 1, list42) && !stringAt(in, current - 1, 3, list43)) {
607 MetaphAdd(primary, 'K');
608 current += 2;
609 break;
610 }
611 if (stringAt(in, current + 1, 1, list44) || stringAt(in, current -
612 1, 4, list45)) {
613 if (stringAt(in, 0, 4, list46) || stringAt(in, 0, 3, list47) ||
614 stringAt(in, current + 1, 2, list48)) {
615 MetaphAdd(primary, 'K');
616 }
617 else {
618 MetaphAdd(primary, 'J');
619 }
620 current += 2;
621 break;
622 }
623 if (in.charAt(current + 1) == 'G')
624 current += 2;
625 else
626 current += 1;
627 MetaphAdd(primary, 'K');
628 break;
629 case 'H':
630 if (((current == 0) || isVowel(in, current - 1, length)) && isVowel(in, current +
631 1, length)) {
632 MetaphAdd(primary, 'H');
633 current += 2;
634 }
635 else {
636 current += 1;
637 }
638 break;
639 case 'J':
640 if (stringAt(in, current, 4, list50) || stringAt(in, 0, 4, list51)) {
641 if ((current == 0) && (in.charAt(current + 4) == ' ') || stringAt(in,
642 0, 4, list52)) {
643 MetaphAdd(primary, 'H');
644 }
645 else {
646 MetaphAdd(primary, 'J');
647 }
648 current += 1;
649 break;
650 }
651 if ((current == 0) && !stringAt(in, current, 4, list53)) {
652 MetaphAdd(primary, 'J');
653 }
654 else {
655 if (isVowel(in, current - 1, length) && !isSlavoGermaic && ((in.charAt(current
656 + 1) == 'A') || in.charAt(current + 1) == 'O')) {
657 MetaphAdd(primary, 'J' );
658 }
659 else {
660 if (current == last) {
661 MetaphAdd(primary, 'J' );
662 }
663 else {
664 if (!stringAt(in, current + 1, 1, list54) && !stringAt(in,
665 current - 1, 1, list55)) {
666 MetaphAdd(primary, 'J');
667 }
668 }
669 }
670 }
671 if (in.charAt(current + 1) == 'J')
672 current += 2;
673 else
674 current += 1;
675 break;
676 case 'K':
677 if (in.charAt(current + 1) == 'K')
678 current += 2;
679 else
680 current += 1;
681 MetaphAdd(primary, 'K');
682 break;
683 case 'L':
684 if (in.charAt(current + 1) == 'L') {
685 if (((current == (length - 3)) && stringAt(in, current - 1, 4,
686 list56)) || ((stringAt(in, last - 1, 2, list57) || stringAt(in,
687 last, 1, list58)) && stringAt(in, current - 1, 4, list59))) {
688 MetaphAdd(primary, 'L' );
689 current += 2;
690 break;
691 }
692 current += 2;
693 }
694 else
695 current += 1;
696 MetaphAdd(primary, 'L');
697 break;
698 case 'M':
699 if ((stringAt(in, current - 1, 3, list60) && (((current + 1) == last)
700 || stringAt(in, current + 2, 2, list61))) || (in.charAt(current
701 + 1) == 'M'))
702 current += 2;
703 else
704 current += 1;
705 MetaphAdd(primary, 'M');
706 break;
707 case 'N':
708 if (in.charAt(current + 1) == 'N')
709 current += 2;
710 else
711 current += 1;
712 MetaphAdd(primary, 'N');
713 break;
714 case 'Ñ':
715 current += 1;
716 MetaphAdd(primary, 'N');
717 break;
718 case 'P':
719 if (in.charAt(current + 1) == 'N') {
720 MetaphAdd(primary, 'F');
721 current += 2;
722 break;
723 }
724 if (stringAt(in, current + 1, 1, list62))
725 current += 2;
726 else
727 current += 1;
728 MetaphAdd(primary, 'P');
729 break;
730 case 'Q':
731 if (in.charAt(current + 1) == 'Q')
732 current += 2;
733 else
734 current += 1;
735 MetaphAdd(primary, 'K');
736 break;
737 case 'R':
738 if ((current == last) && !isSlavoGermaic && stringAt(in, current
739 - 2, 2, list63) && !stringAt(in, current - 4, 2, list64)) {
740 // MetaphAdd(primary, "");
741 } else
742 MetaphAdd(primary, 'R');
743 if (in.charAt(current + 1) == 'R')
744 current += 2;
745 else
746 current += 1;
747 break;
748 case 'S':
749 if (stringAt(in, current - 1, 3, list65)) {
750 current += 1;
751 break;
752 }
753 if ((current == 0) && stringAt(in, current, 5, list66)) {
754 MetaphAdd(primary, 'X');
755 current += 1;
756 break;
757 }
758 if (stringAt(in, current, 2, list67)) {
759 if (stringAt(in, current + 1, 4, list68))
760 MetaphAdd(primary, 'S');
761 else
762 MetaphAdd(primary, 'X');
763 current += 2;
764 break;
765 }
766 if (stringAt(in, current, 3, list69) || stringAt(in, current, 4,
767 list70)) {
768 MetaphAdd(primary, 'S');
769 current += 3;
770 break;
771 }
772 if (((current == 0) && stringAt(in, current + 1, 1, list71)) || stringAt(in,
773 current + 1, 1, list72)) {
774 MetaphAdd(primary, 'S');
775 if (stringAt(in, current + 1, 1, list73))
776 current += 2;
777 else
778 current += 1;
779 break;
780 }
781 if (stringAt(in, current, 2, list74)) {
782 if (in.charAt(current + 2) == 'H')
783 if (stringAt(in, current + 3, 2, list75)) {
784 if (stringAt(in, current + 3, 2, list76)) {
785 MetaphAdd(primary, "X");
786 }
787 else {
788 MetaphAdd(primary, "SK");
789 }
790 current += 3;
791 break;
792 }
793 else {
794 MetaphAdd(primary, 'X');
795 current += 3;
796 break;
797 }
798 if (stringAt(in, current + 2, 1, list77)) {
799 MetaphAdd(primary, 'S');
800 current += 3;
801 break;
802 }
803 MetaphAdd(primary, "SK");
804 current += 3;
805 break;
806 }
807 if ((current == last) && stringAt(in, current - 2, 2, list78)) {
808 //MetaphAdd(primary, "");
809 } else
810 MetaphAdd(primary, 'S');
811 if (stringAt(in, current + 1, 1, list79))
812 current += 2;
813 else
814 current += 1;
815 break;
816 case 'T':
817 if (stringAt(in, current, 4, list80)) {
818 MetaphAdd(primary, 'X');
819 current += 3;
820 break;
821 }
822 if (stringAt(in, current, 3, list81)) {
823 MetaphAdd(primary, 'X');
824 current += 3;
825 break;
826 }
827 if (stringAt(in, current, 2, list82) || stringAt(in, current, 3,
828 list83)) {
829 if (stringAt(in, (current + 2), 2, list84) || stringAt(in, 0, 4,
830 list85) || stringAt(in, 0, 3, list86)) {
831 MetaphAdd(primary, 'T');
832 }
833 else {
834 MetaphAdd(primary, '0');
835 }
836 current += 2;
837 break;
838 }
839 if (stringAt(in, current + 1, 1, list87)) {
840 current += 2;
841 }
842 else
843 current += 1;
844 MetaphAdd(primary, 'T');
845 break;
846 case 'V':
847 if (in.charAt(current + 1) == 'V')
848 current += 2;
849 else
850 current += 1;
851 MetaphAdd(primary, 'F');
852 break;
853 case 'W':
854 if (stringAt(in, current, 2, list88)) {
855 MetaphAdd(primary, 'R');
856 current += 2;
857 break;
858 }
859 if ((current == 0) && (isVowel(in, current + 1, length) || stringAt(in, current,
860 2, list89))) {
861 MetaphAdd(primary, 'A');
862 }
863 if (((current == last) && isVowel(in, current - 1, length)) || stringAt(in, current
864 - 1, 5, list90) || stringAt(in, 0, 3, list91)) {
865 MetaphAdd(primary, 'F');
866 current += 1;
867 break;
868 }
869 if (stringAt(in, current, 4, list92)) {
870 MetaphAdd(primary, "TS");
871 current += 4;
872 break;
873 }
874 current += 1;
875 break;
876 case 'X':
877 if (!((current == last) && (stringAt(in, current - 3, 3, list93) ||
878 stringAt(in, current - 2, 2, list94))))
879 MetaphAdd(primary, "KS");
880 if (stringAt(in, current + 1, 1, list95))
881 current += 2;
882 else
883 current += 1;
884 break;
885 case 'Z':
886 if (in.charAt(current + 1) == 'H') {
887 MetaphAdd(primary, 'J');
888 current += 2;
889 break;
890 }
891 else {
892 MetaphAdd(primary, 'S');
893 }
894 if (in.charAt(current + 1) == 'Z')
895 current += 2;
896 else
897 current += 1;
898 break;
899 default:
900 current += 1;
901 }
902 }
903 return primary.toString();
904 }
905 }
906
907
908