/// <summary> /// 生成的拼音不包含声调,均为大写 /// 中国 - ZHONGGUO /// </summary> /// <param name="text"></param> /// <param name="separator"></param> /// <returns></returns> public static string GetPinyin(string text, string separator = ",") { return(PinyinHelper.GetPinyin(text, separator)); }
public void TestNullInput() { Assert.Throws <ArgumentNullException> (() => PinyinHelper.ToHanyuPinyinStringArray('李', null)); }
private void txtTitleSave_Leave(object sender, EventArgs e) { txtChar.Text = PinyinHelper.GetPinyin(txtTitleSave.Text); }
public virtual IList <string> GetCodeOfChar(char str) { return(PinyinHelper.GetPinYinOfChar(str)); }
public void testToWadeGilesPinyinStringArray() { // any input of non-Chinese characters will return null { Assert.IsNull(PinyinHelper.ToWadeGilesPinyinStringArray('A')); Assert.IsNull(PinyinHelper.ToWadeGilesPinyinStringArray('z')); Assert.IsNull(PinyinHelper.ToWadeGilesPinyinStringArray(',')); Assert.IsNull(PinyinHelper.ToWadeGilesPinyinStringArray('。')); } // Chinese characters // single pronounciation { string[] expectedPinyinArray = new string[] { "li3" }; string[] pinyinArray = PinyinHelper.ToWadeGilesPinyinStringArray('李'); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } { string[] expectedPinyinArray = new string[] { "ch`iu2" }; string[] pinyinArray = PinyinHelper.ToWadeGilesPinyinStringArray('球'); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } { string[] expectedPinyinArray = new string[] { "chuang1" }; string[] pinyinArray = PinyinHelper.ToWadeGilesPinyinStringArray('桩'); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } // multiple pronounciations { string[] expectedPinyinArray = new string[] { "ch`uan2", "chuan4" }; string[] pinyinArray = PinyinHelper.ToWadeGilesPinyinStringArray('传'); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } { string[] expectedPinyinArray = new string[] { "lu:4", "lu4" }; string[] pinyinArray = PinyinHelper.ToWadeGilesPinyinStringArray('绿'); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } }
public void TestNullInput() { PinyinHelper.ToHanyuPinyinStringArray('李', null); }
public void TestMethod2() { var result = PinyinHelper.GetPinyin('的'); Assert.Equal <string>("DE", result, this.comparer); }
public void testToHanyuPinyinStringArray() { // any input of non-Chinese characters will return null { HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); try { Assert.IsNull(PinyinHelper.ToHanyuPinyinStringArray('A', defaultFormat)); Assert.IsNull(PinyinHelper.ToHanyuPinyinStringArray('z', defaultFormat)); Assert.IsNull(PinyinHelper.ToHanyuPinyinStringArray(',', defaultFormat)); Assert.IsNull(PinyinHelper.ToHanyuPinyinStringArray('。', defaultFormat)); } catch (BadHanyuPinyinOutputFormatCombination e) { throw e; } } // Chinese characters // single pronounciation { try { HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); string[] expectedPinyinArray = new string[] { "li3" }; string[] pinyinArray = PinyinHelper.ToHanyuPinyinStringArray('李', defaultFormat); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } catch (BadHanyuPinyinOutputFormatCombination e) { throw e; } } { try { HanyuPinyinOutputFormat upperCaseFormat = new HanyuPinyinOutputFormat(); upperCaseFormat.CaseType = HanyuPinyinCaseType.UPPERCASE; string[] expectedPinyinArray = new string[] { "LI3" }; string[] pinyinArray = PinyinHelper.ToHanyuPinyinStringArray('李', upperCaseFormat); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } catch (BadHanyuPinyinOutputFormatCombination e) { throw e; } } { try { HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); string[] expectedPinyinArray = new string[] { "lu:3" }; string[] pinyinArray = PinyinHelper.ToHanyuPinyinStringArray('吕', defaultFormat); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } catch (BadHanyuPinyinOutputFormatCombination e) { throw e; } } { try { HanyuPinyinOutputFormat vCharFormat = new HanyuPinyinOutputFormat(); vCharFormat.VCharType = HanyuPinyinVCharType.WITH_V; string[] expectedPinyinArray = new string[] { "lv3" }; string[] pinyinArray = PinyinHelper.ToHanyuPinyinStringArray('吕', vCharFormat); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } catch (BadHanyuPinyinOutputFormatCombination e) { throw e; } } // multiple pronounciations { try { HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); string[] expectedPinyinArray = new string[] { "jian1", "jian4" }; string[] pinyinArray = PinyinHelper.ToHanyuPinyinStringArray('间', defaultFormat); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } catch (BadHanyuPinyinOutputFormatCombination e) { throw e; } } { try { HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); string[] expectedPinyinArray = new string[] { "hao3", "hao4" }; string[] pinyinArray = PinyinHelper.ToHanyuPinyinStringArray('好', defaultFormat); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } catch (BadHanyuPinyinOutputFormatCombination e) { throw e; } } }
/// <summary> /// 按照"格式二"从指定的<see cref="ISheet"/>对象中提取信息 /// 并创建<see cref="TimeTable"/>对象集合返回 /// </summary> /// <param name="sheet">将作为数据源的<see cref="ISheet"/>对象</param> /// <returns><see cref="TimeTable"/>对象集合</returns> private static List <TimeTable> GetTimeTableOfStyleTwo(ISheet sheet) { // 从第二行中获取列车运行方向 var row = sheet.GetRow(1); var title = row.Cells[0].ToString(); // 从字符串"古店-集宁间上行列车时刻表"中提取"上行" var direction = title.Substring(title.IndexOf("行列车时刻表") - 1, 2); // 从第八行和第九行中提取所有车次 row = sheet.GetRow(7); var row9 = sheet.GetRow(8); var stationColNum = Regex.Replace(row.Cells[0].ToString(), @"\s", "") == "区间公里" ? 2 : 0; // 车站所在列的索引 var trainNos = new List <string>(); for (var i = stationColNum + 1; i < row.Cells.Count; i++) { // 车次列索引从车站后一列开始 var value = row.Cells[i].ToString().Trim(); var value1 = row9.Cells[i].ToString().Trim(); // 有的车次占了第八和第九两行 if (!string.IsNullOrEmpty(value)) { trainNos.Add(value + value1); } } // 从第一或者第三列中提取所有车站(有的表格车站在第三列,而有的在第一列) // 从第十行开始循环 var stations = new List <BaseStation>(); for (var i = 9; i < sheet.LastRowNum; i++) { row = sheet.GetRow(i); var txt = row.Cells[stationColNum].ToString(); if (!string.IsNullOrEmpty(txt)) { var name = txt.Trim(); var pinyin = PinyinHelper.GetInitials(name).ToLower(); stations.Add(new BaseStation { Spell = pinyin, StationName = name }); } } // 循环车次列表,生成列车时刻表集合 var startColNum = stationColNum + 1; var timeTables = new List <TimeTable>(); for (var trainNoIndex = 0; trainNoIndex < trainNos.Count; trainNoIndex++) { var timeTable = new TimeTable(); // 从第二或者第四列开始,逐列获取列车时刻表 var sort = 1; var stationIndex = 0; // 通过此索引从车站列表中获取与时刻表对应的车站 var colIndex = startColNum + trainNoIndex; // 随着车次索引的增加,相应的改变获取时刻表的单元格索引 for (var rowIndex = 9; rowIndex < sheet.LastRowNum; rowIndex++) { row = sheet.GetRow(rowIndex); var arrive = row.Cells[colIndex].ToString().Trim().Replace("...", ""); rowIndex++; row = sheet.GetRow(rowIndex); var start = row.Cells[colIndex].ToString().Trim().Replace("...", ""); // 出发或者到达时间任意一个不为空 // 则表明本车次将经过stationIndex所对应的车站 // 否则表示本车次不经过此车站,则不将此车站添加到 // 本车次对应的车站列表中 if (!string.IsNullOrEmpty(arrive) || !string.IsNullOrEmpty(start)) { arrive = TimeFormatter(arrive); start = TimeFormatter(start); timeTable.Stations.Add(stations[stationIndex]); timeTable.Moments.Add(new TrainMoment { ArriveTime = arrive, DepartTime = start, Sort = sort++ }); } stationIndex++; // 如果stationIndex已经超出了车站数量,则结束循环 if (stationIndex >= stations.Count) { break; } } // 重置索引和排序 stationIndex = 0; sort = 1; // 如果是上行车次,需要将车站及列车时刻反转 if (direction == "上行") { timeTable.Stations.Reverse(); timeTable.Moments.Reverse(); // 改变序号,并将出发及到达时间互换 sort = 1; timeTable.Moments.ForEach(item => { var temp = item.ArriveTime; item.ArriveTime = item.DepartTime; item.DepartTime = temp; item.Sort = sort++; }); } // 创建车次及线路对象 var firstStation = timeTable.Stations.First().StationName; var lastStation = timeTable.Stations.Last().StationName; timeTable.TrainNo = new TrainNo { Direction = direction, FullName = trainNos[trainNoIndex], FirstStation = firstStation, LastStation = lastStation, RunType = 2 }; timeTable.Line = new BaseLine { FirstStation = firstStation, LastStation = lastStation, LineName = $"{firstStation}-{lastStation}" }; timeTables.Add(timeTable); } return(timeTables); }
public void TestMethod1() { var result = PinyinHelper.GetPinyin('中'); Assert.Equal("ZHONG", result, this.comparer); }
public string GetCodeOfChar(char str) { return(PinyinHelper.GetDefaultPinyin(str)); }
private void InitializePinyinHelpers() { Format.setToneType(HanyuPinyinToneType.WITHOUT_TONE); PinyinHelper.toHanyuPinyinStringArray('T', Format); }
private void txtNameAdd_Leave(object sender, EventArgs e) { txtPinyin.Text = PinyinHelper.GetPinyin(txtNameAdd.Text); }
public void TestPinyinHelper() { var aa = PinyinHelper.PinyinString("ffff"); }
public void TestMethod4() { var result = PinyinHelper.GetPinyinInitials("成都"); Assert.Equal <string>("CD", result, this.comparer); }
public void testToGwoyeuRomatzyhStringArray() { // any input of non-Chinese characters will return null { Assert.IsNull(PinyinHelper.ToGwoyeuRomatzyhStringArray('A')); Assert.IsNull(PinyinHelper.ToGwoyeuRomatzyhStringArray('z')); Assert.IsNull(PinyinHelper.ToGwoyeuRomatzyhStringArray(',')); Assert.IsNull(PinyinHelper.ToGwoyeuRomatzyhStringArray('。')); } // Chinese characters // single pronounciation { string[] expectedPinyinArray = new string[] { "lii" }; string[] pinyinArray = PinyinHelper.ToGwoyeuRomatzyhStringArray('李'); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } { string[] expectedPinyinArray = new string[] { "chyou" }; string[] pinyinArray = PinyinHelper.ToGwoyeuRomatzyhStringArray('球'); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } { string[] expectedPinyinArray = new string[] { "juang" }; string[] pinyinArray = PinyinHelper.ToGwoyeuRomatzyhStringArray('桩'); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } { string[] expectedPinyinArray = new string[] { "fuh" }; string[] pinyinArray = PinyinHelper.ToGwoyeuRomatzyhStringArray('付'); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } // multiple pronounciations { string[] expectedPinyinArray = new string[] { "chwan", "juann" }; string[] pinyinArray = PinyinHelper.ToGwoyeuRomatzyhStringArray('传'); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } { string[] expectedPinyinArray = new string[] { ".me", ".mha", "iau" }; string[] pinyinArray = PinyinHelper.ToGwoyeuRomatzyhStringArray('么'); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } { string[] expectedPinyinArray = new string[] { "liuh", "luh" }; string[] pinyinArray = PinyinHelper.ToGwoyeuRomatzyhStringArray('绿'); Assert.AreEqual(expectedPinyinArray.Length, pinyinArray.Length); for (int i = 0; i < expectedPinyinArray.Length; i++) { Assert.AreEqual(expectedPinyinArray[i], pinyinArray[i]); } } }
public void TestMethod2() { var result = PinyinHelper.GetPinyin('的'); Assert.AreEqual <string>("DE", result); }
public void testOutputCombination() { try { HanyuPinyinOutputFormat outputFormat = new HanyuPinyinOutputFormat(); // fix case type to lowercase firstly, change VChar and Tone // combination outputFormat.CaseType = HanyuPinyinCaseType.LOWERCASE; // WITH_U_AND_COLON and WITH_TONE_NUMBER outputFormat.VCharType = HanyuPinyinVCharType.WITH_U_AND_COLON; outputFormat.ToneType = HanyuPinyinToneType.WITH_TONE_NUMBER; Assert.AreEqual("lu:3", PinyinHelper.ToHanyuPinyinStringArray('吕', outputFormat)[0]); // WITH_V and WITH_TONE_NUMBER outputFormat.VCharType = HanyuPinyinVCharType.WITH_V; outputFormat.ToneType = HanyuPinyinToneType.WITH_TONE_NUMBER; Assert.AreEqual("lv3", PinyinHelper.ToHanyuPinyinStringArray('吕', outputFormat)[0]); // WITH_U_UNICODE and WITH_TONE_NUMBER outputFormat.VCharType = HanyuPinyinVCharType.WITH_U_UNICODE; outputFormat.ToneType = HanyuPinyinToneType.WITH_TONE_NUMBER; Assert.AreEqual("lü3", PinyinHelper.ToHanyuPinyinStringArray('吕', outputFormat)[0]); // // WITH_U_AND_COLON and WITHOUT_TONE outputFormat.VCharType = HanyuPinyinVCharType.WITH_U_AND_COLON; outputFormat.ToneType = HanyuPinyinToneType.WITHOUT_TONE; Assert.AreEqual("lu:", PinyinHelper.ToHanyuPinyinStringArray('吕', outputFormat)[0]); // WITH_V and WITHOUT_TONE outputFormat.VCharType = HanyuPinyinVCharType.WITH_V; outputFormat.ToneType = HanyuPinyinToneType.WITHOUT_TONE; Assert.AreEqual("lv", PinyinHelper.ToHanyuPinyinStringArray('吕', outputFormat)[0]); // WITH_U_UNICODE and WITHOUT_TONE outputFormat.VCharType = HanyuPinyinVCharType.WITH_U_UNICODE; outputFormat.ToneType = HanyuPinyinToneType.WITHOUT_TONE; Assert.AreEqual("lü", PinyinHelper.ToHanyuPinyinStringArray('吕', outputFormat)[0]); // WITH_U_AND_COLON and WITH_TONE_MARK is forbidden // WITH_V and WITH_TONE_MARK is forbidden // WITH_U_UNICODE and WITH_TONE_MARK outputFormat.VCharType = HanyuPinyinVCharType.WITH_U_UNICODE; outputFormat.ToneType = HanyuPinyinToneType.WITH_TONE_MARK; Assert.AreEqual("lǚ", PinyinHelper.ToHanyuPinyinStringArray('吕', outputFormat)[0]); // fix case type to UPPERCASE, change VChar and Tone // combination outputFormat.CaseType = HanyuPinyinCaseType.UPPERCASE; // WITH_U_AND_COLON and WITH_TONE_NUMBER outputFormat.VCharType = HanyuPinyinVCharType.WITH_U_AND_COLON; outputFormat.ToneType = HanyuPinyinToneType.WITH_TONE_NUMBER; Assert.AreEqual("LU:3", PinyinHelper.ToHanyuPinyinStringArray('吕', outputFormat)[0]); // WITH_V and WITH_TONE_NUMBER outputFormat.VCharType = HanyuPinyinVCharType.WITH_V; outputFormat.ToneType = HanyuPinyinToneType.WITH_TONE_NUMBER; Assert.AreEqual("LV3", PinyinHelper.ToHanyuPinyinStringArray('吕', outputFormat)[0]); // WITH_U_UNICODE and WITH_TONE_NUMBER outputFormat.VCharType = HanyuPinyinVCharType.WITH_U_UNICODE; outputFormat.ToneType = HanyuPinyinToneType.WITH_TONE_NUMBER; Assert.AreEqual("LÜ3", PinyinHelper.ToHanyuPinyinStringArray('吕', outputFormat)[0]); // // WITH_U_AND_COLON and WITHOUT_TONE outputFormat.VCharType = HanyuPinyinVCharType.WITH_U_AND_COLON; outputFormat.ToneType = HanyuPinyinToneType.WITHOUT_TONE; Assert.AreEqual("LU:", PinyinHelper.ToHanyuPinyinStringArray('吕', outputFormat)[0]); // WITH_V and WITHOUT_TONE outputFormat.VCharType = HanyuPinyinVCharType.WITH_V; outputFormat.ToneType = HanyuPinyinToneType.WITHOUT_TONE; Assert.AreEqual("LV", PinyinHelper.ToHanyuPinyinStringArray('吕', outputFormat)[0]); // WITH_U_UNICODE and WITHOUT_TONE outputFormat.VCharType = HanyuPinyinVCharType.WITH_U_UNICODE; outputFormat.ToneType = HanyuPinyinToneType.WITHOUT_TONE; Assert.AreEqual("LÜ", PinyinHelper.ToHanyuPinyinStringArray('吕', outputFormat)[0]); // WITH_U_AND_COLON and WITH_TONE_MARK is forbidden // WITH_V and WITH_TONE_MARK is forbidden // WITH_U_UNICODE and WITH_TONE_MARK outputFormat.VCharType = HanyuPinyinVCharType.WITH_U_UNICODE; outputFormat.ToneType = HanyuPinyinToneType.WITH_TONE_MARK; Assert.AreEqual("LǙ", PinyinHelper.ToHanyuPinyinStringArray('吕', outputFormat)[0]); } catch (BadHanyuPinyinOutputFormatCombination e) { throw e; } }
public void TestMethod3() { var result = PinyinHelper.GetPinyin("我们都有一个家", "|"); Assert.AreEqual <string>("WO|MEN|DOU|YOU|YI|GE|JIA", result); }
static string GetPinyin(string str, string separator) => PinyinHelper.GetPinyin(str, separator) ?? string.Empty;
public void TestMethod4() { var result = PinyinHelper.GetPinyinInitials("成都"); Assert.AreEqual <string>("CD", result); }
public void TestNonChineseCharacter(char ch) { Assert.IsNull(PinyinHelper.ToHanyuPinyinStringArray(ch)); }
public void TestMethod1() { var result = PinyinHelper.GetPinyin('中'); Assert.AreEqual <string>("ZHONG", result); }
/// <summary> /// 递归 /// </summary> /// <param name="menu"></param> /// <returns></returns> private MenuInfo Builder(SysMenuDto menu) { //如果是顶级菜单,并且没有子集,需要单独构造,把当前菜单写在 Children 里面 if (menu.FatherID == 0 && (menu.Children == null || menu.Children.Count == 0)) { return(new MenuInfo { Path = GetRoutePath(menu.Url), Component = "Layout", Redirect = string.Empty, Children = new List <MenuInfo> { new MenuInfo { Path = PinyinHelper.GetFirstPinyin(menu.Name), Name = menu.Name, Component = menu.Url, Meta = new Meta { Icon = menu.Icon, Title = menu.Name, MenuID = menu.ID, }, } } }); } MenuInfo result = new MenuInfo { Component = menu.Url, Name = menu.Name, Redirect = string.Empty, Meta = new Meta { Icon = menu.Icon, Title = menu.Name, MenuID = menu.ID, }, Path = menu.Path }; List <MenuInfo> childrenList = new List <MenuInfo>(); if (menu.Children.CheckNotEmpty() == true) { foreach (SysMenuDto menuChild in menu.Children) { childrenList.Add(Builder(menuChild)); } } result.Children = childrenList; //if (result.Children.Count == 0) //{ // result.Path = PinyinHelper.GetFirstPinyin(result.Name); //} //else //{ // result.Component = "Layout"; // result.Path = GetRoutePath(menu.Url); //} if (result.Children.Count > 0) { result.Component = "Layout"; result.Path = GetRoutePath(menu.Url); } return(result); }
private void txtDTitleAdd_TextChanged(object sender, EventArgs e) { txtDCharAdd.Text = PinyinHelper.GetPinYin(txtDTitleAdd.Text); }
public override IList <string> GetAllCodesOfChar(char str) { return(PinyinHelper.GetPinYinWithToneOfChar(str)); }
public object Get(int id) { var assemblies = AssemblyHelper.GetAssembliesBySearchPattern("Dragon.Samples.*.dll"); return(this.Success(PinyinHelper.GetPinyinFirst("國家Country."))); }