• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DoubleMetaphone类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.commons.codec.language.DoubleMetaphone的典型用法代码示例。如果您正苦于以下问题:Java DoubleMetaphone类的具体用法?Java DoubleMetaphone怎么用?Java DoubleMetaphone使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DoubleMetaphone类属于org.apache.commons.codec.language包,在下文中一共展示了DoubleMetaphone类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;

}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:41,代码来源:SimilaritiesDist.java


示例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<>();
}
 
开发者ID:labsai,项目名称:EDDI,代码行数:9,代码来源:PhoneticCorrection.java


示例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));
	}
}
 
开发者ID:gentoku,项目名称:name-matcher,代码行数:12,代码来源:MatcherDoubleMetaphone.java


示例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));
}
 
开发者ID:gentoku,项目名称:name-matcher,代码行数:18,代码来源:MatcherDoubleMetaphone.java


示例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;
}
 
开发者ID:SQLPower,项目名称:power-matchmaker,代码行数:12,代码来源:DoubleMetaphoneMungeStep.java


示例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]);
    }
}
 
开发者ID:ManfredTremmel,项目名称:gwt-commons-codec,代码行数:19,代码来源:StringEncoderComparatorTest.java


示例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);
}
 
开发者ID:ManfredTremmel,项目名称:gwt-commons-codec,代码行数:10,代码来源:StringEncoderComparatorTest.java


示例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;
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:21,代码来源:FuzzyMatch.java


示例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;
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:78,代码来源:DoubleMetaphoneHelper.java


示例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;
}
 
开发者ID:brandall76,项目名称:Saiy-PS,代码行数:74,代码来源:DoubleMetaphoneHelper.java


示例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);
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:6,代码来源:StringDistance.java


示例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);
}
 
开发者ID:datjandra,项目名称:Daytripper,代码行数:42,代码来源:ResponderService.java


示例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());
}
 
开发者ID:icholy,项目名称:geokettle-2.0,代码行数:6,代码来源:ValueDataUtil.java


示例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;
  }
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:61,代码来源:FuzzyMatch.java


示例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);
}
 
开发者ID:Jasig,项目名称:openregistry,代码行数:5,代码来源:AbstractNameImpl.java


示例16: DoubleMetaphoneKeyer

import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
public DoubleMetaphoneKeyer() {
    _metaphone2 = new DoubleMetaphone();
    _metaphone2.setMaxCodeLen(2000);
}
 
开发者ID:dfci-cccb,项目名称:mev,代码行数:5,代码来源:DoubleMetaphoneKeyer.java


示例17: 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() );
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:7,代码来源:ValueDataUtil.java


示例18: hasSlotIsDoubleMetaphoneEqual

import org.apache.commons.codec.language.DoubleMetaphone; //导入依赖的package包/类
/**
 * Checks if a slot is contained in the intent request and has a value which is a
 * phonetic sibling of the string given to this method. Double metaphone algorithm
 * is optimized for English language and in this case is used to match slot value with
 * value given to this method.
 * @param slotName name of the slot to look after
 * @param value the value
 * @return True, if slot value and given value are phonetically equal with Double metaphone algorithm
 */
public boolean hasSlotIsDoubleMetaphoneEqual(final String slotName, final String value) {
    final String slotValue = getSlotValue(slotName);
    return hasSlotNotBlank(slotName) && value != null &&
            new DoubleMetaphone().isDoubleMetaphoneEqual(slotValue, value);
}
 
开发者ID:KayLerch,项目名称:alexa-skills-kit-tellask-java,代码行数:15,代码来源:AlexaInput.java



注:本文中的org.apache.commons.codec.language.DoubleMetaphone类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NodeProvisioner类代码示例发布时间:2022-05-21
下一篇:
Java AuthDescriptor类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap