org.apache.commons.codec.language.Metaphone类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(178)

本文整理了Java中org.apache.commons.codec.language.Metaphone类的一些代码示例,展示了Metaphone类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metaphone类的具体详情如下:
包路径:org.apache.commons.codec.language.Metaphone
类名称:Metaphone

Metaphone介绍

[英]Encodes a string into a metaphone value.

Initial Java implementation by William B. Brogden. December, 1997. Permission given by wbrogden for code to be used anywhere.

Hanging on the Metaphone by Lawrence Philips in Computer Language of Dec. 1990, p 39.
[中]将字符串编码为变音值。
最初的Java实现由William B.Brogden完成。1997年12月。wbrogden授予代码在任何地方使用的权限。
挂在Lawrence Philips 1990年12月计算机语言的变音上,第39页。

代码示例

代码示例来源:origin: commons-codec/commons-codec

/**
 * Encodes a String using the Metaphone algorithm.
 *
 * @param str String object to encode
 * @return The metaphone code corresponding to the String supplied
 */
@Override
public String encode(final String str) {
  return metaphone(str);
}

代码示例来源:origin: commons-codec/commons-codec

while (code.length() < this.getMaxCodeLen() &&
  if (symb != 'C' && isPreviousChar( local, n, symb ) ) {
    n++;
  } else { // not dup
      if ( isPreviousChar(local, n, 'M') &&
         isLastChar(wdsz, n) ) { // B is silent if word ends in MB
        break;
      if ( isPreviousChar(local, n, 'S') &&
         !isLastChar(wdsz, n) &&
         FRONTV.indexOf(local.charAt(n + 1)) >= 0 ) {
        break;
      if (regionMatch(local, n, "CIA")) { // "CIA" -> X
        code.append('X');
        break;
      if (!isLastChar(wdsz, n) &&
        FRONTV.indexOf(local.charAt(n + 1)) >= 0) {
        code.append('S');
        break; // CI,CE,CY -> S
      if (isPreviousChar(local, n, 'S') &&
        isNextChar(local, n, 'H') ) { // SCH->sk
        code.append('K');
        break;

代码示例来源:origin: pentaho/pentaho-kettle

public static String get_Metaphone( ValueMetaInterface metaA, Object dataA ) {
 if ( dataA == null ) {
  return null;
 }
 return ( new Metaphone() ).metaphone( dataA.toString() );
}

代码示例来源:origin: commons-codec/commons-codec

@Test
public void testSetMaxLengthWithTruncation() {
  // should be AKSKS, but istruncated by Max Code Length
  this.getStringEncoder().setMaxCodeLen( 6 );
  assertEquals( "AKSKSK", this.getStringEncoder().metaphone("AXEAXEAXE") );
}

代码示例来源:origin: commons-codec/commons-codec

@Override
protected Metaphone createStringEncoder() {
  return new Metaphone();
}

代码示例来源:origin: stackoverflow.com

Metaphone meta = new Metaphone();
meta.setMaxCodeLen(8);
System.out.println(meta.isMetaphoneEqual("cricket","criket"));
System.out.println(meta.isMetaphoneEqual("cricket","criketgame"));

代码示例来源:origin: Simmetrics/simmetrics

@Override
public String toString() {
  return "Metaphone [maxCodeLen=" + simplifier.getMaxCodeLen() + "]";
}

代码示例来源:origin: Simmetrics/simmetrics

/**
 * Creates an instance of the Metaphone simplifier with a
 * {@code maxCodeLength}. All encodings will have at most
 * {@code maxCodeLength} characters.
 * 
 * @param maxCodeLength
 *            maximum length of the encoding
 */
public Metaphone(int maxCodeLength) {
  this.simplifier = new org.apache.commons.codec.language.Metaphone();
  this.simplifier.setMaxCodeLen(maxCodeLength);
}

代码示例来源:origin: dkpro/dkpro-core

public MetaphonePhoneticTranscriptor()
  {
    this.encoder = new Metaphone();
  }
}

代码示例来源:origin: robovm/robovm

while ((code.length() < this.getMaxCodeLen()) && 
  if ((symb != 'C') && (isPreviousChar( local, n, symb )) ) {
    n++ ;
  } else { // not dup
      if ( isPreviousChar(local, n, 'M') && 
         isLastChar(wdsz, n) ) { // B is silent if word ends in MB
        break;
      if ( isPreviousChar(local, n, 'S') && 
         !isLastChar(wdsz, n) && 
         (this.frontv.indexOf(local.charAt(n + 1)) >= 0) ) { 
        break;
      if (regionMatch(local, n, "CIA")) { // "CIA" -> X
        code.append('X'); 
        break;
      if (!isLastChar(wdsz, n) && 
        (this.frontv.indexOf(local.charAt(n + 1)) >= 0)) {
        code.append('S');
        break; // CI,CE,CY -> S
      if (isPreviousChar(local, n, 'S') &&
        isNextChar(local, n, 'H') ) { // SCH->sk
        code.append('K') ; 
        break ;

代码示例来源:origin: commons-codec/commons-codec

/**
 * Tests is the metaphones of two strings are identical.
 *
 * @param str1 First of two strings to compare
 * @param str2 Second of two strings to compare
 * @return <code>true</code> if the metaphones of these strings are identical,
 *        <code>false</code> otherwise.
 */
public boolean isMetaphoneEqual(final String str1, final String str2) {
  return metaphone(str1).equals(metaphone(str2));
}

代码示例来源:origin: apache/drill

@Override
public void eval() {
 String input = org.apache.drill.exec.expr.fn.impl.StringFunctionHelpers.toStringFromUTF8(rawInput.start, rawInput.end, rawInput.buffer);
 String outputString = new org.apache.commons.codec.language.Metaphone().metaphone(input);
 out.buffer = buffer;
 out.start = 0;
 out.end = outputString.getBytes().length;
 buffer.setBytes(0, outputString.getBytes());
}

代码示例来源:origin: dkpro/dkpro-similarity

public MetaphoneComparator()
{
  encoder = new Metaphone();
}

代码示例来源:origin: ibinti/bugvm

while (code.length() < this.getMaxCodeLen() &&
  if (symb != 'C' && isPreviousChar( local, n, symb ) ) {
    n++;
  } else { // not dup
      if ( isPreviousChar(local, n, 'M') &&
         isLastChar(wdsz, n) ) { // B is silent if word ends in MB
        break;
      if ( isPreviousChar(local, n, 'S') &&
         !isLastChar(wdsz, n) &&
         FRONTV.indexOf(local.charAt(n + 1)) >= 0 ) {
        break;
      if (regionMatch(local, n, "CIA")) { // "CIA" -> X
        code.append('X');
        break;
      if (!isLastChar(wdsz, n) &&
        FRONTV.indexOf(local.charAt(n + 1)) >= 0) {
        code.append('S');
        break; // CI,CE,CY -> S
      if (isPreviousChar(local, n, 'S') &&
        isNextChar(local, n, 'H') ) { // SCH->sk
        code.append('K');
        break;

代码示例来源:origin: robovm/robovm

/**
 * Encodes a String using the Metaphone algorithm. 
 *
 * @param pString String object to encode
 * @return The metaphone code corresponding to the String supplied
 */
public String encode(String pString) {
  return metaphone(pString);   
}

代码示例来源:origin: pentaho/pentaho-kettle

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;
}

代码示例来源:origin: stackoverflow.com

public MetaphoneDistance() {
  Metaphone metaphone = new Metaphone();
}

//I'm not really familiar with the library you mentioned, but I assume generateKeys performs a double metaphone?
public float getDistance(String str1, ,String str2) {
  String[] keys1 = metaphone.getKeys(str1);  
  String[] keys2 = metaphone.getKeys(str2);
  float result = 0;
  if (key1[0] == key2[0] || key1[0] == key2[1]) result += .5
  if (key1[1] == key2[0] || key1[1] == key2[1]) result += .5
  return result;
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

while ((code.length() < this.getMaxCodeLen()) && 
  if ((symb != 'C') && (isPreviousChar( local, n, symb )) ) {
    n++ ;
  } else { // not dup
      if ( isPreviousChar(local, n, 'M') && 
         isLastChar(wdsz, n) ) { // B is silent if word ends in MB
        break;
      if ( isPreviousChar(local, n, 'S') && 
         !isLastChar(wdsz, n) && 
         (this.frontv.indexOf(local.charAt(n + 1)) >= 0) ) { 
        break;
      if (regionMatch(local, n, "CIA")) { // "CIA" -> X
        code.append('X'); 
        break;
      if (!isLastChar(wdsz, n) && 
        (this.frontv.indexOf(local.charAt(n + 1)) >= 0)) {
        code.append('S');
        break; // CI,CE,CY -> S
      if (isPreviousChar(local, n, 'S') &&
        isNextChar(local, n, 'H') ) { // SCH->sk
        code.append('K') ; 
        break ;

代码示例来源:origin: robovm/robovm

/**
 * Tests is the metaphones of two strings are identical.
 *
 * @param str1 First of two strings to compare
 * @param str2 Second of two strings to compare
 * @return true if the metaphones of these strings are identical, 
 *         false otherwise.
 */
public boolean isMetaphoneEqual(String str1, String str2) {
  return metaphone(str1).equals(metaphone(str2));
}

代码示例来源:origin: org.apache.directory.api/api-ldap-client-all

while (code.length() < this.getMaxCodeLen() &&
  if (symb != 'C' && isPreviousChar( local, n, symb ) ) {
    n++;
  } else { // not dup
      if ( isPreviousChar(local, n, 'M') &&
         isLastChar(wdsz, n) ) { // B is silent if word ends in MB
        break;
      if ( isPreviousChar(local, n, 'S') &&
         !isLastChar(wdsz, n) &&
         FRONTV.indexOf(local.charAt(n + 1)) >= 0 ) {
        break;
      if (regionMatch(local, n, "CIA")) { // "CIA" -> X
        code.append('X');
        break;
      if (!isLastChar(wdsz, n) &&
        FRONTV.indexOf(local.charAt(n + 1)) >= 0) {
        code.append('S');
        break; // CI,CE,CY -> S
      if (isPreviousChar(local, n, 'S') &&
        isNextChar(local, n, 'H') ) { // SCH->sk
        code.append('K');
        break;

相关文章