@@ -48,6 +48,15 @@ private void encodeAll(String[] strings, String expectedEncoding) throws Encoder
4848 }
4949 }
5050
51+ @ Test
52+ public void testTrueVariant () {
53+ Nysiis encoder = new Nysiis (true );
54+
55+ String encoded = encoder .encode ("WESTERLUND" );
56+ Assert .assertTrue (encoded .length () <= 6 );
57+ Assert .assertEquals ("WASTAR" , encoded );
58+ }
59+
5160 @ Test
5261 public void testBran () throws EncoderException {
5362 encodeAll (new String [] { "Brian" , "Brown" , "Brun" }, "BRAN" );
@@ -70,6 +79,17 @@ public void testDan() throws EncoderException {
7079 this .encodeAll (new String [] { "Dane" , "Dean" , "Dionne" }, "DAN" );
7180 }
7281
82+ @ Test
83+ public void testSpecialBranches () throws EncoderException {
84+ this .encodeAll (new String [] { "Kobwick" }, "CABWAC" );
85+ this .encodeAll (new String [] { "Kocher" }, "CACAR" );
86+ this .encodeAll (new String [] { "Fesca" }, "FASC" );
87+ this .encodeAll (new String [] { "Shom" }, "SAN" );
88+ this .encodeAll (new String [] { "Ohlo" }, "OL" );
89+ this .encodeAll (new String [] { "Uhu" }, "UH" );
90+ this .encodeAll (new String [] { "Um" }, "UN" );
91+ }
92+
7393 @ Test
7494 public void testDropBy () throws EncoderException {
7595 List <String []> testValues =
@@ -112,16 +132,62 @@ public void testDropBy() throws EncoderException {
112132 */
113133 @ Test
114134 public void testDropBy2 () throws EncoderException {
135+ // Explanation of differences between this implementation and the one at dropby.com.
136+ //
137+ // Algorithm (taken from www.dropby.com/NYSIIS.html):
138+ //
139+ // 1. Transcode first characters of name:
140+ // MAC » MCC
141+ // KN » NN
142+ // K » C
143+ // PH » FF
144+ // PF » FF
145+ // SCH » SSS
146+ //
147+ // 2. Transcode last characters of name:
148+ // EE, IE » Y
149+ // DT,RT,RD,NT,ND » D
150+ //
151+ // 3. First character of key = first character of name.
152+ //
153+ // 4. Transcode remaining characters by following these rules, incrementing by one character each time:
154+ // 4a. EV » AF else A,E,I,O,U » A
155+ // 4b. Q » G
156+ // 4c. Z » S
157+ // 4d. M » N
158+ // 4e. KN » N else K » C
159+ // 4f. SCH » SSS
160+ // 4g. PH » FF
161+ // 4h. H » If previous or next is nonvowel, previous
162+ // 4i. W » If previous is vowel, previous
163+ // 4j. Add current to key if current != last key character
164+ //
165+ // 5. If last character is S, remove it
166+ // 6. If last characters are AY, replace with Y
167+ // 7. If last character is A, remove it
168+ // 8. Collapse all strings of repeated characters
169+ // 9. Add original first character of name as first character of key
170+
115171 List <String []> testValues =
116172 Arrays .asList (
117173 // http://www.dropby.com/indexLF.html?content=/NYSIIS.html
118174 // 1. Transcode first characters of name
119175 new String [] { "MACINTOSH" , "MCANT" },
120- //new String[] { "KNUTH", "NNATH" }, // Original: NNAT; modified: NATH
121- //new String[] { "KOEHN", "C" },
122- //new String[] { "PHILLIPSON", "FFALAP" },
123- //new String[] { "PFEISTER", "FFASTA" },
124- //new String[] { "SCHOENHOEFT", "SSANAF" },
176+ // violates 4j: the second N should not be added, as the first
177+ // key char is already a N
178+ new String [] { "KNUTH" , "NAT" }, // Original: NNAT; modified: NATH
179+ // O and E are transcoded to A because of rule 4a
180+ // H also to A because of rule 4h
181+ // the N gets mysteriously lost, maybe because of a wrongly implemented rule 4h
182+ // that skips the next char in such a case?
183+ // the remaining A is removed because of rule 7
184+ new String [] { "KOEHN" , "CAN" }, // Original: C
185+ // violates 4j: see also KNUTH
186+ new String [] { "PHILLIPSON" , "FALAPSAN" }, // Original: FFALAP[SAN]
187+ // violates 4j: see also KNUTH
188+ new String [] { "PFEISTER" , "FASTAR" }, // Original: FFASTA[R]
189+ // violoates 4j: see also KNUTH
190+ new String [] { "SCHOENHOEFT" , "SANAFT" }, // Original: SSANAF[T]
125191 // http://www.dropby.com/indexLF.html?content=/NYSIIS.html
126192 // 2.Transcode last characters of name:
127193 new String [] { "MCKEE" , "MCY" },
@@ -139,14 +205,21 @@ public void testDropBy2() throws EncoderException {
139205 new String [] { "BOWMAN" , "BANAN" },
140206 new String [] { "MCKNIGHT" , "MCNAGT" },
141207 new String [] { "RICKERT" , "RACAD" },
142- //new String[] { "DEUTSCH", "DATS" },
208+ // violates 5: the last S is not removed
209+ // when comparing to DEUTS, which is phonetically similar
210+ // the result it also DAT, which is correct for DEUTSCH too imo
211+ new String [] { "DEUTSCH" , "DAT" }, // Original: DATS
143212 new String [] { "WESTPHAL" , "WASTFAL" },
144- //new String[] { "SHRIVER", "SHRAVA" },
145- //new String[] { "KUHL", "C" },
213+ // violates 4h: the H should be transcoded to S and thus ignored as
214+ // the first key character is also S
215+ new String [] { "SHRIVER" , "SRAVAR" }, // Original: SHRAVA[R]
216+ // same as KOEHN, the L gets mysteriously lost, the correct one
217+ new String [] { "KUHL" , "CAL" }, // Original: C
146218 new String [] { "RAWSON" , "RASAN" },
147219 // If last character is S, remove it
148220 new String [] { "JILES" , "JAL" },
149- //new String[] { "CARRAWAY", "CARAY" },
221+ // violates 6: if the last two characters are AY, remove A
222+ new String [] { "CARRAWAY" , "CARY" }, // Original: CARAY
150223 new String [] { "YAMADA" , "YANAD" });
151224
152225 for (String [] arr : testValues ) {
0 commit comments