/*
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org1.apache.commons.codec.language;
import org1.apache.commons.codec.EncoderException;
import org1.apache.commons.codec.StringEncoder;
/**
* Encodes a string into a double metaphone value.
* This Implementation is based on the algorithm by <CITE>Lawrence Philips</CITE>.
* <ul>
* <li>Original Article: <a
* href="http://www.cuj.com/documents/s=8038/cuj0006philips/">
* http://www.cuj.com/documents/s=8038/cuj0006philips/</a></li>
* <li>Original Source Code: <a href="ftp://ftp.cuj.com/pub/2000/1806/philips.zip">
* ftp://ftp.cuj.com/pub/2000/1806/philips.zip</a></li>
* </ul>
*
* @author Apache Software Foundation
* @version $Id: DoubleMetaphone.java,v 1.24 2004/06/05 18:32:04 ggregory Exp $
*/
public class DoubleMetaphone implements StringEncoder {
/**
* "Vowels" to test for
*/
private static final String VOWELS = "AEIOUY";
/**
* Prefixes when present which are not pronounced
*/
private static final String[] SILENT_START =
{ "GN", "KN", "PN", "WR", "PS" };
private static final String[] L_R_N_M_B_H_F_V_W_SPACE =
{ "L", "R", "N", "M", "B", "H", "F", "V", "W", " " };
private static final String[] ES_EP_EB_EL_EY_IB_IL_IN_IE_EI_ER =
{ "ES", "EP", "EB", "EL", "EY", "IB", "IL", "IN", "IE", "EI", "ER" };
private static final String[] L_T_K_S_N_M_B_Z =
{ "L", "T", "K", "S", "N", "M", "B", "Z" };
/**
* Maximum length of an encoding, default is 4
*/
protected int maxCodeLen = 4;
/**
* Creates an instance of this DoubleMetaphone encoder
*/
public DoubleMetaphone() {
super();
}
/**
* Encode a value with Double Metaphone
*
* @param value String to encode
* @return an encoded string
*/
public String doubleMetaphone(String value) {
return doubleMetaphone(value, false);
}
/**
* Encode a value with Double Metaphone, optionally using the alternate
* encoding.
*
* @param value String to encode
* @param alternate use alternate encode
* @return an encoded string
*/
public String doubleMetaphone(String value, boolean alternate) {
value = cleanInput(value);
if (value == null) {
return null;
}
boolean slavoGermanic = isSlavoGermanic(value);
int index = isSilentStart(value) ? 1 : 0;
DoubleMetaphoneResult result = new DoubleMetaphoneResult(this.getMaxCodeLen());
while (!result.isComplete() && index <= value.length() - 1) {
switch (value.charAt(index)) {
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'Y':
index = handleAEIOUY(value, result, index);
break;
case 'B':
result.append('P');
index = charAt(value, index + 1) == 'B' ? index + 2 : index + 1;
break;
case '\u00C7':
// A C with a Cedilla
result.append('S');
index++;
break;
case 'C':
index = handleC(value, result, index);
break;
case 'D':
index = handleD(value, result, index);
break;
case 'F':
result.append('F');
index = charAt(value, index + 1) == 'F' ? index + 2 : index + 1;
break;
case 'G':
index = handleG(value, result, index, slavoGermanic);
break;
case 'H':
index = handleH(value, result, index);
break;
case 'J':
index = handleJ(value, result, index, slavoGermanic);
break;
case 'K':
result.append('K');
index = charAt(value, index + 1) == 'K' ? index + 2 : index + 1;
break;
case 'L':
index = handleL(value, result, index);
break;
case 'M':
result.append('M');
index = conditionM0(value, index) ? index + 2 : index + 1;
break;
case 'N':
result.append('N');
index = charAt(value, index + 1) == 'N' ? index + 2 : index + 1;
break;
case '\u00D1':
// N with a tilde (spanish ene)
result.append('N');
index++;
break;
case 'P':
index = handleP(value, result, index);
break;
case 'Q':
result.append('K');
index = charAt(value, index + 1) == 'Q' ? index + 2 : index + 1;
break;
case 'R':
index = handleR(value, result, index, slavoGermanic);
break;
case 'S':
index = handleS(value, result, index, slavoGermanic);
break;
case 'T':
index = handleT(value, result, index);
break;
case 'V':
result.append('F');
index = charAt(value, index + 1) == 'V' ? index + 2 : index + 1;
break;
case 'W':
index = handleW(value, result, index);
break;
case 'X':
index = handleX(value, result, index);
break;
case 'Z':
index = handleZ(value, result, index, slavoGermanic);
break;
default:
index++;
break;
}
}
return alternate ? result.getAlternate() : result.getPrimary();
}
/**
* Encode the value using DoubleMetaphone. It will only work if
* <code>obj</code> is a <code>String</code> (like <code>Metaphone</code>).
*
* @param obj Object to encode (should be of type String)
* @return An encoded Object (will be of type String)
* @throws EncoderException encode parameter is not of type String
*/
public Object encode(Object obj) throws EncoderException {
if (!(obj instanceof String)) {
throw new EncoderException("DoubleMetaphone encode parameter is not of type String");
}
return doubleMetaphone((String) obj);
}
/**
* Encode the value using DoubleMetaphone.
*
* @param value String to encode
* @return An encoded String
*/
public String encode(String value) {
return doubleMetaphone(value);
}
/**
* Check if the Double Metaphone values of two <code>String</code> values
* are equal.
*
* @param value1 The left-hand side of the encoded {@link String#equals(Object)}.
* @param value2 The right-hand side of the encoded {@link String#equals(Object)}.
* @return <code>true</code> if the encoded <code>String</code>s are equal;
* <code>false</code> otherwise.
* @see #isDoubleMetaphoneEqual(String,String,boolean)
没有合适的资源?快使用搜索试试~ 我知道了~
Android 豆瓣网 源代码
共132个文件
java:91个
class:18个
html:6个
5星 · 超过95%的资源 需积分: 19 162 下载量 80 浏览量
2010-07-25
20:18:55
上传
评论
收藏 1.18MB RAR 举报
温馨提示
了解web2.0 API 开发WEB2.0手机客户端应用程序 Android系统和标准的Web2.0网站交互 Web2.0的OAUTH认证 还可以学习下web2.0应用设计流程
资源推荐
资源详情
资源评论
收起资源包目录
Android 豆瓣网 源代码 (132个子文件)
resources.ap_ 9KB
douban_android.apk 254KB
ActivityShowSaying.class 4KB
ActivityAuthSuccess.class 4KB
ActivityShowSaying$SayingListAdapter.class 3KB
ActivityMain.class 3KB
ActivityAuth.class 3KB
ActivityShowSaying$SayingView.class 3KB
ActivityShowSaying$1.class 2KB
AbstractActivity.class 1KB
ActivityMain$1.class 1KB
ActivityShowSaying$Saying.class 772B
PreferencesUtil.class 655B
DoubanUtil.class 576B
R.class 531B
R$id.class 448B
R$drawable.class 436B
R$layout.class 429B
R$string.class 427B
R$attr.class 340B
.classpath 454B
classes.dex 586KB
package.html 3KB
overview.html 1022B
package.html 708B
package.html 704B
package.html 696B
package.html 674B
gdata-core-1.0.jar 457KB
lib.jar 141KB
gdata-client-1.0.jar 61KB
DoubleMetaphone.java 39KB
DoubanService.java 32KB
Base64.java 18KB
OAuthMessage.java 15KB
QuotedPrintableCodec.java 15KB
Metaphone.java 14KB
OAuthClient.java 13KB
URLCodec.java 12KB
OAuth.java 11KB
OAuthSignatureMethod.java 11KB
BinaryCodec.java 10KB
QCodec.java 10KB
RSA_SHA1.java 10KB
Soundex.java 10KB
Hex.java 7KB
BCodec.java 7KB
RefinedSoundex.java 6KB
RFC1522Codec.java 6KB
ActivityShowSaying.java 6KB
HttpMethodResponse.java 5KB
URLConnectionResponse.java 5KB
HttpClient4.java 5KB
HttpMessage.java 5KB
ConsumerProperties.java 5KB
Subject.java 5KB
DigestUtils.java 4KB
URLConnectionClient.java 4KB
SoundexUtils.java 4KB
SimpleOAuthValidator.java 4KB
OAuthProblemException.java 3KB
HMAC_SHA1.java 3KB
HttpMessageDecoder.java 3KB
Tag.java 3KB
OAuthResponseMessage.java 3KB
StringEncoderComparator.java 3KB
ActivityAuthSuccess.java 2KB
OAuthAccessor.java 2KB
Attribute.java 2KB
Namespaces.java 2KB
CollectionEntry.java 2KB
Decoder.java 2KB
OAuthConsumer.java 2KB
ActivityMain.java 2KB
HttpResponseMessage.java 2KB
PLAINTEXT.java 2KB
StringEncodings.java 2KB
SubjectQuery.java 2KB
Encoder.java 2KB
ActivityAuth.java 2KB
CollectionQuery.java 2KB
ReviewQuery.java 2KB
UserEntry.java 1KB
DoubanQuery.java 1KB
SubjectEntry.java 1KB
OAuthValidator.java 1KB
Location.java 1KB
ReviewEntry.java 1KB
BinaryDecoder.java 1KB
EncoderException.java 1KB
BinaryEncoder.java 1KB
TagQuery.java 1KB
ExcerptInputStream.java 1KB
OAuthServiceProvider.java 1KB
OAuthException.java 1KB
StringEncoder.java 1KB
StringDecoder.java 1KB
HttpClient.java 1KB
AbstractFreeTextExtension.java 1KB
DecoderException.java 1KB
共 132 条
- 1
- 2
资源评论
- 蝶化魂2014-05-18十分的不错的.....
- Manzil_112014-07-21代码有些看不懂啊
- 半世疯癫2014-01-06还不错,不过要修改部分源码,不然会崩溃
- doushi72013-08-10用处还是蛮多的。谢谢分享
- 谦卑好学2014-06-07真的很不错。哈哈
JXES智能生态系统
- 粉丝: 1w+
- 资源: 191
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Python 版冒泡排序算法源代码
- tensorflow-gpu-2.7.2-cp38-cp38-manylinux2010-x86-64.whl
- tensorflow-2.7.3-cp39-cp39-manylinux2010-x86-64.whl
- tensorflow-2.7.2-cp39-cp39-manylinux2010-x86-64.whl
- Python版本快速排序源代码
- Python 语言版的快速排序算法实现
- 450815388207377安卓_base.apk
- 超微主板 X9DRE-TF+ bios 支持 nvme启动
- 基于Python通过下载气象数据和插值拟合离散数据曲线实现对寒潮过程的能量分析
- 智能车仿真软件.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功