public static dictId parse(string s, string prefix) { dictId dict = new dictId { prefix = prefix }; if (prefix != null) { s = s.Substring(prefix.Length); } foreach (var lng in LowUtils.EnumGetValues <Langs>()) { var ls = langStr[lng] + "_"; if (s.StartsWith(ls)) { dict.natLang = lng; string subS = s.Substring(ls.Length); foreach (var toLng in LowUtils.EnumGetValues <Langs>()) { if (subS == langStr[toLng]) { dict.crsLang = toLng; return(dict); } } } } throw new Exception(s); }
public dictOptions() { string dirFn = Machines.rootPath + @"RwDicts\LingeaSound\dir.txt"; if (!File.Exists(dirFn)) { var temp = Directory.EnumerateFiles(Machines.rootPath + @"RwDicts\LingeaSound", "*.info", SearchOption.AllDirectories). Select(fn => fn.Split('\\').Reverse().Take(2).Concat(File.ReadAllText(fn).Split('=')).ToArray()). Select(parts => new { id = parts[1] + "/" + parts[0].Replace(".info", null), crsLang = LowUtils.EnumParse <Langs>(parts[2]), word = parts[3] }).ToArray(); sounds = temp.GroupBy(s => s.crsLang).ToDictionary(g => g.Key, g => g.GroupBy(cg => cg.word.ToLower()).ToDictionary(cg => cg.Key, cg => cg.First().id)); File.WriteAllLines(dirFn, sounds.SelectMany(kv => kv.Value.Select(skv => kv.Key.ToString() + "|" + skv.Key + "|" + skv.Value)).OrderBy(w => w)); } else { sounds = File.ReadAllLines(dirFn).Select(l => l.Split('|')). Select(parts => new { crsLang = LowUtils.EnumParse <Langs>(parts[0]), text = parts[1], url = parts[2] }). GroupBy(l => l.crsLang). ToDictionary(g => g.Key, g => g.ToDictionary(tu => tu.text, tu => tu.url)); } }