private bool MatchProgram(Bookmark bookmark, Query query) { if (bookmark.Name.ToLower().Contains(query.RawQuery.ToLower()) || bookmark.Url.ToLower().Contains(query.RawQuery.ToLower())) { return(true); } if (ChineseToPinYin.ToPinYin(bookmark.Name).Replace(" ", "").ToLower().Contains(query.RawQuery.ToLower())) { return(true); } return(false); }
private void button3_Click(object sender, EventArgs e) { FolderBrowserDialog FBD = new FolderBrowserDialog(); string music = ""; music = this.listBox1.SelectedItem.ToString(); music = ChineseToPinYin.ToPinYin(music); string address = this.listBox1.SelectedItem.ToString(); string format = ".mp3"; string folderlocation = router; // judge if the selected file is mp3 file if (address.IndexOf(format) > -1) { //当rename button第二次点击时,因为listbox中未更新,所以显示错误!!需要修改!! File.Move(@address, @music); music = address; // check if the file has been renamed if (this.listBox1.SelectedItem.ToString() == music) { MessageBox.Show("The selected music has been renamed!"); listBox1.Items.Clear(); //display the renewed music string[] files = Directory.GetFiles(folderlocation); foreach (string file in files) { listBox1.Items.Add(file); } } else { MessageBox.Show("The selected music is not renamed!"); } } else { MessageBox.Show("The selected file is not mp3 file"); } // File.Move(this.listBox1.SelectedItem.ToString(),music); // music = ChineseToPinYin.ToPinYin(music); }
private bool MatchProgram(Program program, FuzzyMatcher matcher) { program.Score = matcher.Score(program.Title); if (program.Score > 0) { return(true); } program.Score = matcher.Score(ChineseToPinYin.ToPinYin(program.Title).Replace(" ", "")); if (program.Score > 0) { return(true); } return(false); }
public void ConvertTest() { var res = ChineseToPinYin.Convert("刘晨辉", "_", true); Assert.AreEqual(res, "Liu_Chen_Hui"); res = ChineseToPinYin.Convert("刘晨辉", "", true); Assert.AreEqual(res, "LiuChenHui"); res = ChineseToPinYin.Convert("刘晨辉", "_", false); Assert.AreEqual(res, "liu_chen_hui"); res = ChineseToPinYin.Convert("刘晨辉", "", false); Assert.AreEqual(res, "liuchenhui"); ChineseToPinYin.Phrase.Add("刘晨辉", "Liuch"); res = ChineseToPinYin.Convert("刘晨辉", "", false); Assert.AreEqual(res, "Liuch"); }
private void button2_Click(object sender, EventArgs e) { int ranknum = allmusic.GetLength(0); int i = 0; for (i = 0; i < ranknum; i++) { string chinesemusic = allmusic[i]; string musicpinyin = ChineseToPinYin.ToPinYin(chinesemusic); File.Move(@chinesemusic, @musicpinyin); } string message = string.Format("{0} musics have been renamed!", ranknum); listBox1.Items.Clear(); //display the renewed music string[] files = Directory.GetFiles(router); foreach (string file in files) { listBox1.Items.Add(file); } MessageBox.Show(message); }
/// <summary> /// 获取业务表字段信息列表 /// </summary> /// <returns></returns> private static List <TableFieldInfoDto> GetTableFieldInfos() { List <TableFieldInfoDto> lstDto = new List <TableFieldInfoDto>(); //包含所有数据库表的type数组 List <Type> tableList = new List <Type> { typeof(UnitBasicDataDto), typeof(UnitDevelopDataDto), typeof(WellDevelopDataDto), }; foreach (var tableType in tableList) { var piAry = tableType.GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var pi in piAry) { var attrAry = pi.GetCustomAttributes(typeof(DisplayFieldAttribute), true); if (attrAry.Length <= 0) { continue; } var displayFieldAttri = attrAry[0] as DisplayFieldAttribute; //显示值 string fieldDisplayText = displayFieldAttri.DisplayText; //json名称 string fieldJsonName = string.Empty; var jsonPropertyAttrAry = pi.GetCustomAttributes(typeof(JsonPropertyAttribute), true); if (jsonPropertyAttrAry != null && jsonPropertyAttrAry.Count() > 0) { fieldJsonName = ((JsonPropertyAttribute)jsonPropertyAttrAry[0]).PropertyName; } //别名列表 string[] fieldAliasAry = displayFieldAttri.DisplayAlias?.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); List <string> lstAlasAry = new List <string>(); lstAlasAry.Add(fieldDisplayText); if (string.IsNullOrWhiteSpace(fieldJsonName) == false) { lstAlasAry.Add(fieldJsonName); } if (fieldAliasAry != null) { foreach (var item in fieldAliasAry) { lstAlasAry.Add(item); //不超过一个字符的不用考虑拼音首字符 if (item.Length <= 1) { continue; } //别名查重,添加中文首字母集合 var firstLetter = ChineseToPinYin.GetPYFirstWord(item); var isContain = lstAlasAry.Exists(x => x.ToString().Trim().ToLower() == firstLetter.Trim().ToLower()); if (isContain) { continue; } lstAlasAry.Add(firstLetter); } } var dataFieldAttrAry = pi.GetCustomAttributes(typeof(DataFieldAttribute), true); DataFieldAttribute dataFieldAttr = null; if (dataFieldAttrAry.Length > 0) { dataFieldAttr = dataFieldAttrAry[0] as DataFieldAttribute; } TableFieldInfoDto dto = new TableFieldInfoDto(); dto.TableName = TableNames[tableType]; dto.FieldName = pi.Name; dto.FieldAlias = string.Join(",", lstAlasAry); dto.CNUnitText = displayFieldAttri.CnUnitText; dto.NoNull = dataFieldAttr.IsNull ? 0 : 1; lstDto.Add(dto); } } return(lstDto); }
async Task doOcrTranslate() { if (brush == null) { return; } NotifyUser("Start OCR process", NotifyType.StatusMessage); WriteableBitmap bitmap = croppedBitmap; // This main API call to extract text from image. OcrResult ocrResult = null; try { if (rbSimple.IsChecked == true) { ocrResult = await ocrEngineSimpl.RecognizeAsync((uint)bitmap.PixelHeight, (uint)bitmap.PixelWidth, bitmap.PixelBuffer.ToArray()); } else { ocrResult = await ocrEngineTraditional.RecognizeAsync((uint)bitmap.PixelHeight, (uint)bitmap.PixelWidth, bitmap.PixelBuffer.ToArray()); } } catch (Exception ocrE) { NotifyUser("OCR error:" + ocrE, NotifyType.ErrorMessage); } // OCR result does not contain any lines, no text was recognized. if (ocrResult != null && ocrResult.Lines != null) { string extractedText = ""; // Iterate over recognized lines of text. foreach (var line in ocrResult.Lines) { foreach (var v in line.Words) { extractedText += v.Text; } extractedText += Environment.NewLine; } NotifyUser("OCR success:", NotifyType.StatusMessage); // txtOCR.Text = extractedText; txtbox111.Text = extractedText; try { txtPin.Text = ChineseToPinYin.Convert3Pin(extractedText); } catch (Exception pinEx) { txtPin.Text = "Error during converting to PinYin"; } NotifyUser("Start translation", NotifyType.StatusMessage); if (cbTranslate.IsChecked == true) { DoTranslate(); } } else { // txtOCR.Text = "No text."; txtbox111.Text = "No text."; txtPin.Text = "No text."; txtTranslation.Text = "No text."; NotifyUser("No text recognized", NotifyType.ErrorMessage); } }
//protected void ComboBox1_DirectChange(object sender, DirectEventArgs e) //{ // Session["depname"] = ComboBox1.SelectedItem.Text; //} protected void gettext_Event(object sender, DirectEventArgs e) { TextField3.Text = ChineseToPinYin.Get(TextField1.Text); }
public static bool ImportStoreSuggestDataBulk(string IndexNew) { int PageSize = int.Parse(ConfigurationManager.AppSettings["PageSize"].ToString()); int PageNumber = 1; var clinet = GetClient(IndexNew); List <int> rs = new List <int>(); Utils.WriteLogFile("ImportStoreSuggestDataBulk开始导入数据(" + IndexNew + ")页大小" + PageSize); while (true) { SQLinq.Dynamic.DynamicSQLinq sql = new SQLinq.Dynamic.DynamicSQLinq("v_ProductInfo_s "); sql = sql.Select("storeid,StoreName name").GroupBy("storeid,StoreName"); sql = sql.Skip(PageSize * (PageNumber - 1)).Take(PageSize).OrderByDescending("storeid"); var list = db.Query <dynamic>(sql); if (list.Count == 0) { break; } string initials = ""; var keywordslist = list.Select(a => new { keywords = new { input = new List <string>() { a.name, ChineseToPinYin.ToPinYin(a.name, ref initials), initials }, output = a.name, payload = new { id = a.storeid.ToString(), type = "store", keyword = "" }, weight = 10 } }); var bk = clinet.Bulk(a => a.IndexMany <object>(keywordslist)); if (bk.Errors) { Utils.WriteLogFile("(页码" + PageNumber + "数据量" + list.Count + ")(" + IndexNew + ")导入有错误,数据来源sql语句--" + sql.ToSQL().ToQuery()); rs.Add(0); } else { Utils.WriteLogFile("(页码" + PageNumber + "数据量" + list.Count + ")(" + IndexNew + ")导入成功"); rs.Add(1); } PageNumber++; } Utils.WriteLogFile("ImportStoreSuggestDataBulk导入数据结束(" + IndexNew + ")"); return(rs.Where(a => a == 0).Count() == 0); }
public static bool ImportBrandSuggestDataBulk(string IndexNew) { int PageSize = int.Parse(ConfigurationManager.AppSettings["PageSize"].ToString()); int PageNumber = 1; var clinet = GetClient(IndexNew); List <int> rs = new List <int>(); Utils.WriteLogFile("ImportBrandSuggestDataBulk开始导入数据(" + IndexNew + ")页大小" + PageSize); while (true) { SQLinq.Dynamic.DynamicSQLinq sql = new SQLinq.Dynamic.DynamicSQLinq("v_ProductInfo_s "); sql = sql.Select("brandid,BrandName name").GroupBy("brandid,BrandName"); sql = sql.Skip(PageSize * (PageNumber - 1)).Take(PageSize).OrderByDescending("brandid"); var list = db.Query <dynamic>(sql); if (list.Count == 0) { break; } List <object> keywordslist = new List <object>(); string initials = ""; string pinyin = ""; string output = ""; SQLinq.Dynamic.DynamicSQLinq sqlkeywords = new SQLinq.Dynamic.DynamicSQLinq("bma_brands "); sqlkeywords = sqlkeywords.Select("brandid,keywords"); var listkeywords = db.Query <dynamic>(sqlkeywords).ToList(); foreach (var item in list) { output = item.name; initials = ""; pinyin = ChineseToPinYin.ToPinYin(output, ref initials); keywordslist.Add(new { keywords = new { input = new List <string>() { output, pinyin, initials }, output = output, payload = new { id = item.brandid.ToString(), type = "brand", keyword = "" }, weight = 20 } }); //添加关键词 var brandinfo = listkeywords.FirstOrDefault(a => a.brandid == item.brandid); if (brandinfo != null && brandinfo.keywords != null) { List <string> brandkeywords = ((string)brandinfo.keywords).Split(',').ToList(); foreach (var key in brandkeywords) { if (key == "") { continue; } output = item.name + key; initials = ""; pinyin = ChineseToPinYin.ToPinYin(output, ref initials); keywordslist.Add(new { keywords = new { input = new List <string>() { output, pinyin, initials }, output = output, payload = new { id = item.brandid.ToString(), type = "brand", keyword = key }, weight = 20 } }); } } } var bk = clinet.Bulk(a => a.IndexMany <object>(keywordslist)); if (bk.Errors) { Utils.WriteLogFile("(页码" + PageNumber + "数据量" + list.Count + ")(" + IndexNew + ")导入有错误,数据来源sql语句--" + sql.ToSQL().ToQuery()); rs.Add(0); } else { Utils.WriteLogFile("(页码" + PageNumber + "数据量" + list.Count + ")(" + IndexNew + ")导入成功"); rs.Add(1); } PageNumber++; } Utils.WriteLogFile("ImportBrandSuggestDataBulk导入数据结束(" + IndexNew + ")"); return(rs.Where(a => a == 0).Count() == 0); }
/// <summary> /// 通过姓名生成登录名 /// </summary> /// <param name="CNName"></param> /// <param name="ENName"></param> /// <returns></returns> public virtual string GetLoginName(string CNName, string ENName) { string tempLoginName = string.Empty; string familyName = string.Empty; if (string.IsNullOrWhiteSpace(CNName) && string.IsNullOrWhiteSpace(ENName)) { return(CNName); } else { CNName = specialcharacterRegex.Replace(CNName, ""); } if (CNName == null) { CNName = string.Empty; } if (ENName == null) { ENName = string.Empty; } //中文名不是中文 if (!ChineseToPinYin.IsChineseRegex(CNName)) { if (!IsLoginNameExists(tempLoginName = ENName)) { return(tempLoginName); } else if (!IsLoginNameExists(tempLoginName = CNName)) { return(tempLoginName); } else if (!IsLoginNameExists(tempLoginName = CNName + "." + ENName)) { return(tempLoginName); } else if (!IsLoginNameExists(tempLoginName = ENName + "." + CNName)) { return(tempLoginName); } return(string.Empty); } else if (IsCompoundSurname(CNName, out familyName))//复姓 { #region 姓 /* * 复姓有4个优先级 */ //第一优先级:姓的全拼+名第一个字母简拼 +第二个字字母简拼 tempLoginName = ChineseCharacterToQuanPinYin(familyName.Substring(0, 1)) + ChineseCharacterToQuanPinYin(familyName.Substring(1)).ToLower() + ChineseCharacterToPinYinAbbreviation(CNName.Substring(2)); if (!IsLoginNameExists(tempLoginName)) { return(tempLoginName); } else //存在 { //第二优先级:姓的全拼+名第一个字字母全拼+名第二个字字母简拼 if (CNName.Length < 3) { tempLoginName = ChineseCharacterToQuanPinYin(familyName.Substring(0, 1)).ToLower() + ChineseCharacterToQuanPinYin(familyName.Substring(1)).ToLower(); } else if (CNName.Length == 3) { tempLoginName = ChineseCharacterToQuanPinYin(familyName.Substring(0, 1)).ToLower() + ChineseCharacterToQuanPinYin(familyName.Substring(1)).ToLower() + ChineseCharacterToQuanPinYin(CNName.Substring(2)).ToLower(); } else if (CNName.Length > 3) { tempLoginName = ChineseCharacterToQuanPinYin(familyName.Substring(0, 1)).ToLower() + ChineseCharacterToQuanPinYin(familyName.Substring(1)).ToLower() + ChineseCharacterToQuanPinYin(CNName.Substring(2, 1)).ToLower() + ChineseCharacterToPinYinAbbreviation(CNName.Substring(3)).ToLower(); } if (!IsLoginNameExists(tempLoginName)) { return(tempLoginName); } else//不存在 { //第三优先级:姓缩写+名缩写 tempLoginName = ChineseCharacterToPinYinAbbreviation(familyName.Substring(0, 1)).ToUpper() + ChineseCharacterToPinYinAbbreviation(familyName.Substring(1)).ToLower() + ChineseCharacterToPinYinAbbreviation(CNName.Substring(2)).ToLower(); if (!IsLoginNameExists(tempLoginName)) { return(tempLoginName); } else { //第四优先级:英文名 if (!IsLoginNameExists(tempLoginName = ENName + "." + ChineseCharacterToPinYinAbbreviation(familyName).ToLower())) { return(tempLoginName); } else { return(string.Empty); } } } } #endregion 姓 } else if (CNName.Length < 5)//单姓 { #region 单姓 /* * 单姓 分为17个优先级 */ //第一优先级:姓的全拼+名第一个字母简拼 +第二个字字母简拼 //string tempLoginName = string.Empty; if (!IsLoginNameExists(tempLoginName = ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)).ToLower() + ChineseCharacterToPinYinAbbreviation(CNName.Substring(1)).ToLower())) { return(tempLoginName); } //第二优先级:姓的全拼+名第一个字字母全拼+名第二个字字母简拼 else if (!IsLoginNameExists(tempLoginName = ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)).ToLower() + ChineseCharacterToQuanPinYin(CNName.Substring(1, 1)).ToLower() + ChineseCharacterToPinYinAbbreviation(CNName.Substring(2)).ToLower())) { return(tempLoginName); } //第三优先级:姓的全拼+名全拼 else if (!IsLoginNameExists(tempLoginName = ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)).ToLower() + ChineseCharacterToQuanPinYin(CNName.Substring(1)).ToLower())) { return(tempLoginName); } //第四优先级:姓全拼.名第一个字字母简拼+名第二个字字母简拼 else if (!IsLoginNameExists(tempLoginName = ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)) + "." + ChineseCharacterToPinYinAbbreviation(CNName.Substring(1)).ToLower())) { return(tempLoginName); } //第五优先级:姓全拼.名第一个字字母全拼+名第二个字字母简拼 else if (!IsLoginNameExists(tempLoginName = ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)) + "." + ChineseCharacterToQuanPinYin(CNName.Substring(1, 1)).ToLower() + ChineseCharacterToPinYinAbbreviation(CNName.Substring(2)).ToLower())) { return(tempLoginName); } //第六优先级:姓全拼.名全拼 else if (!IsLoginNameExists(tempLoginName = ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)) + "." + ChineseCharacterToQuanPinYin(CNName.Substring(1)).ToLower())) { return(tempLoginName); } //第七优先级:姓全拼_名第一个字字母简拼+名第二个字字母简拼 else if (!IsLoginNameExists(tempLoginName = ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)) + "_" + ChineseCharacterToPinYinAbbreviation(CNName.Substring(1)).ToLower())) { return(tempLoginName); } //第八优先级:姓全拼_名第一个字字母全拼+名第二个字字母简拼 else if (!IsLoginNameExists(tempLoginName = ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)) + "_" + ChineseCharacterToQuanPinYin(CNName.Substring(1, 1)).ToLower() + ChineseCharacterToPinYinAbbreviation(CNName.Substring(2)).ToLower())) { return(tempLoginName); } //第九优先级:姓全拼_名全拼 else if (!IsLoginNameExists(tempLoginName = ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)) + "_" + ChineseCharacterToQuanPinYin(CNName.Substring(1)).ToLower())) { return(tempLoginName); } //第十优先级:名缩写+.姓全拼 else if (!IsLoginNameExists(tempLoginName = ChineseCharacterToPinYinAbbreviation(CNName.Substring(1)).ToLower() + "." + ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)).ToLower())) { return(tempLoginName); } //第十一优先级:第一个全,以后简+.姓全拼 else if (!IsLoginNameExists(tempLoginName = ChineseCharacterToQuanPinYin(CNName.Substring(1, 1)).ToLower() + ChineseCharacterToPinYinAbbreviation(CNName.Substring(2)).ToLower() + "." + ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)).ToLower())) { return(tempLoginName); } //第十二优先级:名全称+.姓全拼 else if (!IsLoginNameExists(tempLoginName = ChineseCharacterToQuanPinYin(CNName.Substring(1)).ToLower() + "." + ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)).ToLower())) { return(tempLoginName); } //第十三优先级:英文名+.姓全拼 else if (!string.IsNullOrEmpty(ENName) && !IsLoginNameExists(tempLoginName = ENName + "." + ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)).ToLower())) { return(tempLoginName); } //第十四优先级:英文名+.姓第一个字母+名第一个字字母简拼+名第二个字字母简拼 else if (!string.IsNullOrEmpty(ENName) && !IsLoginNameExists(tempLoginName = ENName + "." + ChineseCharacterToPinYinAbbreviation(CNName.Substring(0, 1)) + ChineseCharacterToPinYinAbbreviation(CNName.Substring(1)).ToLower())) { return(tempLoginName); } //第十五优先级:英文名+.姓全拼+名第一个字字母简拼+名第二个字字母简拼 else if (!string.IsNullOrEmpty(ENName) && !IsLoginNameExists(tempLoginName = ENName + "." + ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)).ToLower() + ChineseCharacterToPinYinAbbreviation(CNName.Substring(1)).ToLower())) { return(tempLoginName); } //第十六优先级:英文名+.姓全拼+名第一个字字母全拼+名第二个字字母简拼 else if (!string.IsNullOrEmpty(ENName) && !IsLoginNameExists(tempLoginName = ENName + "." + ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)).ToLower() + ChineseCharacterToQuanPinYin(CNName.Substring(1, 1)).ToLower() + ChineseCharacterToPinYinAbbreviation(CNName.Substring(2)).ToLower())) { return(tempLoginName); } //第十七优先级:英文名.姓全拼+名全拼 else if (!string.IsNullOrEmpty(ENName) && !IsLoginNameExists(tempLoginName = ENName + "." + ChineseCharacterToQuanPinYin(CNName.Substring(0, 1)).ToLower() + ChineseCharacterToQuanPinYin(CNName.Substring(1)).ToLower())) { return(tempLoginName); } else { return(string.Empty); } #endregion 单姓 } else//归属于少数民族 { #region 少数民族姓名 if (CNName.IndexOf('·') > 0) { if (!IsLoginNameExists(tempLoginName = ChineseCharacterToPinYinAbbreviation(CNName.Replace("·", "")))) { return(tempLoginName); } else if (!IsLoginNameExists(tempLoginName = ChineseCharacterToPinYinAbbreviation(CNName.Substring(0, CNName.IndexOf('·'))) + "." + ChineseCharacterToPinYinAbbreviation(CNName.Substring(CNName.IndexOf('·') + 1)))) { return(tempLoginName); } else if (!IsLoginNameExists(tempLoginName = ENName + "." + ChineseCharacterToPinYinAbbreviation(CNName.Substring(0, CNName.IndexOf('·'))))) { return(tempLoginName); } else { return(string.Empty); } } else { if (!IsLoginNameExists(tempLoginName = ChineseCharacterToPinYinAbbreviation(CNName))) { return(tempLoginName); } else { return(string.Empty); } } #endregion 少数民族姓名 } }