private Dictionary <string, double> Comment_Word = new Dictionary <string, double>(); //装饰词,如“非常”等 //double public void Analyze(TeacherData teacher) { foreach (var comment in teacher.CommentList) { string text = comment.Text; //文本 int weight = comment.Vote; //权重 } }
public static FacultyData GetFaculty(TeacherData teacher, string name) { FacultyData thisFaculty; if ((thisFaculty = FacultyList.Where(f => f.Name == name).FirstOrDefault()) != null) { thisFaculty.TeacherList.Add(teacher); thisFaculty.TeacherCount++; return(thisFaculty); } else { var newFaculty = new FacultyData { Name = name, TeacherCount = 1 }; newFaculty.TeacherList.Add(teacher); FacultyList.Add(newFaculty); return(newFaculty); } }
public void GetTeacherDataFromCsv(FileStream file) { TeacherData.totalTeacherList.Clear(); //读取前先清空当前已读取的内容 CourseData.courseDataList.Clear(); FacultyData.FacultyList.Clear(); using (StreamReader streamReader = new StreamReader(file, Encoding.Default)) { string teacherLine = string.Empty; while ((teacherLine = streamReader.ReadLine()) != null) { var Line = teacherLine.Split(','); TeacherData thisTeacher = new TeacherData() { Name = Line[0], ID = int.Parse(Line[1]), Url = Line[2], }; thisTeacher.Faculty = FacultyData.GetFaculty(thisTeacher, Line[3]); thisTeacher.Score = (Line[4] == "N/A") ? 0 : double.Parse(Line[4]); thisTeacher.CallNameRate = double.Parse(Line[5].Replace("%", "")) / 100.0; thisTeacher.VoteNum = (Line[6] == "<5") ? 0 : int.Parse(Line[6]); thisTeacher.CommentNum = (Line[7] == "<5") ? 0 : int.Parse(Line[7]); if (thisTeacher.VoteNum < 5) { thisTeacher.HasEnoughData = false; thisTeacher.CallNameState = TeacherData.CallName_enum.Unknown; } else if (thisTeacher.CallNameRate > 0.5) { thisTeacher.CallNameState = TeacherData.CallName_enum.Yes; } else if (thisTeacher.CallNameRate > 0.2) { thisTeacher.CallNameState = TeacherData.CallName_enum.Possible; } else { thisTeacher.CallNameState = TeacherData.CallName_enum.No; } var hisCourseList = new List <CourseData>(); double overallGPA_number; for (int i = 8; i < Line.Length - 2; i++) { string courseName; if ((courseName = Line[i]) == string.Empty) { break; } while (true) { i++; try { overallGPA_number = double.Parse(Line[i]); break; } catch { courseName += $",{Line[i]}"; } } i++; string overallGPASize_string = Line[i]; int overallGPASize_int = int.Parse(overallGPASize_string.Replace("+", "")); var thisCourseData = new CourseData() { Name = courseName, GPASampleSizeOfTeacher_string = overallGPASize_string, GPASampleSizeOfTeacher_int = overallGPASize_int, OverallGPAOfTeacher = overallGPA_number }; hisCourseList.Add(thisCourseData); var query = from c in CourseData.courseDataList//需要debug where c.Name == courseName select c; if (!query.Any()) { var courseData = new CourseData(); courseData.Name = courseName; courseData.CourseTeachers = new List <TeacherData>(); courseData.CourseTeachers.Add(thisTeacher); courseData.TotalGPA += overallGPA_number * overallGPASize_int; courseData.TotalSampleSize += overallGPASize_int; courseData.OverallGPAOfThisCourse = courseData.TotalGPA / courseData.TotalSampleSize; CourseData.courseDataList.Add(courseData); } else { foreach (var courseData in CourseData.courseDataList.Select(x => x).Where(x => x.Name == courseName)) { courseData.CourseTeachers.Add(thisTeacher); courseData.TotalGPA += overallGPA_number * overallGPASize_int; courseData.TotalSampleSize += overallGPASize_int; courseData.OverallGPAOfThisCourse = courseData.TotalGPA / courseData.TotalSampleSize; } } } thisTeacher.CourseList = hisCourseList; var commentString = streamReader.ReadLine(); var comments = commentString.Split(','); var count = comments.Count(); for (int i = 0; i < count - 1; i = i + 3) { thisTeacher.CommentList.Add(new CommentData() { Text = comments[i].Replace("&NewLine", Environment.NewLine), Vote = int.Parse(comments[i + 1]), Time = DateTime.Parse(comments[i + 2]) }); } TeacherData.totalTeacherList.Add(thisTeacher); } } }
public TeacherDataForm(TeacherData inputTeacherData) { this.teacherData = inputTeacherData; InitializeComponent(); ListAllItems(); }