public void LoadLexicalizedWords(string themeGroup, string theme, List<string> words) { words = words.Distinct().ToList(); words = words.Where(w => !string.IsNullOrWhiteSpace(w)).ToList(); words = words.Select(w => NormilizeText(w)).ToList(); using (var db = new TextClassificatorEntities()) { _themeGroupId = db.ThemeGroup.Single(tg => tg.ThemeGroup_name == themeGroup).ThemeGroup_id; if (!db.Theme.Any(th => th.Theme_name == theme)) { db.Theme.AddObject(new Theme { ThemeGroup_id = _themeGroupId, Theme_name = theme, Theme_caption = theme, System_InsDT = DateTime.Now }); db.SaveChanges(); } var themeObj = db.Theme.Single(th => th.Theme_name == theme && th.ThemeGroup_id == _themeGroupId); var newWords = words.Except(db.Word.Select(w => w.Word_name)).Select(w => new Word { Word_name = w, System_InsDT = DateTime.Now }).ToList(); newWords.ToList().ForEach(w => db.Word.AddObject(w)); db.SaveChanges(); foreach (var word in words) { var wordObj = db.Word.Single(w => w.Word_name == word); if (db.WordNotInTheme.Any(w => w.Theme_id == themeObj.Theme_id && w.Word_id == wordObj.Word_id)) continue; var wc = db.WordCandidatesInTheme.SingleOrDefault(w => w.Theme_id == themeObj.Theme_id && w.Word_id == wordObj.Word_id); if (wc != null) { db.WordCandidatesInTheme.DeleteObject(wc); db.SaveChanges(); } var wt = db.WordInTheme.SingleOrDefault(w => w.Theme_id == themeObj.Theme_id && w.Word_id == wordObj.Word_id); if (wt != null) { db.WordInTheme.DeleteObject(wt); db.SaveChanges(); } db.WordInTheme.AddObject(new WordInTheme { Word_id = wordObj.Word_id, Theme_id = themeObj.Theme_id, WordInTheme_isLexicalizedWord = true, System_InsDT = DateTime.Now }); db.SaveChanges(); } } }
/// <summary>экспорт результатов текущего обучения в базу (без учёта весов) для дальнейшей ручной группировки слов /// </summary> public void ExportToDataBase(string themeGroupName) { using (var db = new TextClassificatorEntities()) { _themeGroupId = db.ThemeGroup.Single(tg => tg.ThemeGroup_name == themeGroupName).ThemeGroup_id; var newGroups = Groups.Except(db.Theme.Where(th => th.ThemeGroup_id == _themeGroupId).Select(th => th.Theme_name)).Select(th => new Theme { ThemeGroup_id = _themeGroupId, Theme_name = th, Theme_caption = th, System_InsDT = DateTime.Now }).ToList(); newGroups.ToList().ForEach(th => db.Theme.AddObject(th)); db.SaveChanges(); var newWords = _wordsWeigthsInGroupsIncludingOtherGroups.Keys.Except(db.Word.Select(w => w.Word_name)).Select(w => new Word { Word_name = w, System_InsDT = DateTime.Now }).ToList(); newWords.ToList().ForEach(w => db.Word.AddObject(w)); db.SaveChanges(); foreach (var allWord in _wordsWeigthsInGroupsIncludingOtherGroups.Select(w => w.Key)) { var stem = _stemOfWord[allWord]; var word = db.Word.Single(w => w.Word_name == allWord); var currentAllologs = db.Allolog.Where(a => a.Word_id == word.Word_id); var newAllogs = stem.Except(currentAllologs.Select(a => a.Allolog_name)).Select(a => new Allolog { Allolog_name = a, Word_id = word.Word_id, System_InsDT = DateTime.Now }).ToList(); newAllogs.ForEach(a => db.Allolog.AddObject(a)); db.SaveChanges(); } foreach (var theme in Groups) { var words = new List<string>(); words.AddRange ( from gr in db.Theme join wc in db.WordCandidatesInTheme on gr.Theme_id equals wc.Theme_id join w in db.Word on wc.Word_id equals w.Word_id where gr.Theme_name == theme where gr.ThemeGroup_id == _themeGroupId select w.Word_name ); words.AddRange ( from gr in db.Theme join wc in db.WordInTheme on gr.Theme_id equals wc.Theme_id join w in db.Word on wc.Word_id equals w.Word_id where gr.Theme_name == theme where gr.ThemeGroup_id == _themeGroupId select w.Word_name ); words.AddRange ( from gr in db.Theme join wc in db.WordNotInTheme on gr.Theme_id equals wc.Theme_id join w in db.Word on wc.Word_id equals w.Word_id where gr.Theme_name == theme where gr.ThemeGroup_id == _themeGroupId select w.Word_name ); words = words.Distinct().ToList(); var wordsInGroup = _wordsWeigthsInGroupsIncludingOtherGroups.Where(w => w.Value.Any(gr => gr.Key == theme)).Select(w => w.Key); var newWordsInGroup = wordsInGroup.Except(words); var group = db.Theme.Single(th => th.Theme_name == theme && th.ThemeGroup_id == _themeGroupId); foreach (var newWordInGroup in newWordsInGroup) { var word = db.Word.Single(w => w.Word_name == newWordInGroup); db.WordCandidatesInTheme.AddObject(new WordCandidatesInTheme { Word_id = word.Word_id, Theme_id = group.Theme_id, System_InsDT = DateTime.Now, WordCandidatesInTheme_Visible = true }); } db.SaveChanges(); } } }