public static TextClassificator CreateLearnedInstance(string themeGroupName) { if (_learnedInstances == null) _learnedInstances = new Dictionary<string, TextClassificator>(); if (!_learnedInstances.ContainsKey(themeGroupName)) { var separators = new List<string>(); var fs = (string)Resource.ResourceManager.GetObject(TextClassificator.SeparatorsFileName); separators = fs.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList(); var stopWords = new List<string>(); fs = (string)Resource.ResourceManager.GetObject(TextClassificator.StopWordsFileName); stopWords = fs.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList(); var instance = new TextClassificator(separators, stopWords); var themes = new Dictionary<string, string>(); instance.Learn(themeGroupName, themes); _learnedInstances.Add(themeGroupName, instance); } return _learnedInstances[themeGroupName]; }
/// <summary>создать обученный экземпляр классификатора (все значения берутся по умолчанию) /// </summary> /// <returns></returns> public static TextClassificator CreateLearnedInstance() { var separators = new List<string>(); var fs = (string)Resource.ResourceManager.GetObject(TextClassificator.SeparatorsFileName); separators = fs.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList(); var stopWords = new List<string>(); fs = (string)Resource.ResourceManager.GetObject(TextClassificator.StopWordsFileName); stopWords = fs.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).ToList(); var instance = new TextClassificator(separators, stopWords); var themes = new Dictionary<string, string>(); foreach (System.Collections.DictionaryEntry file in Resource.ResourceManager.GetResourceSet(new System.Globalization.CultureInfo("ru-RU"), true, true)) { if (file.Key.ToString()[0] == '_') { var text = file.Value.ToString(); text = text.ToLower(); text = DeleteWords(text, separators, false); text = DeleteWords(text, stopWords); text = DeleteDoubleSpaceAndBadSymbols(text); themes.Add(file.Key.ToString().TrimStart('_'), text); } } using (var db = new TextClassificatorEntities()) { instance.Learn(db.ThemeGroup.Single(tg => tg.ThemeGroup_id == 1).ThemeGroup_name, themes); } return instance; }