From 539f3cbf221cb3c90ad6db45165c8421a3067b0f Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Mon, 19 May 2025 17:45:19 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=90=8C=E6=AD=A5balantflow=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E8=A7=86=E5=9B=BE=E6=95=B0=E6=8D=AE=E5=88=B0?= =?UTF-8?q?mongodb=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1421065807429632]增加一个同步balantflow自定义视图数据到mongodb接口 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1421065807429632 --- .../framework/util/HanyuPinyinUtil.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/main/java/neatlogic/framework/util/HanyuPinyinUtil.java diff --git a/src/main/java/neatlogic/framework/util/HanyuPinyinUtil.java b/src/main/java/neatlogic/framework/util/HanyuPinyinUtil.java new file mode 100644 index 000000000..71dc14753 --- /dev/null +++ b/src/main/java/neatlogic/framework/util/HanyuPinyinUtil.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2025 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.framework.util; + +import net.sourceforge.pinyin4j.PinyinHelper; +import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType; +import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; +import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; +import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; +import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination; + +public class HanyuPinyinUtil { + + public static String format(String source) { + HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat(); + format.setCaseType(HanyuPinyinCaseType.LOWERCASE); + format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);// 不带声调 + format.setVCharType(HanyuPinyinVCharType.WITH_V); + char[] ch = source.trim().toCharArray(); + StringBuffer buffer = new StringBuffer(""); + for (int i = 0; i < ch.length; i++) { + if (Character.toString(ch[i]).matches("[\u4e00-\u9fa5]")) { + String[] temp; + try { + temp = PinyinHelper.toHanyuPinyinStringArray(ch[i], format); + buffer.append(temp[0]); + } catch (BadHanyuPinyinOutputFormatCombination | NullPointerException e) { + // 无法翻译的生僻字,不必处理 + } + } else { + buffer.append(Character.toString(ch[i])); + } + } + return buffer.toString(); + } +} -- Gitee