public void Query() { var map = GetTranslationMap(); var optionsBuilder = new DbContextOptionsBuilder <DictionaryContext>(); optionsBuilder.UseSqlite("Data source=dict.db"); var _context = new DictionaryContext(optionsBuilder.Options); var lastId = _context.DictionaryEntries.OrderBy(e => e.Id).Last().Id; var last = 0; while (last < lastId) { var set = _context.DictionaryEntries .Where(e => e.Id > last) .OrderBy(e => e.Id) .Take(1000); foreach (var entry in set) { _context.Update(entry); string translation; if (map.TryGetValue(entry.Lemma, out translation)) { entry.Translation = translation; } ; } last = set.Last().Id; _context.SaveChanges(); } }
public static void SetStressIndex() { var optionsBuilder = new DbContextOptionsBuilder <DictionaryContext>(); optionsBuilder.UseSqlite("Data source=dict.db"); var _context = new DictionaryContext(optionsBuilder.Options); using (var inputStream = new FileStream(@"C:\Users\Willem\Downloads\ru-ru_ozhegov_shvedova_cc_v2_0.dsl", FileMode.Open)) { int cnt = 0; StreamReader reader = new StreamReader(inputStream); while (!reader.EndOfStream) { while (char.IsWhiteSpace((char)reader.Peek())) { reader.ReadLine(); } string lemma = reader.ReadLine(); DictionaryEntry entry = _context.DictionaryEntries.Where(de => de.Lemma == lemma).FirstOrDefault(); if (entry != null) { string definition = reader.ReadLine(); if (definition.Contains("_")) { Match match = Regex.Match(definition, "[А-Я]+(?=_)"); if (match.Success) { _context.Update(entry); entry.StressIndex = match.Value.Length; cnt++; if (cnt % 500 == 0) { _context.SaveChanges(); } } } } } _context.SaveChanges(); } }