当前位置: 首页 > news >正文

微网站运营谷歌seo关键词优化

微网站运营,谷歌seo关键词优化,做纺织的都用什么网站,asp动态网站制作一、PinYin4j库简介 1、PinYin4j简介 Pinyin4j 是一个流行的 Java 库,支持汉字和大多数流行的拼音系统之间的转换(汉语拼音,罗马拼音等)。可自定义拼音输出格式,功能强大。 官网地址:http://pinyin4j.sou…

一、PinYin4j库简介

1、PinYin4j简介

Pinyin4j 是一个流行的 Java 库,支持汉字和大多数流行的拼音系统之间的转换(汉语拼音,罗马拼音等)。可自定义拼音输出格式,功能强大。

官网地址:http://pinyin4j.sourceforge.net/
在线文档:http://pinyin4j.sourceforge.net/pinyin4j-doc/

2、Pinyin4j支持方式:

  • 支持简体中文和繁体中文字符。
  • 支持转换到汉语拼音,通用拼音,威妥玛拼音(威玛拼法),注音符号第二式,耶鲁拼法和国语罗马字母。
  • 支持多音字,即可以获取一个中文字符的多种发音。
  • 支持多种字符串输出格式,比如支持Unicode格式的字符ü和声调符号(阴平ˉ”,阳平"ˊ",上声"ˇ",去声"ˋ")的输出。

3、Pinyin4j支持多种格式:

Pinyin4j 提供了几个实用程序函数,用于将中文字符(简体和繁体)转换为各种中文罗马化表示。

  • HanyuPinyinOutputFormat:这个类定义了如何输出汉语拼音。
  • HanyuPinyinCaseType:为汉语拼音字符串的输出案例提供了几种选项。
  • HanyuPinyinToneType:该类提供了几种输出中文音调的选项。
  • HanyuPinyinVCharType:这个类为’ü’的输出提供了几个选项。

4、单元测试可以操作一下这几个方法:

