Beispiel #1
0
        static QuoteSystem()
        {
            s_systems = new List <QuoteSystem>();

            var doc = new XmlDocument();

            doc.LoadXml(Resources.QuoteSystemData);
            foreach (XmlNode node in doc.SafeSelectNodes("//QuoteSystem"))
            {
                s_systems.Add(XmlSerializationHelper.DeserializeFromString <QuoteSystem>(node.OuterXml));
            }

            var systemsWithAllLevels = new List <QuoteSystem>();

            foreach (var quoteSystem in s_systems)
            {
                foreach (var level2 in QuoteUtils.GetLevel2Possibilities(quoteSystem.FirstLevel))
                {
                    var qs = new QuoteSystem(quoteSystem);
                    if (!string.IsNullOrWhiteSpace(quoteSystem.Name))
                    {
                        qs.Name = String.Format("{0} with levels 2 ({1}/{2}) and 3.", quoteSystem.Name, level2.Open, level2.Close);
                    }
                    qs.AllLevels.Add(level2);
                    qs.AllLevels.Add(QuoteUtils.GenerateLevel3(qs, true));
                    systemsWithAllLevels.Add(qs);
                }
            }
            s_systems.AddRange(systemsWithAllLevels);
        }
Beispiel #2
0
        public static List <BookScript> TestQuoteSystem(Project project, QuoteSystem altQuoteSystem)
        {
            var cvInfo = new CombinedCharacterVerseData(project);

            var unparsedBlocks = Unparse(project.Books);

            var blocksInBook = unparsedBlocks.ToDictionary(bookidBlocksPair => bookidBlocksPair.Key.BookId, bookidBlocksPair => bookidBlocksPair.Value);

            var parsedBlocksByBook = new ConcurrentDictionary <string, BookScript>();

            SetQuoteSystem(altQuoteSystem);
            Parallel.ForEach(blocksInBook, bookidBlocksPair =>
            {
                var bookId = bookidBlocksPair.Key;
                var blocks =
                    new QuoteParser(cvInfo, bookId, bookidBlocksPair.Value, project.Versification).Parse().ToList();
                var parsedBook = new BookScript(bookId, blocks);
                parsedBlocksByBook.AddOrUpdate(bookId, parsedBook, (s, script) => parsedBook);
            });

            // sort the list
            var bookScripts = parsedBlocksByBook.Values.ToList();

            bookScripts.Sort((a, b) => BCVRef.BookToNumber(a.BookId).CompareTo(BCVRef.BookToNumber(b.BookId)));
            return(bookScripts);
        }
 private static void IncrementScore(Dictionary <QuoteSystem, int> scores, QuoteSystem quoteSystem, int increment, ref int bestScore)
 {
     scores[quoteSystem] += increment;
     if (scores[quoteSystem] > bestScore)
     {
         bestScore = scores[quoteSystem];
     }
 }
Beispiel #4
0
        public static QuoteSystem GetOrCreateQuoteSystem(QuotationMark firstLevel, string quotationDashMarker, string quotationDashEndMarker)
        {
            var newQuoteSystem = new QuoteSystem(firstLevel, quotationDashMarker, quotationDashEndMarker);

            var match = s_systems.SingleOrDefault(qs => qs.Equals(newQuoteSystem));

            return(match ?? newQuoteSystem);
        }
Beispiel #5
0
 public QuoteParser(ICharacterVerseInfo cvInfo, string bookId, IEnumerable <Block> blocks, QuoteSystem quoteSystem = null, ScrVers versification = null)
 {
     m_cvInfo        = cvInfo;
     m_bookId        = bookId;
     m_bookNum       = BCVRef.BookToNumber(bookId);
     m_inputBlocks   = blocks;
     m_quoteSystem   = quoteSystem ?? QuoteSystem.Default;
     m_versification = versification ?? ScrVers.English;
     GetRegExesForSplittingQuotes();
 }
Beispiel #6
0
 protected bool Equals(QuoteSystem other)
 {
     if (other == null)
     {
         return(false);
     }
     if (AllLevels == null)
     {
         return(other.AllLevels == null);
     }
     if (other.AllLevels == null)
     {
         return(false);
     }
     return(AllLevels.SequenceEqual(other.AllLevels));
 }
Beispiel #7
0
        public static QuotationMark GenerateLevel3(QuoteSystem system, bool concatenateContinuers)
        {
            if (system.NormalLevels.Count < 2)
            {
                throw new ArgumentException("Cannot generate level 3 unless levels 1 and 2 are defined.");
            }
            var    level1 = system.FirstLevel;
            string level3Continuer;

            if (concatenateContinuers)
            {
                level3Continuer = system.NormalLevels[1].Continue + " " + level1.Continue;
            }
            else
            {
                level3Continuer = level1.Continue;
            }
            return(new QuotationMark(level1.Open, level1.Close, level3Continuer, 3, QuotationMarkingSystemType.Normal));
        }
Beispiel #8
0
 public QuoteSystem(QuoteSystem quoteSystem) : this()
 {
     AllLevels.AddRange(quoteSystem.AllLevels.Select(l => new QuotationMark(l.Open, l.Close, l.Continue, l.Level, l.Type)));
 }
Beispiel #9
0
 public static void SetQuoteSystem(QuoteSystem quoteSystem)
 {
     s_quoteSystem = quoteSystem;
 }
Beispiel #10
0
 public static void SetQuoteSystem(QuoteSystem quoteSystem)
 {
     s_quoteSystem = quoteSystem;
     Block.InitializeInterruptionRegEx(quoteSystem.QuotationDashMarker != null && quoteSystem.QuotationDashMarker.Any(c => c == '\u2014' || c == '\u2015'));
 }