/** * Handles 'W' cases */ private int HandleW(string value, DoubleMetaphoneResult result, int index) { // PIN: In scandinavian languages the W is not a Vowel but another V - which is handled as V return(HandleV(value, result, index)); // PIN: THE BELOW IS NOT USED if (Contains(value, index, 2, "WR")) { // can also be in middle of word result.Append('R'); index += 2; } else { if (index == 0 && (IsVowel(CharAt(value, index + 1)) || Contains(value, index, 2, "WH"))) { if (IsVowel(CharAt(value, index + 1))) { // Wasserman should match Vasserman result.Append('A', 'F'); } else { // need Uomo to match Womo result.Append('A'); } index++; } else if ((index == value.Length - 1 && IsVowel(CharAt(value, index - 1))) || Contains(value, index - 1, 5, "EWSKI", "EWSKY", "OWSKI", "OWSKY") || Contains(value, 0, 3, "SCH")) { // Arnow should match Arnoff result.AppendAlternate('F'); index++; } else if (Contains(value, index, 4, "WICZ", "WITZ")) { // Polish e.g. "filipowicz" result.Append("TS", "FX"); index += 4; } else { index++; } } return(index); }
/** * Handles 'R' cases */ private int HandleR(string value, DoubleMetaphoneResult result, int index, bool slavoGermanic) { //french e.g. 'rogier', but exclude 'hochmeier' if (index == value.Length - 1 && !slavoGermanic && Contains(value, index - 2, 2, "IE") && !Contains(value, index - 4, 2, "ME", "MA")) { result.AppendAlternate('R'); } else { result.Append('R'); } return(CharAt(value, index + 1) == 'R' ? index + 2 : index + 1); }
/** * Handles 'L' cases */ private int HandleL(string value, DoubleMetaphoneResult result, int index) { // PIN: do not add another L if the last added character was also a L if (!result.GetPrimary().ToUpper().EndsWith("L")) { result.Append('L'); } // PIN: Todo: handle spanish e.g. 'cabrillo', 'gallegos' // one example can be found here: http://swoodbridge.com/DoubleMetaPhone/double_metaphone_func_1-01.txt if (CharAt(value, index + 1) == 'L') { if (ConditionL0(value, index)) { result.AppendAlternate(' '); } index += 2; } else { index++; } return(index); }
/** * Handles 'R' cases */ private int HandleR(string value, DoubleMetaphoneResult result, int index, bool slavoGermanic) { //french e.g. 'rogier', but exclude 'hochmeier' if (index == value.Length - 1 && !slavoGermanic && Contains(value, index - 2, 2, "IE") && !Contains(value, index - 4, 2, "ME", "MA")) { result.AppendAlternate('R'); } else { result.Append('R'); } return CharAt(value, index + 1) == 'R' ? index + 2 : index + 1; }
/** * Handles 'L' cases */ private int HandleL(string value, DoubleMetaphoneResult result, int index) { // PIN: do not add another L if the last added character was also a L if (!result.GetPrimary().ToUpper().EndsWith("L")) { result.Append('L'); } // PIN: Todo: handle spanish e.g. 'cabrillo', 'gallegos' // one example can be found here: http://swoodbridge.com/DoubleMetaPhone/double_metaphone_func_1-01.txt if (CharAt(value, index + 1) == 'L') { if (ConditionL0(value, index)) { result.AppendAlternate(' '); } index += 2; } else { index++; } return index; }
/** * Handles 'W' cases */ private int HandleW(string value, DoubleMetaphoneResult result, int index) { // PIN: In scandinavian languages the W is not a Vowel but another V - which is handled as V return HandleV(value, result, index); // PIN: THE BELOW IS NOT USED if (Contains(value, index, 2, "WR")) { // can also be in middle of word result.Append('R'); index += 2; } else { if (index == 0 && (IsVowel(CharAt(value, index + 1)) || Contains(value, index, 2, "WH"))) { if (IsVowel(CharAt(value, index + 1))) { // Wasserman should match Vasserman result.Append('A', 'F'); } else { // need Uomo to match Womo result.Append('A'); } index++; } else if ((index == value.Length - 1 && IsVowel(CharAt(value, index - 1))) || Contains(value, index - 1, 5, "EWSKI", "EWSKY", "OWSKI", "OWSKY") || Contains(value, 0, 3, "SCH")) { // Arnow should match Arnoff result.AppendAlternate('F'); index++; } else if (Contains(value, index, 4, "WICZ", "WITZ")) { // Polish e.g. "filipowicz" result.Append("TS", "FX"); index += 4; } else { index++; } } return index; }
/** * Handles 'S' cases */ private int HandleS(string value, DoubleMetaphoneResult result, int index, bool slavoGermanic) { if (Contains(value, index - 1, 3, "ISL", "YSL")) { // special cases "island", "isle", "carlisle", "carlysle" index++; } else if (index == 0 && Contains(value, index, 5, "SUGAR")) { // special case "sugar-" result.Append('X', 'S'); index++; } else if (Contains(value, index, 2, "SH")) { if (Contains(value, index + 1, 4, "HEIM", "HOEK", "HOLM", "HOLZ")) { // germanic result.Append('S'); } else { result.Append('X'); } index += 2; } else if (Contains(value, index, 3, "SIO", "SIA") || Contains(value, index, 4, "SIAN")) { // Italian and Armenian if (slavoGermanic) { result.Append('S'); } else { result.Append('S', 'X'); } index += 3; } else if ((index == 0 && Contains(value, index + 1, 1, "M", "N", "L", "W")) || Contains(value, index + 1, 1, "Z")) { // german & anglicisations, e.g. "smith" match "schmidt" // // "snider" match "schneider" // also, -sz- in slavic language altho in hungarian it // // is pronounced "s" result.Append('S', 'X'); index = Contains(value, index + 1, 1, "Z") ? index + 2 : index + 1; } else if (Contains(value, index, 2, "SC")) { index = HandleSC(value, result, index); } else { if (index == value.Length - 1 && Contains(value, index - 2, 2, "AI", "OI")) { // french e.g. "resnais", "artois" result.AppendAlternate('S'); } else { result.Append('S'); } index = Contains(value, index + 1, 1, "S", "Z") ? index + 2 : index + 1; } return index; }
/** * Handles 'S' cases */ private int HandleS(string value, DoubleMetaphoneResult result, int index, bool slavoGermanic) { if (Contains(value, index - 1, 3, "ISL", "YSL")) { // special cases "island", "isle", "carlisle", "carlysle" index++; } else if (index == 0 && Contains(value, index, 5, "SUGAR")) { // special case "sugar-" result.Append('X', 'S'); index++; } else if (Contains(value, index, 2, "SH")) { if (Contains(value, index + 1, 4, "HEIM", "HOEK", "HOLM", "HOLZ")) { // germanic result.Append('S'); } else { result.Append('X'); } index += 2; } else if (Contains(value, index, 3, "SIO", "SIA") || Contains(value, index, 4, "SIAN")) { // Italian and Armenian if (slavoGermanic) { result.Append('S'); } else { result.Append('S', 'X'); } index += 3; } else if ((index == 0 && Contains(value, index + 1, 1, "M", "N", "L", "W")) || Contains(value, index + 1, 1, "Z")) { // german & anglicisations, e.g. "smith" match "schmidt" // // "snider" match "schneider" // also, -sz- in slavic language altho in hungarian it // // is pronounced "s" result.Append('S', 'X'); index = Contains(value, index + 1, 1, "Z") ? index + 2 : index + 1; } else if (Contains(value, index, 2, "SC")) { index = HandleSC(value, result, index); } else { if (index == value.Length - 1 && Contains(value, index - 2, 2, "AI", "OI")) { // french e.g. "resnais", "artois" result.AppendAlternate('S'); } else { result.Append('S'); } index = Contains(value, index + 1, 1, "S", "Z") ? index + 2 : index + 1; } return(index); }