public RulesApplication invoke() { found = false; int j = 0; Iterator localIterator = finalRules.iterator(); while (localIterator.hasNext()) { Rule localRule = (Rule) localIterator.next(); int k = localRule.getPattern().length(); j = k; if (localRule.patternAndContextMatches(input, i)) { phonemeBuilder = phonemeBuilder.apply(localRule.getPhoneme(), maxPhonemes); found = true; j = k; } } if (!found) { j = 1; } i += j; return this; }
public String transRule(String word) { String ret = ""; int remainder = 1; while (remainder < word.length() - 1) { RuleHolder rh; char c = word.toUpperCase().charAt(remainder); if (c == ' ') { c = word.toUpperCase().charAt(remainder + 1); } if (c < 'A' || c > 'Z') { rh = holders[26]; } else { rh = holders[c - 'A']; } boolean matched = false; for (int end = word.length() - 1; end > remainder; end--) { Rule r = rh.getRule( word.substring(0, remainder), word.substring(remainder, end), word.substring(end)); if (r != null) { ret = ret + r.getPhoneme(); remainder += r.getMatch().length(); matched = true; break; } } if (!matched) { // no match found! System.err.println( "Error - NO MATCH FOUND FOR CHARACTER " + word.charAt(remainder) + " OF WORD " + word); // skip letter remainder++; } } return ret; }