介绍一个功能,可以把汉语转化成拼音,包括全拼和首字母,甚至可以带音调。
大家可以去http://pinyin4j.sourceforge.net/ 看看,下载支持jar包:pinyin4j-2.5.0.jar。
我也是看的demo,大家可以把下面的代码运行看看。
1![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/** *//**
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![](/Images/OutliningIndicators/None.gif)
19
package pinyin;
20![](/Images/OutliningIndicators/None.gif)
21
import java.awt.BorderLayout;
22
import java.awt.Dimension;
23
import java.awt.Font;
24
import java.awt.GridLayout;
25
import java.awt.event.WindowAdapter;
26
import java.awt.event.WindowEvent;
27![](/Images/OutliningIndicators/None.gif)
28
import javax.swing.JApplet;
29
import javax.swing.JButton;
30
import javax.swing.JComboBox;
31
import javax.swing.JFrame;
32
import javax.swing.JLabel;
33
import javax.swing.JPanel;
34
import javax.swing.JScrollPane;
35
import javax.swing.JTabbedPane;
36
import javax.swing.JTextArea;
37
import javax.swing.JTextField;
38![](/Images/OutliningIndicators/None.gif)
39
import net.sourceforge.pinyin4j.PinyinHelper;
40
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
41
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
42
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
43
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
44
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
45![](/Images/OutliningIndicators/None.gif)
46![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/** *//**
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![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/** *//**
57
* A demo show the functions of pinyin4j library
58
*
59
* @author Li Min (xmlerlimin@gmail.com)
60
*
61
*/
62
public class Pinyin4jAppletDemo extends JApplet
63![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
{
64
private static final Dimension APP_SIZE = new Dimension(600, 400);
65![](/Images/OutliningIndicators/InBlock.gif)
66
private static final long serialVersionUID = -1934962385592030162L;
67![](/Images/OutliningIndicators/InBlock.gif)
68
private JPanel jContentPane = null;
69![](/Images/OutliningIndicators/InBlock.gif)
70
private JTabbedPane jTabbedPane = null;
71![](/Images/OutliningIndicators/InBlock.gif)
72
private JPanel formattedCharPanel = null;
73![](/Images/OutliningIndicators/InBlock.gif)
74
private JPanel optionPanel = null;
75![](/Images/OutliningIndicators/InBlock.gif)
76
private JButton convertButton = null;
77![](/Images/OutliningIndicators/InBlock.gif)
78
private JPanel buttonPanel = null;
79![](/Images/OutliningIndicators/InBlock.gif)
80
private JTextArea formattedOutputField = null;
81![](/Images/OutliningIndicators/InBlock.gif)
82
private JComboBox toneTypesComboBox = null;
83![](/Images/OutliningIndicators/InBlock.gif)
84
private JComboBox vCharTypesComboBox = null;
85![](/Images/OutliningIndicators/InBlock.gif)
86
private JComboBox caseTypesComboBox = null;
87![](/Images/OutliningIndicators/InBlock.gif)
88
private static String appName = "pinyin4j-2.0.0 applet demo";
89![](/Images/OutliningIndicators/InBlock.gif)
90![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/** *//**
91
* This method initializes charTextField
92
*
93
* @return javax.swing.JTextField
94
*/
95
private JTextField getCharTextField()
96![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
97
if (charTextField == null)
98![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
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![](/Images/OutliningIndicators/InBlock.gif)
107![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/** *//**
108
* This method initializes unformattedCharPanel
109
*
110
* @return javax.swing.JPanel
111
*/
112
private JPanel getUnformattedCharPanel()
113![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
114
if (unformattedCharPanel == null)
115![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
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![](/Images/OutliningIndicators/InBlock.gif)
135![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/** *//**
136
* This method initializes unformattedHanyuPinyinTextArea
137
*
138
* @return javax.swing.JTextArea
139
*/
140
private JTextArea getUnformattedHanyuPinyinTextArea()
141![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
142
if (unformattedHanyuPinyinTextArea == null)
143![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
144
unformattedHanyuPinyinTextArea = new JTextArea();
145
unformattedHanyuPinyinTextArea.setEditable(false); // Generated
146
unformattedHanyuPinyinTextArea.setLineWrap(true); // Generated
147
}
148
return unformattedHanyuPinyinTextArea;
149
}
150![](/Images/OutliningIndicators/InBlock.gif)
151![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/** *//**
152
* This method initializes unformattedHanyuPinyinPanel
153
*
154
* @return javax.swing.JPanel
155
*/
156
private JPanel getUnformattedHanyuPinyinPanel()
157![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
158
if (unformattedHanyuPinyinPanel == null)
159![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{<
分享到:
相关推荐
在IT行业中,尤其是在数据库管理和数据处理领域,有时候我们需要将汉字转换为全拼或首字母形式。这在构建搜索引擎、文本分析或实现特定的查询功能时非常有用。Oracle数据库系统提供了强大的SQL查询语言,可以帮助...
Pinyin4j是一个广泛使用的Java库,它提供了将汉字转换为汉语拼音的功能,支持全拼和首字母。 使用Pinyin4j库进行汉字转拼音的步骤如下: 1. 引入Pinyin4j库:在项目中添加Pinyin4j的依赖。如果是Maven项目,可以在...
总结起来,"汉字转全拼或首字母Oracle存储过程"是一个利用PL/SQL实现的工具,它可以将汉字字符串转换为其全拼或首字母,这对于处理汉字数据和提升搜索效率具有重要意义。通过创建和使用这样的存储过程,我们可以灵活...
--此函数默认返回汉字拼音的首字母,第二个参数不为空则返回全拼。 create or replace function f_getFirstOrFullSpell(p_cnStr In varchar2,p_sign In number default null) return varchar2 as lv_spell varchar2...
oracle汉字转换成拼音首字母、全拼,各种转换类型比较齐全,oracle汉字转换五笔首字母链接https://blog.csdn.net/weixin_40912627/article/details/88710064
在 pinyin.js 中有两种转换: 全拼转换 和 拼音首字母转换。全拼转换时可以使用不同的 汉字库js 得到你想要的带或不带声调的全拼。 拼音首字母转换则随便使用哪种汉字库js了。hz.js 汉字拼音带声调。如: 贝bèi 。 ...
标题提到的“select2插件支持全拼搜索和首字母搜索”意味着这个插件已经被进一步扩展,增加了对中文拼音搜索的支持,让用户可以通过输入首字母或全拼来快速定位和选择目标选项。 首先,`Select2` 插件的核心特性...
4. 首字母转换:转换为首字母,通常指的是汉字转换为其拼音的首字母,如“北京”转换为“BJ”,并且可以选择首字母的大写或小写形式。 5. "文本转换为全拼音.bas":这是一个VBA的基本模块文件,包含了将Excel单元格...
将汉字转为全拼或返回拼音首字母(Oracle SQL语句)
MySQL中文拼音数据库是一种专门用于处理中文字符到其拼音转化的数据资源,它包含了6565个汉字的全拼和首字母信息。这个数据库是用MySQL这种关系型数据库管理系统构建的,设计时考虑到了高效检索和数据存储的需求。...
oracle汉字转拼音 获得全拼、拼音首字母、拼音截取等
标题中的"Delphi中文转拼音,全拼和首字母"是指使用Delphi编程语言开发的一个功能,该功能能够将输入的中文文本转化为对应的拼音表示,包括全拼(每个汉字转化为完整的拼音)和首字母(每个汉字转化为声母,即汉语...
Oracle中进行汉字转换成拼音,通过参数不同可以返回拼音首字母或全拼: --调用方式: SELECT f_getSpell('江西') from dual; --返回 'jx' --SELECT f_getSpell('江西',0) from dual; --返回 'jiangxi'
汉字转换成拼音全拼也能转换成首写字母,如有需要联系本人.
汉字转换拼音、拼音首字母工具类!很好,很实用,可以把中文转换成汉语拼音全拼或者拼音首字母!
将汉字转换为全拼或首字母,oracle 默认返回汉字拼音的首字母,第二个参数不为空则返回全拼
标题提到的"将中文转化为英文首字母或是因为全拼"是指将中文字符转换成对应的拼音,其中可以包括首字母或者完整的拼音。这一功能在开发各种应用程序时非常有用,比如用户输入法、信息检索系统、语音识别系统等。 ...
在处理中文字符时,有时我们需要将汉字转换为拼音,以便进行各种操作,如搜索、排序或生成便于机器处理的数据。"JS汉语转拼音 全拼字母和首拼字母"这个主题正是关于如何在JavaScript中实现这一功能。 全拼是汉字的...