public void getDicTemp(string word) { //检查词库是否被加载, 如果没有加载,则返回空字符串数组 try { char first, second, secondKey; resulList.Clear(); string key; if (word.Length < 3) { return; } #region //从词库一个一个地读取词 first = word[0]; this.DicTemp.Clear(); for (int i = 0; i < this.myDicList.Count; i++) { //两个词的长度区别大于2,则忽略 key = myDicList[i]; //如果大开了智能功能,则执行以下算法 (可以设) if (Spelling.ContainChar(first, ououeiae)) { //如果被检词的第一个字母时没有加 "ئ" 的元音的话暂时不提供智能分析 } else if (first != 'ئ') { #region 如果第一个字母维复音 if (word[0] != key[0]) { continue; } else { if (key.Length < 3) { continue; } second = word[1]; secondKey = key[1]; if (Spelling.ContainChar(second, ei)) { if (!Spelling.ContainChar(secondKey, ei)) { continue; } } else if (Spelling.ContainChar(second, ouou)) { if (!Spelling.ContainChar(secondKey, ouou)) { continue; } } else { } } } #endregion else { #region 如果被检此地第一个字母是元音的前缀 如:"ئ" if (key.Length < 3) { continue; } second = word[1]; secondKey = key[1]; if (Spelling.ContainChar(second, ei)) { if (key[0] != 'ئ' || !Spelling.ContainChar(secondKey, ei)) { continue; } } else if (Spelling.ContainChar(second, ouou)) { if (key[0] != 'ئ' || !Spelling.ContainChar(secondKey, ouou)) { continue; } } else if (Spelling.ContainChar(second, ae)) { if (key[0] != 'ئ' || !Spelling.ContainChar(secondKey, ae)) { continue; } } else { if (!Spelling.ContainChar(secondKey, ei)) { continue; } } #endregion } #endregion this.DicTemp.Add(i); } } catch (NullReferenceException nee) { this.errMessage = nee.Message; } }
/// <summary> /// Calculates the minimum number of change, inserts or deletes /// required to change firstWord into secondWord /// </summary> /// <param name="source" type="string"> /// <para> /// The first word to calculate /// </para> /// </param> /// <param name="target" type="string"> /// <para> /// The second word to calculate /// </para> /// </param> /// <returns> /// The number of edits to make firstWord equal secondWord /// </returns> /// <remarks> /// This method automatically gives priority to matching the first and last char /// </remarks> public string[] getSuggestionsTemp(string word, int needCount, bool firstLetterSame, bool lastLetterSame) { //检查词库是否被加载, 如果没有加载,则返回空字符串数组 try { char first, second, secondKey; string[] result; float[] value; float disf; if (word.Length <= 2) { return(new string[] { }); } resulList.Clear(); #region //从词库一个一个地读取词 first = word[0]; string key; for (int i = 0; i < this.myDicList.Count; i++) { //两个词的长度区别大于2,则忽略 key = myDicList[i]; if (Math.Abs(word.Length - key.Length) > this.ignoredLength) { continue; } if (key.Length < 3) { continue; } //如果大开了智能功能,则执行以下算法 (可以设) if (firstLetterSame == true) { #region 智能分析 if (Spelling.ContainChar(first, ououeiae)) { //如果被检词的第一个字母时没有加 "ئ" 的元音的话暂时不提供智能分析 } else if (first != 'ئ') { #region 如果第一个字母维复音 if (word[0] != key[0]) { continue; } else { second = word[1]; secondKey = key[1]; if (Spelling.ContainChar(second, ei)) { if (!Spelling.ContainChar(secondKey, ei)) { continue; } } else if (Spelling.ContainChar(second, ouou)) { if (!Spelling.ContainChar(secondKey, ouou)) { continue; } } else { //因为维语中有一些不符合维语传统规格的词(外来),所以取消了这部分. 如:(كرېدىتلىق , پسىخىكىسىدىمۇ) //if (!ei.IsMatch(secondKey)) //{ // continue; //} } } } #endregion else { #region 如果被检此地第一个字母是元音的前缀 如:"ئ" second = word[1]; secondKey = key[1]; if (Spelling.ContainChar(second, ei)) { if (key[0] != 'ئ' || !Spelling.ContainChar(secondKey, ei)) { continue; } } else if (Spelling.ContainChar(second, ouou)) { if (key[0] != 'ئ' || !Spelling.ContainChar(secondKey, ouou)) { continue; } } else if (Spelling.ContainChar(second, ae)) { if (key[0] != 'ئ' || !Spelling.ContainChar(secondKey, ae)) { continue; } } else { if (!Spelling.ContainChar(secondKey, ei)) { continue; } } #endregion } #endregion } //if (lastLetterSame == true) //{ // if (word.Length > 12) // { // if (getLevenshtein_distance(word.Substring(word.Length - 3, 3), word.Substring(key.Length - 3, 3)) > 1) // { continue; } // } //} //两个词的最后字母不同,则忽略(可以设) if (lastLetterSame == true && word[word.Length - 1] != key[key.Length - 1]) { continue; } if ((disf = this.getLDPercent(word, key)) > 0.6F) { resulList.Add(key, disf); } }//while((link = link.Next) != null ); #endregion //排列并过滤工作 //如果没有推荐词返回空 if (resulList.Count == 0) { return(new string[] { }); } int count = resulList.Keys.Count; value = new float[count]; result = new string[count]; resulList.Keys.CopyTo(result, 0); for (int i = 0; i < count; i++) { value[i] = resulList[result[i]]; } //排列 this.Sort(ref value, ref result); //如果需要的推荐总数参数为-0的话,返回所有 if (needCount == -1) { return(result); } else { #region 需要的数目切 if (result.Length > needCount) { string[] strs = new string[needCount]; for (int i = 0; i < needCount; i++) { strs[i] = result[i]; } return(strs); } return(result); #endregion } } catch (NullReferenceException nee) { this.errMessage = nee.Message; return(new string[] { }); } }