static int add_max(int count, string tempdis) { //将疾病中frequency最大的finding找出并加入到globalvarible.question里; string temp1 = "NULL"; string temp2 = "NULL"; string temp3 = "NULL"; int max_frequency = 0; foreach (symbol temp5 in globalvarible.disease[tempdis]) { ask ask_temp1 = new ask(); ask_temp1.propertyname = temp5.propertyname; ask_temp1.findingname = temp5.findingname; ask_temp1.findingtype = temp5.findingtype; // ask_temp1.optionname = new List<string>(); if (!globalvarible.question.Contains(ask_temp1) && temp5.frequency > max_frequency) { max_frequency = temp5.frequency; temp1 = temp5.findingname; temp2 = temp5.propertyname; temp3 = temp5.findingtype; } } if (max_frequency > 0) { //找到了最大的frequency; ask ask_temp2 = new ask(); ask_temp2.propertyname = temp2; ask_temp2.findingname = temp1; ask_temp2.findingtype = temp3; // ask_temp2.optionname = new List<string>(); globalvarible.question.Add(ask_temp2); count++; } return(count); }
static void disease_remove(int num) { //有很多候选疾病,依据排除疾病的方法; Dictionary <List <string>, int> total_sign = new Dictionary <List <string>, int>(); string temp1 = ""; //findingname; string temp2 = ""; //propertyname; string temp3 = ""; //findingtype; //total_sign 统计每个<findingname,propertyname>出现的个数,方便查找出现次数最多的症候组合; #region foreach (string key in globalvarible.possibility.Keys) { if (num <= 0) { break; } num--; foreach (symbol sign in globalvarible.disease[key]) { if (globalvarible.count < 2 && sign.findingtype == "Laboratory") { continue;//当询问次数在两次以内的时候不考虑Labratory; } temp1 = sign.findingname; temp2 = sign.propertyname; temp3 = sign.findingtype; List <string> temp = new List <string>(); temp.Add(temp1); temp.Add(temp2); temp.Add(temp3); if (total_sign.ContainsKey(temp)) { total_sign[temp]++; } else { total_sign.Add(temp, 1); } } } if (total_sign.Keys.Count > 1) { var dissort = from objDic in total_sign orderby objDic.Value descending select objDic;//对value排序 Dictionary <List <string>, int> temp_total = new Dictionary <List <string>, int>(); foreach (KeyValuePair <List <string>, int> temp4 in dissort) { temp_total.Add(temp4.Key, temp4.Value); } total_sign.Clear(); total_sign = temp_total; } #endregion int count = 0; foreach (List <string> temp in total_sign.Keys) { if (total_sign[temp] > 2) { if (count > 8) { break; } count++; temp1 = temp[0]; temp2 = temp[1]; temp3 = temp[2]; ask temp4 = new ask(); temp4.findingname = temp1; temp4.propertyname = temp2; temp4.findingtype = temp3; // temp4.optionname = new List<string>(); globalvarible.question.Add(temp4); } } //当共同症候总数少于8时,询问每种候选疾病的最大frequency对应症候; #region if (count < 8) { foreach (string tempdis in globalvarible.possibility.Keys) { count = add_max(count, tempdis); if (count >= 8) { break; } } } #endregion }