介绍一个功能,可以把汉语转化成拼音,包括全拼和首字母,甚至可以带音调。
大家可以去http://pinyin4j.sourceforge.net/ 看看,下载支持jar包:pinyin4j-2.5.0.jar。
我也是看的demo,大家可以把下面的代码运行看看。
1/** *//**
2 * This file is part of pinyin4j (http://sourceforge.net/projects/pinyin4j/)
3 * and distributed under GNU GENERAL PUBLIC LICENSE (GPL).
4 *
5 * pinyin4j is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * pinyin4j is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with pinyin4j.
17 */
18
19package pinyin;
20
21import java.awt.BorderLayout;
22import java.awt.Dimension;
23import java.awt.Font;
24import java.awt.GridLayout;
25import java.awt.event.WindowAdapter;
26import java.awt.event.WindowEvent;
27
28import javax.swing.JApplet;
29import javax.swing.JButton;
30import javax.swing.JComboBox;
31import javax.swing.JFrame;
32import javax.swing.JLabel;
33import javax.swing.JPanel;
34import javax.swing.JScrollPane;
35import javax.swing.JTabbedPane;
36import javax.swing.JTextArea;
37import javax.swing.JTextField;
38
39import net.sourceforge.pinyin4j.PinyinHelper;
40import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
41import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
42import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
43import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
44import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
45
46/** *//**
47 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
48 * Builder, which is free for non-commercial use. If Jigloo is being used
49 * commercially (ie, by a corporation, company or business for any purpose
50 * whatever) then you should purchase a license for each developer using Jigloo.
51 * Please visit www.cloudgarden.com for details. Use of Jigloo implies
52 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
53 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
54 * ANY CORPORATE OR COMMERCIAL PURPOSE.
55 */
56/** *//**
57 * A demo show the functions of pinyin4j library
58 *
59 * @author Li Min (xmlerlimin@gmail.com)
60 *
61 */
62public class Pinyin4jAppletDemo extends JApplet
63{
64 private static final Dimension APP_SIZE = new Dimension(600, 400);
65
66 private static final long serialVersionUID = -1934962385592030162L;
67
68 private JPanel jContentPane = null;
69
70 private JTabbedPane jTabbedPane = null;
71
72 private JPanel formattedCharPanel = null;
73
74 private JPanel optionPanel = null;
75
76 private JButton convertButton = null;
77
78 private JPanel buttonPanel = null;
79
80 private JTextArea formattedOutputField = null;
81
82 private JComboBox toneTypesComboBox = null;
83
84 private JComboBox vCharTypesComboBox = null;
85
86 private JComboBox caseTypesComboBox = null;
87
88 private static String appName = "pinyin4j-2.0.0 applet demo";
89
90 /** *//**
91 * This method initializes charTextField
92 *
93 * @return javax.swing.JTextField
94 */
95 private JTextField getCharTextField()
96 {
97 if (charTextField == null)
98 {
99 charTextField = new JTextField();
100 charTextField.setFont(new Font("Dialog", Font.PLAIN, 12)); // Generated
101 charTextField.setText("和"); // Generated
102 charTextField.setPreferredSize(new Dimension(26, 20)); // Generated
103 }
104 return charTextField;
105 }
106
107 /** *//**
108 * This method initializes unformattedCharPanel
109 *
110 * @return javax.swing.JPanel
111 */
112 private JPanel getUnformattedCharPanel()
113 {
114 if (unformattedCharPanel == null)
115 {
116 unformattedHanyuPinyinLabel = new JLabel();
117 unformattedHanyuPinyinLabel.setText("Hanyu Pinyin"); // Generated
118 GridLayout gridLayout = new GridLayout();
119 gridLayout.setRows(2); // Generated
120 gridLayout.setHgap(1); // Generated
121 gridLayout.setVgap(1); // Generated
122 gridLayout.setColumns(3); // Generated
123 unformattedCharPanel = new JPanel();
124 unformattedCharPanel.setLayout(gridLayout); // Generated
125 unformattedCharPanel.add(getUnformattedHanyuPinyinPanel(), null); // Generated
126 unformattedCharPanel.add(getUnformattedTongyongPinyinPanel(), null); // Generated
127 unformattedCharPanel.add(getUnformattedWadePinyinPanel(), null); // Generated
128 unformattedCharPanel.add(getUnformattedMPS2PinyinPanel(), null); // Generated
129 unformattedCharPanel.add(getUnformattedYalePinyinPanel(), null); // Generated
130 unformattedCharPanel.add(getUnformattedGwoyeuRomatzyhPanel(), null); // Generated
131 }
132 return unformattedCharPanel;
133 }
134
135 /** *//**
136 * This method initializes unformattedHanyuPinyinTextArea
137 *
138 * @return javax.swing.JTextArea
139 */
140 private JTextArea getUnformattedHanyuPinyinTextArea()
141 {
142 if (unformattedHanyuPinyinTextArea == null)
143 {
144 unformattedHanyuPinyinTextArea = new JTextArea();
145 unformattedHanyuPinyinTextArea.setEditable(false); // Generated
146 unformattedHanyuPinyinTextArea.setLineWrap(true); // Generated
147 }
148 return unformattedHanyuPinyinTextArea;
149 }
150
151 /** *//**
152 * This method initializes unformattedHanyuPinyinPanel
153 *
154 * @return javax.swing.JPanel
155 */
156 private JPanel getUnformattedHanyuPinyinPanel()
157 {
158 if (unformattedHanyuPinyinPanel == null)
159 {<
分享到:
相关推荐
汉字转换为全拼或者首字母形式,oracle使用的sql
Java实现汉字转拼音功能,包括首字母和全拼,为大家减少时间,为此提供便捷。
--此函数默认返回汉字拼音的首字母,第二个参数不为空则返回全拼。 create or replace function f_getFirstOrFullSpell(p_cnStr In varchar2,p_sign In number default null) return varchar2 as lv_spell varchar2...
在 pinyin.js 中有两种转换: 全拼转换 和 拼音首字母转换。全拼转换时可以使用不同的 汉字库js 得到你想要的带或不带声调的全拼。 拼音首字母转换则随便使用哪种汉字库js了。hz.js 汉字拼音带声调。如: 贝bèi 。 ...
将汉字转为全拼或返回拼音首字母(Oracle SQL语句)
oracle汉字转换成拼音首字母、全拼,各种转换类型比较齐全,oracle汉字转换五笔首字母链接https://blog.csdn.net/weixin_40912627/article/details/88710064
汉字转全拼或首字母Oracle存储过程
Oracle中进行汉字转换成拼音,通过参数不同可以返回拼音首字母或全拼: --调用方式: SELECT f_getSpell('江西') from dual; --返回 'jx' --SELECT f_getSpell('江西',0) from dual; --返回 'jiangxi'
汉字转换成拼音全拼也能转换成首写字母,如有需要联系本人.
汉字转换拼音、拼音首字母工具类!很好,很实用,可以把中文转换成汉语拼音全拼或者拼音首字母!
通过excel提供的宏很好的可以将文字转换为拼音,可以首字母大写、全拼。通过Visual Basic新建一个模块来实现
将汉字转换为全拼或首字母,oracle 默认返回汉字拼音的首字母,第二个参数不为空则返回全拼
可以把中文转换成拼音,支持首字母和全拼,比较简单,实用就行,支持中英文字符混排等。字库为unicode编码,可以维护,D7下通过。
将中文转化为拼音首字母或是中文全拼。辅助类库。可用于转换中文拼音首字母以及内容转为编码等方法,使用方便,无其他第三方引用。
背景: 在建项目某些基础表需增加根据拼音首字母或全拼进行模糊... 2、修改表结构,增加全拼与拼音首字母的字段,修改数据入库与更新时的业务逻辑增加拼音的转换,在新功能上线前需批量更新相关数据库表的存量数据。
这是一个C#类,专门将汉字转换为简拼或全拼的,准确很高,还可以自己改:将某个字改成你想要的拼音或首字母。
Java汉字转换为拼音工具类 汉字转换为拼音包括全拼、首字母缩写;全拼可计算出多音字。
自定义函数,将汉字转换成每个汉语拼音的首字母
javascript编写的可以实现汉字转换为拼音的工具,里面的方法有获取汉字的首字母大写拼音 还有获取汉字大写的全拼 和获取汉字小写全拼。里面有一个工具js和一个使用示例