static GramInfo() { var enRuDic = new Dictionary <string, string>(); var gramsDic = new Dictionary <string, GramInfo>(); var gList = new List <GramInfo>(); using (Stream stream = Utils.GetResourceStream("DeepMorphy.grams.xml")) { var rdr = XmlReader.Create(new StreamReader(stream, Encoding.UTF8)); List <Cls> clsList = null; while (rdr.Read()) { if (rdr.Name == "G" && rdr.NodeType == XmlNodeType.Element) { if (gList.Any()) { gList.Last().Classes = clsList.ToArray(); } var gr = new GramInfo() { Index = int.Parse(rdr.GetAttribute("index")), KeyEn = rdr.GetAttribute("key_en"), KeyRu = rdr.GetAttribute("key_ru"), }; enRuDic[gr.KeyEn] = gr.KeyRu; clsList = new List <Cls>(); gList.Add(gr); gramsDic[gr.KeyEn] = gr; gramsDic[gr.KeyRu] = gr; } else if (rdr.Name == "C" && rdr.NodeType == XmlNodeType.Element) { var cls = new GramInfo.Cls() { NNIndex = rdr.GetAttribute("nn_index") == null ? (long?)null : long.Parse(rdr.GetAttribute("nn_index")), KeyEn = rdr.GetAttribute("key_en"), KeyRu = rdr.GetAttribute("key_ru"), }; enRuDic[cls.KeyEn] = cls.KeyRu; clsList.Add(cls); } } gList.Last().Classes = clsList.ToArray(); } GramsInfo = gList.ToArray(); EnRuDic = new ReadOnlyDictionary <string, string>(enRuDic); RuEnDic = new ReadOnlyDictionary <string, string>(EnRuDic.ToDictionary(x => x.Value, x => x.Key)); GramsDic = new ReadOnlyDictionary <string, GramInfo>(gramsDic); GramCatIndexDic = new ReadOnlyDictionary <int, GramInfo>(gList.ToDictionary(x => x.Index, x => x)); }
internal TagHelper(bool useEn) { _useEn = useEn; if (!useEn) { _postKey = GramInfo.TranslateKeyToRu(_postKey); _nmbrKey = GramInfo.TranslateKeyToRu(_nmbrKey); _gndrKey = GramInfo.TranslateKeyToRu(_gndrKey); _caseKey = GramInfo.TranslateKeyToRu(_caseKey); _persKey = GramInfo.TranslateKeyToRu(_persKey); _tensKey = GramInfo.TranslateKeyToRu(_tensKey); _moodKey = GramInfo.TranslateKeyToRu(_moodKey); _voicKey = GramInfo.TranslateKeyToRu(_voicKey); } TagsDic = useEn ? TagsEnDic : TagsRuDic; }