@Test public void testGetNumberPhoneticRhymePart() { assertEquals(wordParser.phoneticRhymePart("-1"), "uno"); assertEquals(wordParser.phoneticRhymePart("0"), "ero"); assertEquals(wordParser.phoneticRhymePart("dos"), "os"); assertEquals(wordParser.phoneticRhymePart("3521637"), "ete"); assertEquals(wordParser.phoneticRhymePart("350000"), "il"); assertEquals(wordParser.phoneticRhymePart("5000000"), "ones"); }
@Override public String phoneticRhymePart(final String word) { String withoutPunctuation = removeTwitterChars(removeTrailingPunctuation(word)); if (WordUtils.isNumber(withoutPunctuation)) { withoutPunctuation = SpanishNumber.getBaseSound(withoutPunctuation); } String rhymePart = rhymePart(withoutPunctuation); StringBuilder result = new StringBuilder(); char[] letters = rhymePart.toCharArray(); for (int i = 0; i < letters.length; i++) { switch (letters[i]) { case 225: result.append('a'); break; case 233: result.append('e'); break; case 237: result.append('i'); break; case 243: result.append('o'); break; case 250: result.append('u'); break; case 252: result.append('u'); break; case 'b': result.append('v'); break; case 'y': result.append("ll"); break; case 'h': if (i > 0 && letters[i - 1] == 'c') { result.append('h'); } break; case 'g': if (i + 1 < letters.length && (letters[i + 1] == 'e' || letters[i + 1] == 'i')) { result.append('j'); } else { result.append('g'); } break; default: result.append(letters[i]); break; } } return result.toString(); }
SpanishWordParser implements WordParser { @Override public String phoneticRhymePart(final String word) { String withoutPunctuation = removeTwitterChars(removeTrailingPunctuation(word)); if (WordUtils.isNumber(withoutPunctuation)) { withoutPunctuation = SpanishNumber.getBaseSound(withoutPunctuation); } String rhymePart = rhymePart(withoutPunctuation); StringBuilder result = new StringBuilder(); char[] letters = rhymePart.toCharArray(); for (int i = 0; i < letters.length; i++) { switch (letters[i]) { case 225: result.append('a'); break; case 233: result.append('e'); break; case 237: result.append('i'); break; case 243: result.append('o'); break; case 250: result.append('u'); break; case 252: result.append('u'); break; case 'b': result.append('v'); break; case 'y': result.append("ll"); break; case 'h': if (i > 0 && letters[i - 1] == 'c') { result.append('h'); } break; case 'g': if (i + 1 < letters.length && (letters[i + 1] == 'e' || letters[i + 1] == 'i')) { result.append('j'); } else { result.append('g'); } break; default: result.append(letters[i]); break; } } return result.toString(); } }
SpanishWordParser implements WordParser { @Override public String phoneticRhymePart(final String word) { String withoutPunctuation = removeTwitterChars(removeTrailingPunctuation(word)); if (WordUtils.isNumber(withoutPunctuation)) { withoutPunctuation = SpanishNumber.getBaseSound(withoutPunctuation); } String rhymePart = rhymePart(withoutPunctuation); StringBuilder result = new StringBuilder(); char[] letters = rhymePart.toCharArray(); for (int i = 0; i < letters.length; i++) { switch (letters[i]) { case 225: result.append('a'); break; case 233: result.append('e'); break; case 237: result.append('i'); break; case 243: result.append('o'); break; case 250: result.append('u'); break; case 252: result.append('u'); break; case 'b': result.append('v'); break; case 'y': result.append("ll"); break; case 'h': if (i > 0 && letters[i - 1] == 'c') { result.append('h'); } break; case 'g': if (i + 1 < letters.length && (letters[i + 1] == 'e' || letters[i + 1] == 'i')) { result.append('j'); } else { result.append('g'); } break; default: result.append(letters[i]); break; } } return result.toString(); } @Inject  SpanishWordParser(final @Named(FALLBACK_RHYMES) List<String> defaultRhymes); }
SpanishWordParser implements WordParser { @Override public String phoneticRhymePart(final String word) { String withoutPunctuation = removeTwitterChars(removeTrailingPunctuation(word)); if (WordUtils.isNumber(withoutPunctuation)) { withoutPunctuation = SpanishNumber.getBaseSound(withoutPunctuation); } String rhymePart = rhymePart(withoutPunctuation); StringBuilder result = new StringBuilder(); char[] letters = rhymePart.toCharArray(); for (int i = 0; i < letters.length; i++) { switch (letters[i]) { case 225: result.append('a'); break; case 233: result.append('e'); break; case 237: result.append('i'); break; case 243: result.append('o'); break; case 250: result.append('u'); break; case 252: result.append('u'); break; case 'b': result.append('v'); break; case 'y': result.append("ll"); break; case 'h': if (i > 0 && letters[i - 1] == 'c') { result.append('h'); } break; case 'g': if (i + 1 < letters.length && (letters[i + 1] == 'e' || letters[i + 1] == 'i')) { result.append('j'); } else { result.append('g'); } break; default: result.append(letters[i]); break; } } return result.toString(); } @Inject  SpanishWordParser(final @Named(FALLBACK_RHYMES) List<String> defaultRhymes); @Override StressType stressType(final String word); @Override boolean rhyme(final String word1, final String word2); @Override String phoneticRhymePart(final String word); @Override boolean isLetter(final char letter); @Override boolean isWord(final String text); @Override String getDefaultRhyme(); }
SpanishWordParser implements WordParser { @Override public String phoneticRhymePart(final String word) { String withoutPunctuation = removeTwitterChars(removeTrailingPunctuation(word)); if (WordUtils.isNumber(withoutPunctuation)) { withoutPunctuation = SpanishNumber.getBaseSound(withoutPunctuation); } String rhymePart = rhymePart(withoutPunctuation); StringBuilder result = new StringBuilder(); char[] letters = rhymePart.toCharArray(); for (int i = 0; i < letters.length; i++) { switch (letters[i]) { case 225: result.append('a'); break; case 233: result.append('e'); break; case 237: result.append('i'); break; case 243: result.append('o'); break; case 250: result.append('u'); break; case 252: result.append('u'); break; case 'b': result.append('v'); break; case 'y': result.append("ll"); break; case 'h': if (i > 0 && letters[i - 1] == 'c') { result.append('h'); } break; case 'g': if (i + 1 < letters.length && (letters[i + 1] == 'e' || letters[i + 1] == 'i')) { result.append('j'); } else { result.append('g'); } break; default: result.append(letters[i]); break; } } return result.toString(); } @Inject  SpanishWordParser(final @Named(FALLBACK_RHYMES) List<String> defaultRhymes); @Override StressType stressType(final String word); @Override boolean rhyme(final String word1, final String word2); @Override String phoneticRhymePart(final String word); @Override boolean isLetter(final char letter); @Override boolean isWord(final String text); @Override String getDefaultRhyme();  }