本文整理汇总了Java中org.apache.commons.codec.language.DoubleMetaphone类的典型用法代码示例。如果您正苦于以下问题:Java DoubleMetaphone类的具体用法?Java DoubleMetaphone怎么用?Java DoubleMetaphone使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DoubleMetaphone类属于org.apache.commons.codec.language包,在下文中一共展示了DoubleMetaphone类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compute
import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
/**
* Mesure de similarité.
*
* @param s
* @param t
* @return int
* as coefficient de similarité
*/
public double compute(String s1, String s2) {
if (s1 == null || s2 == null) {
throw new IllegalArgumentException("Strings must not be null");
}
double l = 0.0;
s1 = s1.toLowerCase();
s2 = s2.toLowerCase();
s1 = s1.replaceAll("[\\W]|_\\-", " "); //$NON-NLS-1$ //$NON-NLS-2$
s2 = s2.replaceAll("[\\W]|_\\-", " "); //$NON-NLS-1$ //$NON-NLS-2$
StringTokenizer tokenizer = new StringTokenizer(s1);
StringTokenizer tokenizer2 = new StringTokenizer(s2);
String s1dm = ""; //$NON-NLS-1$
DoubleMetaphone m = new DoubleMetaphone();
while (tokenizer.hasMoreTokens()) {
s1dm += m.doubleMetaphone(tokenizer.nextToken()) + " "; //$NON-NLS-1$
}
s1dm = s1dm.trim();
String s2dm = ""; //$NON-NLS-1$
while (tokenizer2.hasMoreTokens()) {
s2dm += m.doubleMetaphone(tokenizer2.nextToken()) + " "; //$NON-NLS-1$
}
s2dm = s2dm.trim();
l = longestSubstrSim(s1dm, s2dm);
DST_LOGGER.info(" Distance de similarité : " + l);
return 1 - l;
}
示例2: PhoneticCorrection
import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
public PhoneticCorrection(boolean lookupIfKnown) {
this.lookupIfKnown = lookupIfKnown;
refinedSoundex = new RefinedSoundex();
doubleMetaphone = new DoubleMetaphone();
metaphoneCodes = new HashMap<>();
soundexCodes = new HashMap<>();
}
示例3: match
import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
@Override
public boolean match(String a, String b) {
DoubleMetaphone dm = new DoubleMetaphone();
dm.setMaxCodeLen(MAX_LENGTH);
if (this.threshold < 1) {
return dm.isDoubleMetaphoneEqual(a, b);
} else {
Matcher m = new MatcherLevenshtein(this.threshold);
return m.match(dm.doubleMetaphone(a), dm.doubleMetaphone(b));
}
}
示例4: main
import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
public static void main(String[] args) {
String a;
String b;
String ma;
String mb;
MatcherDoubleMetaphone mdm0 = new MatcherDoubleMetaphone(0);
MatcherDoubleMetaphone mdm1 = new MatcherDoubleMetaphone(1);
DoubleMetaphone dm = new DoubleMetaphone();
dm.setMaxCodeLen(MAX_LENGTH);
a = "Manchester United";
b = "Nanchestar United"; // intentional two spelling mistakes, M -> N and e -> a
ma = dm.doubleMetaphone(a);
mb = dm.doubleMetaphone(b);
System.out.println(String.format("%s for [%s(%s)]=[%s(%s)]", mdm0.match(a, b), a, ma, b, mb));
System.out.println(String.format("%s for [%s(%s)]=[%s(%s)]", mdm1.match(a, b), a, ma, b, mb));
}
示例5: doCall
import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
public Boolean doCall() throws Exception {
MungeStepOutput<String> out = getOut();
MungeStepOutput<String> in = getMSOInputs().get(0);
String data = in.getData();
if (data != null) {
out.setData(new DoubleMetaphone().doubleMetaphone(data, isUseAlternate()));
} else {
out.setData(null);
}
return true;
}
示例6: testComparatorWithDoubleMetaphone
import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
@SuppressWarnings("unchecked") // cannot easily avoid this warning
@Test
public void testComparatorWithDoubleMetaphone() throws Exception {
final StringEncoderComparator sCompare = new StringEncoderComparator(new DoubleMetaphone());
final String[] testArray = { "Jordan", "Sosa", "Prior", "Pryor" };
final List<String> testList = Arrays.asList(testArray);
final String[] controlArray = { "Jordan", "Prior", "Pryor", "Sosa" };
Collections.sort(testList, sCompare); // unchecked
final String[] resultArray = testList.toArray(new String[0]);
for (int i = 0; i < resultArray.length; i++) {
assertEquals("Result Array not Equal to Control Array at index: " + i, controlArray[i], resultArray[i]);
}
}
示例7: testComparatorWithDoubleMetaphoneAndInvalidInput
import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
@Test
public void testComparatorWithDoubleMetaphoneAndInvalidInput() throws Exception {
final StringEncoderComparator sCompare =
new StringEncoderComparator( new DoubleMetaphone() );
final int compare = sCompare.compare(new Double(3.0), Long.valueOf(3));
assertEquals( "Trying to compare objects that make no sense to the underlying encoder should return a zero compare code",
0, compare);
}
示例8: getEncodedMF
import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
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;
}
示例9: executeCustomCommand
import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
/**
* 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;
}
示例10: executeGeneric
import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
/**
* 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;
}
示例11: StringDistance
import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
public StringDistance(String a, String b) {
DoubleMetaphone m = new DoubleMetaphone();
this.a = m.doubleMetaphone(a);
this.b = m.doubleMetaphone(b);
}
示例12: onHandleIntent
import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
Log.i(TAG, "onHandleIntent()");
String query = intent.getStringExtra(KEY_QUERY);
query = query.toLowerCase(Locale.getDefault()).replace("\'", "");
DoubleMetaphone encoder = new DoubleMetaphone();
Set<String> ngrams = StringUtils.extractNgrams(query, NGRAM_SIZE);
for (String segment : ngrams) {
String hash = encoder.encode(segment);
if (KEYWORD_HASHES.containsKey(hash)) {
query = query.replace(segment, KEYWORD_HASHES.get(hash));
break;
}
}
final Daytripper daytripper = (Daytripper) getApplicationContext();
final Chat chatSession = daytripper.getChatSession();
String response = chatSession.multisentenceRespond(query);
Intent broadcastIntent = new Intent();
broadcastIntent.setAction(RESPONSE_ACTION);
broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT);
String url = chatSession.predicates.get("url");
if (!TextUtils.isEmpty(url) && !url.equalsIgnoreCase("unknown")) {
chatSession.predicates.remove("url");
broadcastIntent.putExtra(EXTRA_URL_MESSAGE, url);
} else {
broadcastIntent.putExtra(EXTRA_CONTENT_MESSAGE, response);
}
String voice = chatSession.predicates.get(VOICE_FLAG);
if (!TextUtils.isEmpty(voice) && !voice.equalsIgnoreCase("unknown")) {
chatSession.predicates.remove(VOICE_FLAG);
broadcastIntent.putExtra(VOICE_FLAG, voice);
}
broadcastIntent.putExtra(EXTRA_TEXT_MESSAGE, Jsoup.parse(response).text());
LocalBroadcastManager.getInstance(this).sendBroadcast(broadcastIntent);
}
示例13: get_Double_Metaphone
import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
public static String get_Double_Metaphone(ValueMetaInterface metaA, Object dataA)
{
if(dataA==null) return null;
return (new DoubleMetaphone()).doubleMetaphone(dataA.toString());
}
示例14: doPhonetic
import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
private Object[] doPhonetic(Object[] row) {
// Reserve room
Object[] rowData = buildEmptyRow();
Iterator<Object[]> it = data.look.iterator();
String lookupValueMF=null;
Object o=row[data.indexOfMainField];
String lookupvalue=(String) o;
lookupValueMF=(new Metaphone()).metaphone(lookupvalue);
while (it.hasNext()){
// Get cached row data
Object[] cachedData = (Object[]) it.next();
// Key value is the first value
String cacheValue= (String) cachedData[0];
String cacheValueMF="";
switch (meta.getAlgorithmType()) {
case FuzzyMatchMeta.OPERATION_TYPE_METAPHONE:
cacheValueMF=(new Metaphone()).metaphone(cacheValue);
break;
case FuzzyMatchMeta.OPERATION_TYPE_DOUBLE_METAPHONE:
cacheValueMF=((new DoubleMetaphone()).doubleMetaphone(cacheValue));
break;
case FuzzyMatchMeta.OPERATION_TYPE_SOUNDEX:
cacheValueMF= (new Soundex()).encode(cacheValue);
break;
case FuzzyMatchMeta.OPERATION_TYPE_REFINED_SOUNDEX:
cacheValueMF=(new RefinedSoundex()).encode(cacheValue);
break;
default:
break;
}
if(lookupValueMF.equals(cacheValueMF)) {
// Add match value
int index=0;
rowData[index++]=cacheValue;
// Add metric value?
if(data.addValueFieldName) {
rowData[index++]= cacheValueMF;
}
// Add additional return values?
if(data.addAdditionalFields) {
for(int i=0; i<meta.getValue().length; i++) {
int nf=i+index;
int nr=i+1;
rowData[nf] = cachedData[nr];
}
}
}
}
return rowData;
}
示例15: generateSoundEx
import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
protected final String generateSoundEx(final String comparison) {
final DoubleMetaphone dmp = new DoubleMetaphone();
return dmp.encode(comparison);
}