ChineseUtils
这里获得汉字的拼音使用了pinyin4j这个插件,因为多音字的原因效果并不理想
/**
* 获得汉字拼音
* @param name
* @return
*/
@SuppressWarnings("deprecation")
public static String getPiYin(String src) {
HanyuPinyinOutputFormat outFormat = new HanyuPinyinOutputFormat();
outFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
outFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
outFormat.setVCharType(HanyuPinyinVCharType.WITH_V);
try {
return PinyinHelper.toHanyuPinyinString(src, outFormat, "");
} catch (BadHanyuPinyinOutputFormatCombination e1) {
e1.printStackTrace();
return src;
}
} /**
* 获得拼音首字母
* @param name
* @return
*/
public static String getPinYinFirstLetter(String name){
char[] str=StringUtils.defaultIfEmpty(name, "").toCharArray();
String shouZiMu="";
for ( char string : str) {
shouZiMu+=getPiYin(String.valueOf(string)).charAt(0);
}
return shouZiMu;
} public boolean isChinese(char c) {
Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
return true;
}
return false;
} public boolean isChinese(String s) {
return s.matches("[\\u4E00-\\u9FA5]+");
}
ChineseUtils的更多相关文章
- word2vec训练&IC分词(待)
参考http://www.52nlp.cn/%E4%B8%AD%E8%8B%B1%E6%96%87%E7%BB%B4%E5%9F%BA%E7%99%BE%E7%A7%91%E8%AF%AD%E6%96 ...
- Java字符串中文检测转换
public class ChineseUtils { public static void main(String[] args) { String str = "中国 (1).jpg&q ...
随机推荐
- thinkphp5.0 文章详情页 上一篇 下一篇
// 上一篇下一篇(同一个分类下,先确定该分类的pid) public function frontAfter() { $param=$this->param; $front=Db::name( ...
- 阿里云邮箱POP3、SMTP设置教程
3G免费网www.3gmfw.cn免费为你分享阿里云邮箱POP3.SMTP设置教程,阿里云邮箱 阿里云邮箱POP3设置 阿里云邮箱SMTP设置的相关资源如下: 什么是POP3.SMTP? 阿里云邮箱已 ...
- 常用排序算法java实现
写在前面:纸上得来终觉浅.基本排序算法的思想,可能很多人都说的头头是到,但能说和能写出来,真的还是有很大区别的. 今天整理了一下各种常用排序算法,当然还不全,后面会继续补充.代码中可能有累赘或错误的地 ...
- javascript之this
全局作用域的this this == window //true this.a = 8 window.a 一般函数的this function thisTest(){ return this; } t ...
- 有关linux下redis overcommit_memory的问题
公司的几台Redis服务器出现不明故障,查看Redis日志,发现如下提示: 1 [34145] 01 Jan 17:42:02 # WARNING overcommit_memory is set t ...
- Intellij-创建Maven项目速度慢
原因: IDEA根据maven archetype的本质,其实是执行mvn archetype:generate命令,该命令执行时,需要指定一个archetype-catalog.xml文件. 该命令 ...
- python3 第九章 - 数据类型之Number(数字)
Python 支持三种不同的数字类型: 整型(Int) - 通常被称为是整型或整数,是正或负整数,不带小数点.Python3 整型是没有限制大小的,可以当作 Long 类型使用,所以 Python3 ...
- 一个自己稍作修改了的美赛论文LaTeX模板
原模板(5.0)来自LaTeX工作室(latexstudio.net),我按照比赛规范做了一点小小的修改(5.0y),并加上了比原来更详细一些的注释,方便使用. 仅仅分享一下方便大家使用,模板的原创者 ...
- sed替换文本
[root@localhost.localdomain home]#cat test ### @2=1492785988 /* INT meta=0 nullable=0 is_null=0 */ # ...
- Codeforce A. Fair Game
A. Fair Game time limit per test 1 second memory limit per test 256 megabytes input standard input o ...