主要是搜索引擎用到的
比如,you are a nice girl
会被分为 you|are|a|nice girl|
比如,you are a nice girl
会被分为 you|are|a|nice girl|
解决方案 »
- C# DataGridView数据导出到Excel模板
- 求一正则表达式
- 急急急急急(tableLayoutPanel1;怎么把tableLayoutPanel1的第二行设置为1)
- 如下的c++代码在c#中如何声明和传递?
- C#中对SQL数据库操作问题 如何使时间做到最快
- 什么是“windows用户体验”?
- Winform 自定义控件的右键菜单的问题
- 如何获取文件完整路径
- 如何搜索数据库字段名
- 帮朋友咨询一个问题,IE安全性的问题!!请大家发表见解!!
- System.Reflection.TargetParameterCountException”类型的异常 参数计数不匹配 请问谁遇过这个问题
- notifyIcon1.Icon = imageList1.Images[1]; 求这个正确的写法
* 分词
*
* @param source
* 待分的字符串
* @return String[]
*/
public String[] fenci(String source) {
/* 分隔符的集合 */
String delimiters = " \t\n\r\f~!@#$%^&*()_ |`1234567890-=\\{}[]:\";'<>?,./'";/* 根据分隔符分词 */
StringTokenizer stringTokenizer = new StringTokenizer(source,
delimiters);
Vector vector = new Vector();/* 根据大写首字母分词 */
while (stringTokenizer.hasMoreTokens()) {
String token = stringTokenizer.nextToken();
int index = 0;
flag1: while (index < token.length()) {
flag2: while (true) {
index ;
if ((index == token.length())
|| !Character.isLowerCase(token.charAt(index))) {
break flag2;
}
}
vector.addElement(token.substring(0, index));
//System.out.println("识别出" token.substring(0, index));
token = token.substring(index);
//System.out.println("剩余" token);
index = 0;
continue flag1;
}
}/*
* 复数转单数 参考以下文档:
* http://ftp.haie.edu.cn/Resource/GZ/GZYY/DCYFWF/NJSYYY/421b0061ZW_0015.htm
*/
for (int i = 0; i < vector.size(); i ) {
String token = (String) vector.elementAt(i);
if (token.equalsIgnoreCase("feet")) {
token = "foot";
} else if (token.equalsIgnoreCase("geese")) {
token = "goose";
} else if (token.equalsIgnoreCase("lice")) {
token = "louse";
} else if (token.equalsIgnoreCase("mice")) {
token = "mouse";
} else if (token.equalsIgnoreCase("teeth")) {
token = "tooth";
} else if (token.equalsIgnoreCase("oxen")) {
token = "ox";
} else if (token.equalsIgnoreCase("children")) {
token = "child";
} else if (token.endsWith("men")) {
token = token.substring(0, token.length() - 3) "man";
} else if (token.endsWith("ies")) {
token = token.substring(0, token.length() - 3) "y";
} else if (token.endsWith("ves")) {
if (token.equalsIgnoreCase("knives")
|| token.equalsIgnoreCase("wives")
|| token.equalsIgnoreCase("lives")) {
token = token.substring(0, token.length() - 3) "fe";
} else {
token = token.substring(0, token.length() - 3) "f";
}
} else if (token.endsWith("oes") || token.endsWith("ches")
|| token.endsWith("shes") || token.endsWith("ses")
|| token.endsWith("xes")) {
token = token.substring(0, token.length() - 2);
} else if (token.endsWith("s")) {
token = token.substring(0, token.length() - 1);
}/* 处理完毕 */
vector.setElementAt(token, i);
}/* 转为数组形式 */
String[] array = new String[vector.size()];
Enumeration enumeration = vector.elements();
int index = 0;
while (enumeration.hasMoreElements()) {
array[index] = (String) enumeration.nextElement();
index ;
}/* 打印显示 */
for (int i = 0; i < array.length; i ) {
System.out.println(array[i]);
}/* 返回 */
return array;
}
看看Speech API吧,DotNET下现在也有包装了。