private void AttachWordFrequencyOnSingleKanaMatch() { _log.InfoFormat("Attaching word frequency on single kana match..."); VocabDao dao = new VocabDao(); dao.OpenMassTransaction(); foreach (string line in FileReadingHelper.ReadLineByLine(PathHelper.WordUsagePath, Encoding.UTF8)) { if (!string.IsNullOrWhiteSpace(line)) { string[] split = line.Trim().Split('|'); long? rank = ParsingHelper.ParseLong(split[0]); if (split.Count() == 3 && rank.HasValue) { string kanjiReading = split[1]; string kanaReading = split[2]; if (kanjiReading == kanaReading) { if (dao.UpdateFrequencyRankOnSingleKanaMatch(kanaReading, (int)rank.Value)) { _log.InfoFormat("{0} has a frequency of {1}", kanaReading, rank.Value); } } } } } dao.CloseMassTransaction(); }
public CategoryFilterControl() { InitializeComponent(); VocabDao dao = new VocabDao(); DataContext = dao; var converter = new VocabCategoriesToStringConverter(); var allCategories = dao.GetAllCategories().ToList(); var filteredCategories = allCategories.Where(cat => { // These are various types of archaic verbs. // We remove these from the category list for two reasons: // 1) The user would see these as individual categories; // 2) None of these categories currently have any vocab words. switch (cat.ShortName) { case "v4k": case "v4g": case "v4s": case "v4t": case "v4n": case "v4b": case "v4m": case "v2k-k": case "v2g-k": case "v2t-k": case "v2d-k": case "v2h-k": case "v2b-k": case "v2m-k": case "v2y-k": case "v2r-k": case "v2k-s": case "v2g-s": case "v2s-s": case "v2z-s": case "v2t-s": case "v2d-s": case "v2n-s": case "v2h-s": case "v2b-s": case "v2m-s": case "v2y-s": case "v2r-s": case "v2w-s": return(false); } object convertedValue = converter.Convert(cat, null, null, null); return(!string.IsNullOrWhiteSpace(convertedValue as string)); }).ToList(); HiddenList.ItemsSource = filteredCategories; ComboBox.ItemsSource = filteredCategories; }
/// <summary> /// Command callback. /// Called to switch between two variants of a vocab entry. /// </summary> /// <param name="variant">Variant to switch to.</param> private void OnSwitchVocab(VocabVariant variant) { int index = LoadedItems.IndexOf(variant.Parent); if (index >= 0) { VocabEntity newVocab = new VocabDao().GetVocabById(variant.Variant.ID); LoadedItems[index] = new ExtendedVocab(newVocab, newVocab.SrsEntries.Any() ? new ExtendedSrsEntry(newVocab.SrsEntries.First()) : null); } }
static CategoryFilterViewModel() { var converter = new VocabCategoriesToStringConverter(); VocabDao dao = new VocabDao(); var allCategories = dao.GetAllCategories().OrderBy(cat => cat.Label); categories = allCategories.Where( cat => { // These are various types of archaic verbs. // We remove these from the category list for two reasons: // 1) The user would see these as individual categories; // 2) None of these categories currently have any vocab words. switch (cat.ShortName) { case "v4k": case "v4g": case "v4s": case "v4t": case "v4n": case "v4b": case "v4m": case "v2k-k": case "v2g-k": case "v2t-k": case "v2d-k": case "v2h-k": case "v2b-k": case "v2m-k": case "v2y-k": case "v2r-k": case "v2k-s": case "v2g-s": case "v2s-s": case "v2z-s": case "v2t-s": case "v2d-s": case "v2n-s": case "v2h-s": case "v2b-s": case "v2m-s": case "v2y-s": case "v2r-s": case "v2w-s": return(false); } object convertedValue = converter.Convert(cat, null, null, null); return(!string.IsNullOrWhiteSpace(convertedValue as string)); }).ToArray(); }
static VocabCategoriesToStringConverter() { CategoryDictionary = new Dictionary<long, VocabCategoryInfo>(); VocabDao vocabDao = new VocabDao(); foreach (VocabCategory category in vocabDao.GetAllCategories()) { VocabCategoryInfo info = GetInfo(category); if (info != null) { CategoryDictionary.Add(category.ID, info); } } }
/// <summary> /// Before going to the next step, read all items! /// </summary> public override bool OnNextStep() { // Initialize fields _parent.NewEntries = new List <SrsEntry>(); StringBuilder log = new StringBuilder(); log.AppendLine(string.Format("Starting import with {0} line(s).", _parent.CsvLines.Count)); int i = 0; var vocabDao = new VocabDao(); var kanjiDao = new KanjiDao(); vocabDao.OpenMassTransaction(); // Browse CSV lines! foreach (List <string> row in _parent.CsvLines) { log.AppendFormat("l{0}: ", ++i); // Attempt to read the entry. SrsEntry entry = ReadEntry(row, vocabDao, kanjiDao, log); log.AppendLine(); // Add the entry to the parent's list if not null. if (entry != null) { _parent.NewEntries.Add(entry); } } vocabDao.CloseMassTransaction(); // All items have been added. // Apply the timing preferences for items that do not have a review date. _parent.ApplyTiming(); // Pray for the plural log.AppendLine(string.Format("Finished with {0} new entries.", _parent.NewEntries.Count)); // Set the import log. We're good. _parent.ImportLog = log.ToString(); return(true); }
/// <summary> /// Builds a ViewModel aimed at editing an existing SrsEntry, /// or adding a pre-composed SrsEntry. /// </summary> /// <param name="entity">Entity to edit.</param> public SrsEntryViewModel(SrsEntry entity) { // Initialize fields. _entry = new ExtendedSrsEntry(entity); _originalNextReviewDate = entity.NextAnswerDate; _originalLevelValue = entity.CurrentGrade; _associatedKanjiString = Entry.AssociatedKanji; _associatedVocabString = Entry.AssociatedVocab; _srsEntryDao = new SrsEntryDao(); _kanjiDao = new KanjiDao(); _vocabDao = new VocabDao(); if (IsNew) { Entry.Tags = Properties.Settings.Default.LastSrsTagsValue; } // Create the relay commands. SubmitCommand = new RelayCommand(OnSubmit); CancelCommand = new RelayCommand(OnCancel); SrsProgressResetCommand = new RelayCommand(OnSrsProgressReset); ApplyAssociatedKanjiCommand = new RelayCommand(OnApplyAssociatedKanji); ApplyAssociatedVocabCommand = new RelayCommand(OnApplyAssociatedVocab); ToggleSuspendCommand = new RelayCommand(OnToggleSuspend); DeleteCommand = new RelayCommand(OnDelete); ToggleDateEditCommand = new RelayCommand(OnToggleDateEdit); DateToNowCommand = new RelayCommand(OnDateToNow); DateToNeverCommand = new RelayCommand(OnDateToNever); // Get the associated kanji or vocab. GetAssociatedKanji(); GetAssociatedVocab(); // Initialize the VM. _isFirstSrsLevelSelect = true; SrsLevelPickerVm = new SrsLevelPickerViewModel(); SrsLevelPickerVm.SrsLevelSelected += OnSrsLevelSelected; SrsLevelPickerVm.Initialize(_entry.CurrentGrade); }
/// <summary> /// Reads an SRS item from a field row using the parameters of the view model. /// </summary> /// <param name="row">Row to read.</param> /// <param name="log">Log under the form of a stringbuilder to inform the user about how everything goes.</param> /// <returns>The SRS item read if successful. A null value otherwise.</returns> private SrsEntry ReadEntry(List <string> row, VocabDao vocabDao, KanjiDao kanjiDao, StringBuilder log) { try { SrsEntry entry = new SrsEntry(); string kanjiReading = row[_kanjiReadingColumn]; if (string.IsNullOrEmpty(kanjiReading)) { log.AppendFormat("Empty kanji reading. Skipping."); return(null); } // Figure out item type. CsvItemType itemType = ReadItemType(row); if (itemType == CsvItemType.Kanji || (itemType == CsvItemType.Unspecified && (_noTypeBehavior == CsvImportNoTypeBehavior.AllKanji || (_noTypeBehavior == CsvImportNoTypeBehavior.Auto && kanjiReading.Length == 1)))) { // Three solutions to set as kanji: // 1. Item is manually specified as kanji in source data. // 2. Item is not specified and no type behavior is set to AllKanji. // 3. Item is not specified and no type behavior is set to Auto and the length of kanjiReading is exactly 1. entry.AssociatedKanji = kanjiReading; log.AppendFormat("Kanji: \"{0}\". ", kanjiReading); itemType = CsvItemType.Kanji; } else { // All other cases will lead to vocab. entry.AssociatedVocab = kanjiReading; log.AppendFormat("Vocab: \"{0}\". ", kanjiReading); itemType = CsvItemType.Vocab; } string readings = ReadAcceptedReadings(row); long?sequenceNumber = ReadSequenceNumber(row); if (ReadingAutofill || MeaningAutofill) { switch (itemType) { case CsvItemType.Kanji: var kanji = kanjiDao.GetFirstMatchingKanji(kanjiReading); if (kanji == null) { log.Append("Can't find kanji in database. Skipping."); return(null); } entry.LoadFromKanji(kanji); break; case CsvItemType.Vocab: var vocabs = string.IsNullOrEmpty(readings) ? vocabDao.GetMatchingVocab(kanjiReading) : vocabDao.GetVocabByReadings(kanjiReading, readings); if (sequenceNumber.HasValue) { vocabs = vocabs.Where(v => v.Seq == sequenceNumber); } var vocab = vocabs.FirstOrDefault(); if (vocab == null) { log.Append("Can't find vocab in database. Skipping."); return(null); } entry.LoadFromVocab(vocab); entry.AssociatedVocab = kanjiReading; entry.Readings = default(string); break; } } // Find readings. if (!ReadingAutofill || !string.IsNullOrEmpty(readings)) { entry.Readings = readings; } if (itemType == CsvItemType.Kanji && string.IsNullOrEmpty(entry.Readings)) { log.Append("Empty readings. Skipping."); return(null); } // Find meanings. string meanings = ReadAcceptedMeanings(row); if (!MeaningAutofill || !string.IsNullOrEmpty(meanings)) { entry.Meanings = meanings; } if (string.IsNullOrEmpty(entry.Meanings)) { log.Append("Empty meanings. Skipping."); return(null); } // Find all optional info. entry.MeaningNote = ReadMeaningNotes(row); entry.ReadingNote = ReadReadingNotes(row); entry.Tags = ReadTags(row); entry.CurrentGrade = ReadStartLevel(row); entry.NextAnswerDate = ReadNextReviewDate(row); log.Append("OK."); return(entry); } catch (Exception ex) { log.AppendFormat("Unknown error: \"{0}\". Skipping.", ex.Message); } return(null); }
/// <summary> /// Builds a filtered vocab list using the provided filter. /// </summary> /// <param name="filter">Vocab filter.</param> public FilteredVocabIterator(VocabFilter filter) : base(filter) { _vocabDao = new VocabDao(); }