/// <summary> /// 取得关键词和等级 /// </summary> /// <param name="sourceText"></param> /// <returns></returns> private SentenceClass GetLevels(string sourceText) { SentenceClass sc = new SentenceClass(); List <SentenceKeywordClass> levels = new List <SentenceKeywordClass>(); Dictionary <string, string> xkhValue = new Dictionary <string, string>(); ReadXiaoKuoHao(sourceText, ref xkhValue, ref sourceText);//处理小括号 sc.XKHValue = xkhValue; // Debug.Log(sourceText); Dictionary <string, string> zkhValue = new Dictionary <string, string>(); ReadZhongKuoHao(sourceText, ref zkhValue, ref sourceText);//处理中括号 sc.ZKHValues = zkhValue; // Debug.Log(sourceText); string[] strs = sourceText.ToLower().Split(' ');//切割字符串 Qia!!! //List<string> onceStrList = new List<string>();//一级缓冲池 for (int i = 0; i < strs.Length; i++) { string str = strs[i];//获取源 if (string.IsNullOrEmpty(str.Trim())) { continue; //舍去异常的源 } string[] oneStrs = str.Split('='); //分割源 if (oneStrs.Length == 0) { continue; } SentenceKeywordClass skc = new SentenceKeywordClass(); skc.words = new List <string>(oneStrs); string reT = ""; skc.sorce = GetStarCount(oneStrs[0], ref reT) + 1; // Debug.Log(reT); skc.words[0] = reT; levels.Add(skc); // onceStrList.Add(str);//载入一级缓冲池 } sc.sentenceKeywordClasses = levels; //一级缓冲池填装完毕! return(sc); }
/// <summary> /// 取得成绩(Key为总,Value为自己的成绩) /// </summary> /// <param name="sourceText"></param> /// <param name="voiceText"></param> /// <returns></returns> private KeyValuePair <int, int> GetMyGradeFromString(string sourceText, string voiceText) { sourceText = sourceText.ToLower(); voiceText = voiceText.ToLower(); SentenceClass sc = GetLevels(sourceText); //替换小括号 List <string> strs = new List <string>(sc.XKHValue.Keys); for (int i = 0; i < strs.Count; i++) { string str = sc.XKHValue[strs[i]]; voiceText = voiceText.Replace(str + " ", strs[i] + " "); } // Debug.Log(voiceText); //替换中括号 List <string> strs1 = new List <string>(sc.ZKHValues.Keys); for (int i = 0; i < strs1.Count; i++) { string str = sc.ZKHValues[strs1[i]]; voiceText = voiceText.Replace(str + " ", strs1[i] + " "); } // Debug.Log(voiceText); List <string> vTs = new List <string>(voiceText.Split(' ')); List <SentenceKeywordClass> sentenceKeywordClasses = sc.sentenceKeywordClasses; int all = 0; int my = 0; for (int i = 0; i < sentenceKeywordClasses.Count; i++) { SentenceKeywordClass skc = sentenceKeywordClasses[i]; all += skc.sorce; for (int j = 0; j < skc.words.Count; j++) { //识别 string str = skc.words[j]; /* * int start= voiceText.IndexOf(str); * int end = voiceText.IndexOf(" ",start) ; * if (end == -1) end = voiceText.Length - 1; * if (start == -1 || end < start) continue; * if ((end - start) == str.Length) * my += skc.sorce; * else * my +=Mathf.Clamp(skc.sorce - 1,0,10); * voiceText = voiceText.Remove(start, end-start); */ //KeyValuePair<int, string> word = skc.words[j]; //if(j==0)all+= // Debug.Log("信息:" + str); if (vTs.Contains(str)) { my += skc.sorce; vTs.RemoveAt(vTs.IndexOf(str)); //Debug.Log("存在" + str); break; } for (int k = 0; k < vTs.Count; k++) { if (vTs[k].Contains(str)) { my += Mathf.Clamp(skc.sorce - 1, 0, 10); vTs.RemoveAt(i); Debug.Log("半存在" + str); break; } } } } return(new KeyValuePair <int, int>(all, my)); }