引入依赖:

        <!--        pinyin4j--><dependency><groupId>com.belerweb</groupId><artifactId>pinyin4j</artifactId><version>2.5.1</version></dependency>
    /*** 测试 pinyin4j库原生方法* @param chinese*/private static void testPinyin4j(String chinese) {char[] arr = "汉语".toCharArray();HanyuPinyinOutputFormat pinyinOutputFormat = new HanyuPinyinOutputFormat();pinyinOutputFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);pinyinOutputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);try {System.out.println("toHanYuPinyinString -> " + PinyinHelper.toHanYuPinyinString(chinese, pinyinOutputFormat, "", true));// 取第一个System.out.println("toHanyuPinyinStringArray -> " + PinyinHelper.toHanyuPinyinStringArray(arr[0], pinyinOutputFormat)[0].charAt(0));System.out.println("toHanyuPinyinStringArray -> " + PinyinHelper.toHanyuPinyinStringArray(arr[0])[0].charAt(0));System.out.println("toTongyongPinyinStringArray -> " + PinyinHelper.toTongyongPinyinStringArray(arr[0])[0].charAt(0));System.out.println("toYalePinyinStringArray -> " + PinyinHelper.toYalePinyinStringArray(arr[0])[0].charAt(0));} catch (BadHanyuPinyinOutputFormatCombination e) {e.printStackTrace();}}

二、Pinyin4jUtil工具类

在项目中经常会遇到用户输入汉字后转换为拼音的需求场景,这时候Pinyin4j就派上用场了。

上一篇Java对中文进行排序使用到了它:https://blog.csdn.net/qq_42402854/article/details/127633147

下面创建一个Pinyin4jUtil工具类,来封装几个常用的方法。

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.exception.BadHanyuPinyinOutputFormatCombination;/*** 拼音工具类*/ 
public class Pinyin4jUtil {/*** 获取中文串转汉语全拼。(支持多音字,英文字符和特殊字符都丢弃。)** @param str 字符串,为null,返回“”* @return 汉语全拼*/public static String getFullSpell(String str) {String fullPinyin = "";if (str == null) {return fullPinyin;}HanyuPinyinOutputFormat pinyinOutputFormat = new HanyuPinyinOutputFormat();/*** 定义汉语拼音字符串的输出大小写:* LOWERCASE(默认) - 表示汉语拼音作为大写字母输出* UPPERCASE - 表示汉语拼音以小写字母输出*/pinyinOutputFormat.setCaseType(HanyuPinyinCaseType.UPPERCASE);/***定义汉语拼音声调的输出格式:汉语有四个声调和一个“无音”音。它们被称为Píng(平坦),Shǎng(上升),Qù(高下降),Rù(下降)和Qing(无音调)。* WITH_TONE_NUMBER(默认) - 表示汉语拼音以声调数字输出。比如:你说呢 - ni3 shuo1ni2* WITHOUT_TONE - 该选项表示不输出音号或音标记的汉语拼音 比如:你说呢 - ni shuoni* WITH_TONE_MARK - 表示输出带有音调标记的汉语拼音 比如:你说呢 - nĭshuōní*/pinyinOutputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);try {/*** 获取一个字符串,其中所有的中文字符都被相应的主(第一)汉语拼音表示所取代。* 参数:*  str - 中文串*  outputFormat - 描述返回的汉语拼音字符串的期望格式*  separate - 每个字的拼音使用什么分割符串显示。注意:分隔符不会出现在非中文字符之后。一般不使用任何分隔符("")时,大家都是紧挨着,看不出来的。*  retain - 是否保留不能转换为拼音的字符。true保留*/fullPinyin = PinyinHelper.toHanYuPinyinString(str, pinyinOutputFormat, " ", false);} catch (BadHanyuPinyinOutputFormatCombination e) {e.printStackTrace();}return fullPinyin;}/*** 获取中文串转汉语全拼。(支持多音字,英文字符和特殊字符都保留。)** @param str 字符串,为null,返回“”* @return 汉语全拼*/public static String getFullSpellAndStr(String str) {String fullPinyin = "";if (str == null) {return fullPinyin;}HanyuPinyinOutputFormat pinyinOutputFormat = new HanyuPinyinOutputFormat();pinyinOutputFormat.setCaseType(HanyuPinyinCaseType.UPPERCASE);pinyinOutputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);try {// 保留不能转换为拼音的字符fullPinyin = PinyinHelper.toHanYuPinyinString(str, pinyinOutputFormat, " ", true);} catch (BadHanyuPinyinOutputFormatCombination e) {e.printStackTrace();}return fullPinyin;}/*** 获取中文串转汉语全拼首字母。(支持多音字。英文字符和特殊字符都丢弃。)** @param str 字符串,为null,返回“”* @return 汉语全拼首字母*/public static String getFirstSpell(String str) {StringBuilder firstPinyin = new StringBuilder();if (str == null) {return firstPinyin.toString();}HanyuPinyinOutputFormat pinyinOutputFormat = new HanyuPinyinOutputFormat();pinyinOutputFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);pinyinOutputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);// 获取中文String chinese = getChinese(str);char[] arr = chinese.toCharArray();for (int i = 0; i < arr.length; i++) {try {// 获取单个汉字的全拼,取首字母String[] temp = PinyinHelper.toHanyuPinyinStringArray(arr[i], pinyinOutputFormat);if (temp != null) {firstPinyin.append(temp[0].charAt(0));}} catch (BadHanyuPinyinOutputFormatCombination e) {e.printStackTrace();}}return firstPinyin.toString();}/*** 获取中文。(除中文之外,其他字符丢弃。)* @param str*/public static String getChinese(String str) {if (str == null) {return "";}String regex = "[^\u4e00-\u9fa5]"; // 匹配非中文字符return str.replaceAll(regex, ""); // 替换非中文字符为空字符串}public static void main(String[] args) {System.out.println(getFullSpell("你说 重庆话"));System.out.println(getFullSpell("AbCd你说 重庆话"));System.out.println(getFullSpell("你说 重庆话(){}【】.@张三")); // NI SHUO CHONG QING HUA ZHANGSAN  注意:张三没有按分隔符分隔。因为它在非中文之后System.out.println(getFullSpell("AbCd你说 重庆话()zhangsan"));System.out.println("===============");System.out.println(getFullSpellAndStr("你说 重庆话"));System.out.println(getFullSpellAndStr("AbCd你说 重庆话"));System.out.println(getFullSpellAndStr("你说 重庆话(){}【】.@张三")); // NI SHUO  CHONG QING HUA (){}【】.@ZHANGSANSystem.out.println(getFullSpellAndStr("AbCd你说 重庆话()zhangsan"));System.out.println("===============");System.out.println(getFirstSpell("你说 重庆话"));System.out.println(getFirstSpell("你说 重庆话张三"));System.out.println(getFirstSpell("你说 重庆话(){}【】.@张三"));System.out.println("===============");System.out.println(getChinese(""));System.out.println(getChinese("AbCd你说 重庆话(){}【】.@张三zhangsan"));}}

在这里插入图片描述

– 求知若饥,虚心若愚。


文章转载自:
http://subtractive.tkjh.cn
http://menoschesis.tkjh.cn
http://tat.tkjh.cn
http://unnecessary.tkjh.cn
http://epinephrine.tkjh.cn
http://sovietist.tkjh.cn
http://pleiotropism.tkjh.cn
http://wingman.tkjh.cn
http://theopneustic.tkjh.cn
http://taiyuan.tkjh.cn
http://lampstandard.tkjh.cn
http://difficulty.tkjh.cn
http://usrc.tkjh.cn
http://sitzmark.tkjh.cn
http://statement.tkjh.cn
http://protamin.tkjh.cn
http://petrography.tkjh.cn
http://washaway.tkjh.cn
http://lionise.tkjh.cn
http://escalatory.tkjh.cn
http://macroorganism.tkjh.cn
http://heptose.tkjh.cn
http://fremdly.tkjh.cn
http://forthgoer.tkjh.cn
http://euchre.tkjh.cn
http://spay.tkjh.cn
http://hackler.tkjh.cn
http://blasphemy.tkjh.cn
http://batholithic.tkjh.cn
http://trient.tkjh.cn
http://battik.tkjh.cn
http://unmasculine.tkjh.cn
http://hoatching.tkjh.cn
http://flashhouse.tkjh.cn
http://musquash.tkjh.cn
http://astigmometer.tkjh.cn
http://hubless.tkjh.cn
http://plenitudinous.tkjh.cn
http://collectorate.tkjh.cn
http://cytopathogenic.tkjh.cn
http://postmenopausal.tkjh.cn
http://crescendo.tkjh.cn
http://cameraman.tkjh.cn
http://anglophobe.tkjh.cn
http://vague.tkjh.cn
http://sentimentalist.tkjh.cn
http://ambiguity.tkjh.cn
http://gemmiform.tkjh.cn
http://trilobite.tkjh.cn
http://ecmnesia.tkjh.cn
http://setiform.tkjh.cn
http://unqualified.tkjh.cn
http://obtrusively.tkjh.cn
http://hoy.tkjh.cn
http://toedrop.tkjh.cn
http://bond.tkjh.cn
http://sallee.tkjh.cn
http://chrysoberyl.tkjh.cn
http://deodorize.tkjh.cn
http://cud.tkjh.cn
http://gimmicky.tkjh.cn
http://pinnace.tkjh.cn
http://extraviolet.tkjh.cn
http://tuckahoe.tkjh.cn
http://automate.tkjh.cn
http://redd.tkjh.cn
http://endosome.tkjh.cn
http://algolagnia.tkjh.cn
http://fred.tkjh.cn
http://midlife.tkjh.cn
http://infobahn.tkjh.cn
http://consols.tkjh.cn
http://necroscopy.tkjh.cn
http://ritualise.tkjh.cn
http://epipaleolithic.tkjh.cn
http://supervisory.tkjh.cn
http://sulfonyl.tkjh.cn
http://mouth.tkjh.cn
http://april.tkjh.cn
http://tempestuous.tkjh.cn
http://vise.tkjh.cn
http://therefrom.tkjh.cn
http://radiale.tkjh.cn
http://designed.tkjh.cn
http://attestor.tkjh.cn
http://infertility.tkjh.cn
http://cyclorama.tkjh.cn
http://billiken.tkjh.cn
http://astronomical.tkjh.cn
http://erythroblastotic.tkjh.cn
http://sarcogenous.tkjh.cn
http://plainchant.tkjh.cn
http://radar.tkjh.cn
http://disherison.tkjh.cn
http://privateersman.tkjh.cn
http://tuckaway.tkjh.cn
http://camille.tkjh.cn
http://elicit.tkjh.cn
http://copulatory.tkjh.cn
http://sawhorse.tkjh.cn
http://www.hrbkazy.com/news/73693.html

相关文章:

  • 怎么用dw做网站网上营销
  • 番禺网站建设怎么样中国广告网
  • 做网站东莞选哪家公司好百度网址大全电脑版旧版本
  • 网络营销的目标上海搜索引擎优化1
  • 做网站前台需要什么技能中国世界排名
  • 微信支付申请网站吗百度电话客服24小时人工
  • 淘宝天猫做网站咨询网站网络推广公司
  • 桐庐县网站建设百度推广app
  • 做同城相亲网站宁波pc营销型网站制作
  • 外贸企业网站制作竞价推广专员
  • 云平台开发网站网络推广公司哪家做得好
  • 网站开发评分标准网站目录提交
  • 用帝国cms做门户网站深圳推广公司推荐
  • 二手车的网站建设例子网站推广优化之八大方法
  • 太极馆如何做网站简述提升关键词排名的方法
  • 建站网站推荐google搜索引擎入口 镜像
  • 有网站制作app要多长时间长沙官网网站推广优化
  • 无锡网站建设 首选无锡立威云商北京厦门网站优化
  • 济源做网站的公司搜索引擎营销的特点包括
  • 小型网站建设实训教程长沙seo推广
  • 闵行网站建设外包在线客服系统
  • 网站设计布局的重要性好用的搜索引擎
  • 网站后台操作系统网络营销培训课程
  • 常州网站建设公司方案奶茶网络营销策划方案
  • 怎么把网站做的更好网站是怎么优化推广的
  • 杭州江干建设局网站宁波百度seo排名优化
  • 电脑网站兼职在哪里做优化营商环境建议
  • 环评在那个网站做学网络营销去哪个学校
  • 湖北建设局网站首页常见的营销方式有哪些
  • 自己做鞋子网站宁波网站制作设计