org.apache.commons.codec.language.DoubleMetaphone Java Examples
The following examples show how to use
org.apache.commons.codec.language.DoubleMetaphone.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FuzzyMatch.java From hop with Apache License 2.0 | 6 votes |
private String getEncodedMF( String value, Integer algorithmType ) { String encodedValueMF = ""; switch ( algorithmType ) { case FuzzyMatchMeta.OPERATION_TYPE_METAPHONE: encodedValueMF = ( new Metaphone() ).metaphone( value ); break; case FuzzyMatchMeta.OPERATION_TYPE_DOUBLE_METAPHONE: encodedValueMF = ( ( new DoubleMetaphone() ).doubleMetaphone( value ) ); break; case FuzzyMatchMeta.OPERATION_TYPE_SOUNDEX: encodedValueMF = ( new Soundex() ).encode( value ); break; case FuzzyMatchMeta.OPERATION_TYPE_REFINED_SOUNDEX: encodedValueMF = ( new RefinedSoundex() ).encode( value ); break; default: break; } return encodedValueMF; }
Example #2
Source File: TestPhoneticFilter.java From lucene-solr with Apache License 2.0 | 6 votes |
public void testEmptyTerm() throws IOException { Encoder encoders[] = new Encoder[] { new Metaphone(), new DoubleMetaphone(), new Soundex(), new RefinedSoundex(), new Caverphone2() }; for (final Encoder e : encoders) { Analyzer a = new Analyzer() { @Override protected TokenStreamComponents createComponents(String fieldName) { Tokenizer tokenizer = new KeywordTokenizer(); return new TokenStreamComponents(tokenizer, new PhoneticFilter(tokenizer, e, random().nextBoolean())); } }; checkOneTerm(a, "", ""); a.close(); } }
Example #3
Source File: FuzzyMatch.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private String getEncodedMF( String value, Integer algorithmType ) { String encodedValueMF = ""; switch ( algorithmType ) { case FuzzyMatchMeta.OPERATION_TYPE_METAPHONE: encodedValueMF = ( new Metaphone() ).metaphone( value ); break; case FuzzyMatchMeta.OPERATION_TYPE_DOUBLE_METAPHONE: encodedValueMF = ( ( new DoubleMetaphone() ).doubleMetaphone( value ) ); break; case FuzzyMatchMeta.OPERATION_TYPE_SOUNDEX: encodedValueMF = ( new Soundex() ).encode( value ); break; case FuzzyMatchMeta.OPERATION_TYPE_REFINED_SOUNDEX: encodedValueMF = ( new RefinedSoundex() ).encode( value ); break; default: break; } return encodedValueMF; }
Example #4
Source File: TestPhoneticFilter.java From lucene-solr with Apache License 2.0 | 5 votes |
public void testAlgorithms() throws Exception { assertAlgorithm(new Metaphone(), true, "aaa bbb ccc easgasg", new String[] { "A", "aaa", "B", "bbb", "KKK", "ccc", "ESKS", "easgasg" }); assertAlgorithm(new Metaphone(), false, "aaa bbb ccc easgasg", new String[] { "A", "B", "KKK", "ESKS" }); assertAlgorithm(new DoubleMetaphone(), true, "aaa bbb ccc easgasg", new String[] { "A", "aaa", "PP", "bbb", "KK", "ccc", "ASKS", "easgasg" }); assertAlgorithm(new DoubleMetaphone(), false, "aaa bbb ccc easgasg", new String[] { "A", "PP", "KK", "ASKS" }); assertAlgorithm(new Soundex(), true, "aaa bbb ccc easgasg", new String[] { "A000", "aaa", "B000", "bbb", "C000", "ccc", "E220", "easgasg" }); assertAlgorithm(new Soundex(), false, "aaa bbb ccc easgasg", new String[] { "A000", "B000", "C000", "E220" }); assertAlgorithm(new RefinedSoundex(), true, "aaa bbb ccc easgasg", new String[] { "A0", "aaa", "B1", "bbb", "C3", "ccc", "E034034", "easgasg" }); assertAlgorithm(new RefinedSoundex(), false, "aaa bbb ccc easgasg", new String[] { "A0", "B1", "C3", "E034034" }); assertAlgorithm(new Caverphone2(), true, "Darda Karleen Datha Carlene", new String[] { "TTA1111111", "Darda", "KLN1111111", "Karleen", "TTA1111111", "Datha", "KLN1111111", "Carlene" }); assertAlgorithm(new Caverphone2(), false, "Darda Karleen Datha Carlene", new String[] { "TTA1111111", "KLN1111111", "TTA1111111", "KLN1111111" }); assertAlgorithm(new Nysiis(), true, "aaa bbb ccc easgasg", new String[] { "A", "aaa", "B", "bbb", "C", "ccc", "EASGAS", "easgasg" }); assertAlgorithm(new Nysiis(), false, "aaa bbb ccc easgasg", new String[] { "A", "B", "C", "EASGAS" }); }
Example #5
Source File: PhoneticCorrection.java From EDDI with Apache License 2.0 | 5 votes |
public PhoneticCorrection(boolean lookupIfKnown) { this.lookupIfKnown = lookupIfKnown; refinedSoundex = new RefinedSoundex(); doubleMetaphone = new DoubleMetaphone(); metaphoneCodes = new HashMap<>(); soundexCodes = new HashMap<>(); }
Example #6
Source File: ValueDataUtil.java From hop with Apache License 2.0 | 4 votes |
public static String get_Double_Metaphone( IValueMeta metaA, Object dataA ) { if ( dataA == null ) { return null; } return ( new DoubleMetaphone() ).doubleMetaphone( dataA.toString() ); }
Example #7
Source File: DoubleMetaphoneHelper.java From Saiy-PS with GNU Affero General Public License v3.0 | 4 votes |
/** * Method to iterate through the voice data and attempt to match the user's custom commands * using the {@link DoubleMetaphone} within ranges applied by the associated thresholds constants. * * @return the highest scoring {@link CustomCommand} or null if thresholds aren't satisfied */ public CustomCommand executeCustomCommand() { long then = System.nanoTime(); final double jwdLowerThreshold = SPH.getJaroWinklerLower(mContext); CustomCommand customCommand = null; final ArrayList<CustomCommandContainer> toKeep = new ArrayList<>(); final DoubleMetaphone metaphone = new DoubleMetaphone(); final JaroWinklerDistance jwd = new JaroWinklerDistance(); String phrase; CustomCommandContainer container; double score; boolean matches; int size = genericData.size(); outer: for (int i = 0; i < size; i++) { container = (CustomCommandContainer) genericData.get(i); phrase = container.getKeyphrase().toLowerCase(loc).trim(); for (String vd : inputData) { vd = vd.toLowerCase(loc).trim(); matches = metaphone.isDoubleMetaphoneEqual(phrase, vd); if (matches && Algorithm.checkLength(phrase, vd)) { score = jwd.apply(phrase, vd); if (score > jwdLowerThreshold) { container.setScore(score); container.setUtterance(vd); container.setExactMatch(true); toKeep.add(SerializationUtils.clone(container)); break outer; } else { if (DEBUG) { MyLog.i(CLS_NAME, "Matches: double check JW: rejected"); } } } } } if (UtilsList.notNaked(toKeep)) { if (DEBUG) { MyLog.i(CLS_NAME, "Have a match"); } final CustomCommandContainer ccc = toKeep.get(0); final Gson gson = new GsonBuilder().disableHtmlEscaping().create(); customCommand = gson.fromJson(ccc.getSerialised(), CustomCommand.class); customCommand.setExactMatch(ccc.isExactMatch()); customCommand.setUtterance(ccc.getUtterance()); customCommand.setScore(ccc.getScore()); customCommand.setAlgorithm(Algorithm.DOUBLE_METAPHONE); } else { if (DEBUG) { MyLog.i(CLS_NAME, "no custom phrases matched"); } } if (DEBUG) { MyLog.getElapsed(CLS_NAME, then); } return customCommand; }
Example #8
Source File: DoubleMetaphoneHelper.java From Saiy-PS with GNU Affero General Public License v3.0 | 4 votes |
/** * Method to iterate through the given input data and attempt to match the given String data * using the {@link DoubleMetaphone} within ranges applied by the associated thresholds constants. * * @return an {@link AlgorithmicContainer} or null if thresholds aren't satisfied */ public AlgorithmicContainer executeGeneric() { long then = System.nanoTime(); final double jwdLowerThreshold = SPH.getJaroWinklerLower(mContext); final ArrayList<AlgorithmicContainer> toKeep = new ArrayList<>(); final DoubleMetaphone metaphone = new DoubleMetaphone(); final JaroWinklerDistance jwd = new JaroWinklerDistance(); String generic; String genericLower; AlgorithmicContainer container = null; double score; boolean matches; int size = genericData.size(); outer: for (int i = 0; i < size; i++) { generic = (String) genericData.get(i); genericLower = generic.toLowerCase(loc).trim(); for (String vd : inputData) { vd = vd.toLowerCase(loc).trim(); matches = metaphone.isDoubleMetaphoneEqual(genericLower, vd); if (matches && Algorithm.checkLength(genericLower, vd)) { score = jwd.apply(genericLower, vd); if (score > jwdLowerThreshold) { container = new AlgorithmicContainer(); container.setInput(vd); container.setGenericMatch(generic); container.setScore(score); container.setAlgorithm(Algorithm.DOUBLE_METAPHONE); container.setParentPosition(i); container.setExactMatch(true); toKeep.add(container); break outer; } else { if (DEBUG) { MyLog.i(CLS_NAME, "Matches: double check JW: rejected"); } } } } } if (UtilsList.notNaked(toKeep)) { if (DEBUG) { MyLog.i(CLS_NAME, "Have a match"); } container = toKeep.get(0); } else { if (DEBUG) { MyLog.i(CLS_NAME, "no matches"); } } if (DEBUG) { MyLog.getElapsed(CLS_NAME, then); } return container; }
Example #9
Source File: AbstractNameImpl.java From openregistry with Apache License 2.0 | 4 votes |
protected final String generateSoundEx(final String comparison) { final DoubleMetaphone dmp = new DoubleMetaphone(); return dmp.encode(comparison); }
Example #10
Source File: ValueDataUtil.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public static String get_Double_Metaphone( ValueMetaInterface metaA, Object dataA ) { if ( dataA == null ) { return null; } return ( new DoubleMetaphone() ).doubleMetaphone( dataA.toString() ); }