起因:工作中发现同事做汉字提取对应拼音首字母时用到了一个包 HanLP,Gtihub:https://github.com/hankcs/HanLP ,记录下使用方式,深入研究留作以后(未完待续)
使用:
- 引入
<dependency>
<groupId>com.hankcs</groupId>
<artifactId>hanlp</artifactId>
<version>portable-1.7.5</version>
</dependency>
- 汉字拼音提取首字母
String pyIndex = HanLP.convertToPinyinList(“要拼音的汉字”).stream().map(pyItem -> String.valueOf(pyItem.getFirstChar())).collect(Collectors.joining("")).toUpperCase();