public static void HomographsImport() { // Clear collections for new data WordForm.Homographs = new List <List <WordForm> >(); WordRoot.Roots = new HashSet <WordRoot>(); using (StreamReader sr = new StreamReader("export.txt", System.Text.Encoding.UTF8)) { string[] lineParts = { }; int wId, rId; string wTitle, wDef, rTitle, rDef; List <WordForm> homos = new List <WordForm>(); while (!sr.EndOfStream) { lineParts = sr.ReadLine().Split('║'); wId = Convert.ToInt32(lineParts[3].Split(':')[1].Trim()); wTitle = lineParts[4].Split(':')[1].Trim(); wDef = lineParts[5].Split(':')[1].Trim(); rId = Convert.ToInt32(lineParts[0].Split(':')[1].Trim()); rTitle = lineParts[1].Split(':')[1].Trim(); rDef = lineParts[2].Split(':')[1].Trim(); WordForm wf = new WordForm(wId, rId, wTitle, wDef); WordRoot wr = new WordRoot(rId, rTitle, rDef); // Prevent duplicates if (!WordRoot.Roots.Any(item => item.Id == rId)) { WordRoot.Roots.Add(wr); } if (homos.LastOrDefault() != null && wf.Title.Equals(homos.LastOrDefault().Title)) { homos.Add(wf); } else if (homos.LastOrDefault() != null) { WordForm.Homographs.Add(homos); homos = new List <WordForm>(); homos.Add(wf); } else { homos.Add(wf); } } // Add the last homographs collection because the check happens only after the each iteration WordForm.Homographs.Add(homos); Console.WriteLine("HomographsImport - Done"); } }
public string GetTranslation() { string noSignsFilePath = "maciev-dictionary-no-signs.txt"; string translation = ""; if (Id == 0) { Regex re = new Regex("^" + Title + "\\s"); foreach (var line in File.ReadLines(noSignsFilePath)) { var matches = re.Matches(line); foreach (var m in matches) { return(line); } } } else { translation = "см. " + WordRoot.GetWordRoot(RootId).Title; } return(translation); }