Esempio n. 1
0
        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();
        }
        /// <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);
        }