qzw1210 / jpinyin Goto Github PK
View Code? Open in Web Editor NEW拼音和汉字之间的转换、简体汉字和繁体汉字之间的转换
拼音和汉字之间的转换、简体汉字和繁体汉字之间的转换
好好学习 转不带声调的拼音 期望得到 "hao,hao,xue,xi"。得到的结果确实"hao,xue,xi"。
发现源码中有这么一句,就是这句去重复导致的
`
/**
* 将带声调格式的拼音转换为不带声调格式的拼音
*
* @param pinyinArrayString
* 带声调格式的拼音
* @return 不带声调的拼音
*/
private static String[] convertWithoutTone(String pinyinArrayString) {
String[] pinyinArray;
for (int i = ALL_MARKED_VOWEL.length() - 1; i >= 0; i--) {
char originalChar = ALL_MARKED_VOWEL.charAt(i);
char replaceChar = ALL_UNMARKED_VOWEL.charAt((i - i % 4) / 4);
pinyinArrayString = pinyinArrayString.replace(String.valueOf(originalChar), String.valueOf(replaceChar));
}
// 将拼音中的ü替换为v
pinyinArray = pinyinArrayString.replace("ü", "v").split(PINYIN_SEPARATOR);
// *****去掉声调后的拼音可能存在重复,做去重处理*****
LinkedHashSet<String> pinyinSet = new LinkedHashSet<String>();
for (String pinyin : pinyinArray) {
pinyinSet.add(pinyin);
}
return pinyinSet.toArray(new String[pinyinSet.size()]);
}
`
java
public class PinyinConvertChinese {
public static void main(String[] args) throws Exception {
String str = "好读书读好书好读书";
// hǎo,dú,shū,dú,hǎo,shū,hǎo,dú,shū
System.out.println(PinyinHelper.convertToPinyinString(str, ",", PinyinFormat.WITH_TONE_MARK));
}
}
打包成jar后,
resource下的文件是存在于jar这个文件里面,在磁盘上是没有真实路径存在,导致自定义字典无法读取
自定义字典目录:\src\main\resources\drug_mutil_pinyin.dic
调用方法如下:
@Test
void testAddMutilPinyinDict() throws IOException {
ClassPathResource resource = new ClassPathResource("drug_mutil_pinyin.dic");
PinyinHelper.addMutilPinyinDict(resource.getFile().getPath());
}
开发测试结果:无异常
打包后测试结果:
class path resource [drug_mutil_pinyin.dic] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/C:/dev/workspeace/java/demo/target/demo-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/drug_mutil_pinyin.dic
'角色'转换为拼音,正常输出应该是'jue,se',而不是'jiao se'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.