org.apache.commons.codec.language.Metaphone.metaphone()方法的使用及代码示例

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

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

Metaphone.metaphone介绍

[英]Find the metaphone value of a String. This is similar to the soundex algorithm, but better at finding similar sounding words. All input is converted to upper case. Limitations: Input format is expected to be a single ASCII word with only characters in the A - Z range, no punctuation or numbers.
[中]查找字符串的变音值。这与soundex算法类似,但在查找类似发音的单词时效果更好。所有输入都转换为大写。限制:输入格式应该是一个ASCII字,只有a-Z范围内的字符,没有标点或数字。

代码示例

代码示例来源: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

/**
 * 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: 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

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

/**
 * Encodes an Object using the metaphone algorithm.  This method
 * is provided in order to satisfy the requirements of the
 * Encoder interface, and will throw an EncoderException if the
 * supplied object is not of type java.lang.String.
 *
 * @param obj Object to encode
 * @return An object (or type java.lang.String) containing the
 *         metaphone code which corresponds to the String supplied.
 * @throws EncoderException if the parameter supplied is not
 *                          of type java.lang.String
 */
@Override
public Object encode(final Object obj) throws EncoderException {
  if (!(obj instanceof String)) {
    throw new EncoderException("Parameter supplied to Metaphone encode is not of type java.lang.String");
  }
  return metaphone((String) obj);
}

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

@Test
public void testWordEndingInMB() {
  assertEquals( "KM", this.getStringEncoder().metaphone("COMB") );
  assertEquals( "TM", this.getStringEncoder().metaphone("TOMB") );
  assertEquals( "WM", this.getStringEncoder().metaphone("WOMB") );
}

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

@Test
public void testDiscardOfSCEOrSCIOrSCY() {
  assertEquals( "SNS", this.getStringEncoder().metaphone("SCIENCE") );
  assertEquals( "SN", this.getStringEncoder().metaphone("SCENE") );
  assertEquals( "S", this.getStringEncoder().metaphone("SCY") );
}

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

@Test
public void testMetaphone() {
  assertEquals("HL", this.getStringEncoder().metaphone("howl"));
  assertEquals("TSTN", this.getStringEncoder().metaphone("testing"));
  assertEquals("0", this.getStringEncoder().metaphone("The"));
  assertEquals("KK", this.getStringEncoder().metaphone("quick"));
  assertEquals("BRN", this.getStringEncoder().metaphone("brown"));
  assertEquals("FKS", this.getStringEncoder().metaphone("fox"));
  assertEquals("JMPT", this.getStringEncoder().metaphone("jumped"));
  assertEquals("OFR", this.getStringEncoder().metaphone("over"));
  assertEquals("0", this.getStringEncoder().metaphone("the"));
  assertEquals("LS", this.getStringEncoder().metaphone("lazy"));
  assertEquals("TKS", this.getStringEncoder().metaphone("dogs"));
}

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

@Test
public void testTranslateOfSCHAndCH() {
  assertEquals( "SKTL", this.getStringEncoder().metaphone("SCHEDULE") );
  assertEquals( "SKMT", this.getStringEncoder().metaphone("SCHEMATIC") );
  assertEquals( "KRKT", this.getStringEncoder().metaphone("CHARACTER") );
  assertEquals( "TX", this.getStringEncoder().metaphone("TEACH") );
}

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

@Test
public void testTranslateToJOfDGEOrDGIOrDGY() {
  assertEquals( "TJ", this.getStringEncoder().metaphone("DODGY") );
  assertEquals( "TJ", this.getStringEncoder().metaphone("DODGE") );
  assertEquals( "AJMT", this.getStringEncoder().metaphone("ADGIEMTI") );
}

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

@Test
public void testSHAndSIOAndSIAToX() {
  assertEquals( "XT", this.getStringEncoder().metaphone("SHOT") );
  assertEquals( "OTXN", this.getStringEncoder().metaphone("ODSIAN") );
  assertEquals( "PLXN", this.getStringEncoder().metaphone("PULSION") );
}

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

@Test
public void testDiscardOfSilentGN() {
  // NOTE: This does not test for silent GN, but for starting with GN
  assertEquals( "N", this.getStringEncoder().metaphone("GNU") );
  // NOTE: Trying to test for GNED, but expected code does not appear to execute
  assertEquals( "SNT", this.getStringEncoder().metaphone("SIGNED") );
}

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

@Test
public void testDiscardOfSilentHAfterG() {
  assertEquals( "KNT", this.getStringEncoder().metaphone("GHENT") );
  assertEquals( "B", this.getStringEncoder().metaphone("BAUGH") );
}

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

@Test
public void testTIOAndTIAToX() {
  assertEquals( "OX", this.getStringEncoder().metaphone("OTIA") );
  assertEquals( "PRXN", this.getStringEncoder().metaphone("PORTION") );
}

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

@Test
public void testTCH() {
  assertEquals( "RX", this.getStringEncoder().metaphone("RETCH") );
  assertEquals( "WX", this.getStringEncoder().metaphone("WATCH") );
}

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

/**
 * Tests (CODEC-57) Metaphone.metaphone(String) returns an empty string when passed the word "why"
 */
@Test
public void testWhy() {
  // PHP returns "H". The original metaphone returns an empty string.
  assertEquals("", this.getStringEncoder().metaphone("WHY"));
}

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

@Test
public void testExceedLength() {
  // should be AKSKS, but istruncated by Max Code Length
  assertEquals( "AKSK", this.getStringEncoder().metaphone("AXEAXE") );
}

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

@Test
public void testWordsWithCIA() {
  assertEquals( "XP", this.getStringEncoder().metaphone("CIAPO") );
}

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

@Test
public void testPHTOF() {
  assertEquals( "FX", this.getStringEncoder().metaphone("PHISH") );
}

代码示例来源: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") );
}

相关文章