/// <summary> /// 获取更新的标签 /// </summary> /// <param name="personlabels"></param> /// <param name="sentences"></param> /// <returns></returns> private string GetUpdateLabels(List <Label> personlabels, List <int> newsIds) { string updateLabels = null; if (personlabels != null) { MysqlHelper mysqlHelper = new MysqlHelper(); string content = mysqlHelper.GetLabelContent(newsIds); for (int i = 0; i < personlabels.Count; i++) { List <Sentence> sentences = GetLabelSentences(personlabels[i].LabelName, content); string updateLabel = GetUpdateLabel(personlabels[i].LabelName, sentences); if (IsUpdateLabelValuabel(updateLabel)) { updateLabels += updateLabel + ","; } } } return(updateLabels); }
private void ThreadFunction() { MysqlHelper mysqlHelper = new MysqlHelper(); while (true) { Person oneperson = DequeuePerson(); if (oneperson != null) { List <Label> personlabels = new List <Label>(); Console.WriteLine("------->" + oneperson.PersonName); List <Sentence> sentences = GetSentences(ref oneperson, content); personlabels = ParseSentence(sentences); string labels = null; string updateLabels = null; if (personlabels != null && personlabels.Count != 0) { labels = GetLabelStr(personlabels); } if (personlabels != null && personlabels.Count != 0) { updateLabels = GetUpdateLabels(personlabels, oneperson.NewsIds); } oneperson.Labels = labels; oneperson.UpdateLabels = updateLabels; oneperson.Time = DateTime.Now; if (labels != null) { _persons.Add(oneperson); } else { Console.WriteLine(oneperson.PersonName); } } else { break; } } int i = 0; foreach (var thread in _thread_person) { if (thread != null && thread.ThreadState == ThreadState.Running) { i++; } } if (i == 1) { DateTime now = DateTime.Now; foreach (var person in _persons) { int year = now.Year; int month = now.Month; int date = now.Day; int hour = now.Hour; DateTime datetime = new DateTime(year, month, date, hour, 0, 0); person.ClassifyTime = datetime; mysqlHelper.InsertPerson(person); } Console.WriteLine("分析结束-------------------〉" + DateTime.Now); } }