Ejemplo n.º 1
0
        public BlockMatchup GetBlocksForVerseMatchedToReferenceText(BookScript vernacularBook, int iBlock, ScrVers vernacularVersification, uint predeterminedBlockCount = 0)
        {
            if (iBlock < 0 || iBlock >= vernacularBook.GetScriptBlocks().Count)
            {
                throw new ArgumentOutOfRangeException("iBlock");
            }

            if (!CanDisplayReferenceTextForBook(vernacularBook))
            {
                return(null);
            }

            int bookNum = BCVRef.BookToNumber(vernacularBook.BookId);
            var verseSplitLocationsBasedOnRef = GetVerseSplitLocations(vernacularBook.BookId);

            var matchup = new BlockMatchup(vernacularBook, iBlock, portion =>
            {
                MakesSplits(portion, bookNum, vernacularVersification, verseSplitLocationsBasedOnRef, "vernacular", LanguageName);
            },
                                           nextVerse => IsOkayToSplitAtVerse(nextVerse, vernacularVersification, verseSplitLocationsBasedOnRef),
                                           this, predeterminedBlockCount);

            if (!matchup.AllScriptureBlocksMatch)
            {
                MatchVernBlocksToReferenceTextBlocks(matchup.CorrelatedBlocks, vernacularBook.BookId, vernacularVersification);
            }
            return(matchup);
        }
Ejemplo n.º 2
0
        protected virtual IList <CharacterVerse> ProcessLine(string[] items, int lineNumber)
        {
            var list = new List <CharacterVerse>();

            if (items.Length < kiQuoteType)
            {
                throw new ApplicationException("Bad format in CharacterVerse control file! Line #: " + lineNumber + "; Line contents: " + string.Join("\t", items));
            }
            if (items.Length > kMaxItems)
            {
                throw new ApplicationException("Incorrect number of fields in CharacterVerse control file! Line #: " + lineNumber + "; Line contents: " + string.Join("\t", items));
            }

            int chapter;

            if (!Int32.TryParse(items[1], out chapter))
            {
                Debug.Assert(false, string.Format("Invalid chapter number ({0}) on line {1}: {2}", items[1], lineNumber, items[0]));
            }
            for (int verse = BCVRef.VerseToIntStart(items[2]); verse <= BCVRef.VerseToIntEnd(items[2]); verse++)
            {
                list.Add(CreateCharacterVerse(new BCVRef(BCVRef.BookToNumber(items[0]), chapter, verse), items));
            }

            return(list);
        }
Ejemplo n.º 3
0
        public string ToString(bool includeReference, string bookId = null)
        {
            if (!includeReference)
            {
                return(ToString());
            }

            if (bookId == null && !string.IsNullOrEmpty(BookCode))
            {
                bookId = BookCode;
            }
            int bookNum;

            if (bookId == null)
            {
                bookId  = string.Empty;
                bookNum = 1;
            }
            else
            {
                bookNum = BCVRef.BookToNumber(bookId);
            }

            var startRef = new BCVRef(bookNum, ChapterNumber, InitialStartVerseNumber);
            var endRef   = new BCVRef(bookNum, ChapterNumber, LastVerseNum);

            return(BCVRef.MakeReferenceString(bookId, startRef, endRef, ":", "-") + " : " + ToString());
        }
Ejemplo n.º 4
0
        public void GetIndicesOfFirstBlockAtReference_InFirstBook_ReturnsIndices()
        {
            var result = m_navigator.GetIndicesOfFirstBlockAtReference(new VerseRef(BCVRef.BookToNumber("LUK"), 1, 1));

            Assert.AreEqual(0, result.BookIndex);
            Assert.AreEqual(1, result.BlockIndex);
        }
        public void DataIntegrity_AlternateAccompaniedByAnotherCharacter()
        {
            var acceptablePrimaryQuoteTypes = new List <QuoteType>
            {
                QuoteType.Normal,
                QuoteType.Potential,
                QuoteType.Quotation,
                QuoteType.Hypothetical,
                QuoteType.Implicit,
                QuoteType.ImplicitWithPotentialSelfQuote
            };
            var numberOfAcceptableQuoteTypesInOT = acceptablePrimaryQuoteTypes.Count;

            foreach (var alternate in ControlCharacterVerseData.Singleton.GetAllQuoteInfo()
                     .Where(i => i.QuoteType == QuoteType.Alternate))
            {
                if (alternate.BookCode == "MAT" && acceptablePrimaryQuoteTypes.Count == numberOfAcceptableQuoteTypesInOT)
                {
                    acceptablePrimaryQuoteTypes.Remove(QuoteType.Hypothetical);
                }
                var otherEntries = ControlCharacterVerseData.Singleton.GetCharacters(BCVRef.BookToNumber(alternate.BookCode),
                                                                                     alternate.Chapter, new SingleVerse(alternate.Verse), ScrVers.English)
                                   .Where(c => acceptablePrimaryQuoteTypes.Contains(c.QuoteType)).ToList();
                Assert.IsFalse(otherEntries.Any(c => c.Character == alternate.Character && c.Delivery == alternate.Delivery),
                               $"Alternate used for a {alternate.Character} in {alternate.BookCode} {alternate.Chapter}:{alternate.Verse}, " +
                               "but that character also has another quote type in that verse!");
                Assert.IsTrue(otherEntries.Any(c => c.QuoteType != QuoteType.Quotation || !c.Character.StartsWith("narrator-") ||
                                               // PG-1248: Because of the logic in AdjustData, this Alternate could be a Quotation that was turned into
                                               // an Alternate because there was a corresponding narrator Quotation that should be considered as primary.
                                               // If so, we don't want to flag this as a mistake.
                                               c.Character == alternate.DefaultCharacter),
                              $"Character-verse file contains an Alternate quote for {alternate.Character} in {alternate.BookCode} {alternate.Chapter}:{alternate.Verse}" +
                              ", but there is no primary character.");
            }
        }
Ejemplo n.º 6
0
        private void CheckBoxNewTestament_CheckedChanged(object sender, EventArgs e)
        {
            if (m_checkBoxNewTestament.Checked)
            {
                foreach (DataGridViewRow row in m_ntBooksGrid.Rows)
                {
                    if (m_storedNtSelections.Contains(m_availableNtBooks[row.Index].Code))
                    {
                        m_ntBooksGrid[m_includeInScriptColumnIndex, row.Index].Value = true;
                    }
                }
            }
            else
            {
                m_storedNtSelections = m_includeInScript.Where(p => BCVRef.BookToNumber(p.Key) > 39 && p.Value).Select(p => p.Key).ToList();
                foreach (DataGridViewRow row in m_ntBooksGrid.Rows)
                {
                    m_ntBooksGrid[m_includeInScriptColumnIndex, row.Index].Value = false;
                }
            }

            m_ntBooksGrid.Enabled = m_checkBoxNewTestament.Checked;

            UpdateState();
        }
Ejemplo n.º 7
0
 public UsxParser(string bookId, IStylesheet stylesheet, XmlNodeList nodeList)
 {
     m_bookId     = bookId;
     m_bookNum    = BCVRef.BookToNumber(m_bookId);
     m_stylesheet = stylesheet;
     m_nodeList   = nodeList;
 }
Ejemplo n.º 8
0
        public void GetIndicesOfFirstBlockAtReference_TwoBlockAtSameReference_ReturnsIndicesForFirstMatch()
        {
            var result = m_navigator.GetIndicesOfFirstBlockAtReference(new VerseRef(BCVRef.BookToNumber("ROM"), 5, 7));

            Assert.AreEqual(1, result.BookIndex);
            Assert.AreEqual(2, result.BlockIndex);
        }
        public void GetCharacterOverrideDetailsForRefRange_VerseBeforeFirstVerseInOverriddenChapter_ReturnsEmpty()
        {
            var bookNum  = BCVRef.BookToNumber("EZR");
            var ezra7_26 = new VerseRef(new BCVRef(bookNum, 7, 26), ScrVers.English);

            Assert.IsFalse(NarratorOverrides.GetCharacterOverrideDetailsForRefRange(ezra7_26, 26).Any());
        }
Ejemplo n.º 10
0
        public BlockMatchup GetBlocksForVerseMatchedToReferenceText(BookScript vernacularBook, int iBlock, ScrVers vernacularVersification)
        {
            if (iBlock < 0 || iBlock >= vernacularBook.GetScriptBlocks().Count)
            {
                throw new ArgumentOutOfRangeException("iBlock");
            }

            if (!Books.Any(b => b.BookId == vernacularBook.BookId))
            {
                return(null);
            }

            int bookNum       = BCVRef.BookToNumber(vernacularBook.BookId);
            var referenceBook = Books.Single(b => b.BookId == vernacularBook.BookId);
            var verseSplitLocationsBasedOnRef = GetVerseSplitLocations(referenceBook, bookNum);

            var matchup = new BlockMatchup(vernacularBook, iBlock, portion =>
            {
                MakesSplits(portion, bookNum, vernacularVersification, verseSplitLocationsBasedOnRef, "vernacular", LanguageName);
            },
                                           nextVerse =>
            {
                nextVerse.Versification = vernacularVersification;
                return(verseSplitLocationsBasedOnRef.Any(s => s.Before.CompareTo(nextVerse) == 0));
            }, this);

            if (!matchup.AllScriptureBlocksMatch)
            {
                MatchVernBlocksToReferenceTextBlocks(matchup.CorrelatedBlocks, vernacularBook.BookId, vernacularVersification);
            }
            return(matchup);
        }
Ejemplo n.º 11
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Parse a reference like "MAT.1.2", returning the integer equivalent.
        /// </summary>
        /// <param name="sRef"></param>
        /// <returns></returns>
        /// -----------------------------------------------------------------------------------
        private static BCVRef SetOxesRef(string sRef)
        {
            if (string.IsNullOrEmpty(sRef))
            {
                return(null);
            }

            string[] rgs = sRef.Split('.');
            if (rgs.Length == 0)
            {
                return(null);
            }

            int nBook = BCVRef.BookToNumber(rgs[0]);

            if (nBook <= 0)
            {
                return(null);
            }

            BCVRef bcvref = new BCVRef(nBook, 0, 0);

            int val;

            if (rgs.Length > 1 && int.TryParse(rgs[1], out val))
            {
                bcvref.Chapter = val;
                if (rgs.Length > 2 && int.TryParse(rgs[2], out val))
                {
                    bcvref.Verse = val;
                }
            }

            return(bcvref);
        }
        public void GetCharacterOverrideDetailsForRefRange_ChapterAfterAnyOverrideInBook_ReturnsEmpty()
        {
            var bookNum  = BCVRef.BookToNumber("EZR");
            var ezra10_1 = new VerseRef(new BCVRef(bookNum, 10, 1), ScrVers.English);

            Assert.IsFalse(NarratorOverrides.GetCharacterOverrideDetailsForRefRange(ezra10_1, 1).Any());
        }
        public void GetCharacterOverrideDetailsForRefRange_RangeOnlyPartiallyWithinOverride_ReturnsEmpty(string bookId, int chapter, int startVerse, int endVerse)
        {
            var bookNum  = BCVRef.BookToNumber(bookId);
            var verseRef = new VerseRef(new BCVRef(bookNum, chapter, startVerse), ScrVers.English);

            Assert.IsFalse(NarratorOverrides.GetCharacterOverrideDetailsForRefRange(verseRef, endVerse).Any());
        }
        [TestCase("PSA", 33, 23, ExpectedResult = "David")]         // Should map to PSA 34:23 (Original) -> PSA 34:22 (English)
        public string GetCharacterOverrideDetailsForRefRange_VulgateVersificationChapterOutsideOfOverrideRangeBeforeMappingToEnglish_MapsToReturnCorrectOverrideCharacter(string bookId, int chapter, int verse)
        {
            var bookNum  = BCVRef.BookToNumber(bookId);
            var verseRef = new VerseRef(new BCVRef(bookNum, chapter, verse), ScrVers.Vulgate);

            return(NarratorOverrides.GetCharacterOverrideDetailsForRefRange(verseRef, verse).Single().Character);
        }
        public void GetCharacterOverrideDetailsForRefRange_RangeStartsInVerseZeroInMultiChapterOverride_ReturnsEmpty()
        {
            var bookNum  = BCVRef.BookToNumber("PSA");
            var verseRef = new VerseRef(new BCVRef(bookNum, 45, 0), ScrVers.English);

            Assert.IsFalse(NarratorOverrides.GetCharacterOverrideDetailsForRefRange(verseRef, 2).Any());
        }
Ejemplo n.º 16
0
        private void SizeRefColumnForCurrentBook()
        {
            m_userIsResizingColumns     = false;
            m_colReference.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;

            int bookNum     = BCVRef.BookToNumber(m_viewModel.CurrentBookId);
            var lastChapter = m_viewModel.Versification.LastChapter(bookNum);
            var maxVerse    = 0;

            for (int i = 1; i <= lastChapter; i++)
            {
                maxVerse = Math.Max(maxVerse, m_viewModel.Versification.LastVerse(bookNum, i));
            }

            var startRef  = new BCVRef(bookNum, lastChapter, maxVerse - 1);
            var endRef    = new BCVRef(bookNum, lastChapter, maxVerse);
            var refString = m_viewModel.GetReferenceString(startRef, endRef);

            DataGridViewCellStyle cellStyle = m_colReference.DefaultCellStyle;

            using (Graphics g = CreateGraphics())
            {
                Debug.Assert(CellBorderStyle == DataGridViewCellBorderStyle.Single);
                const int       borderWidth = 1;
                TextFormatFlags flags       = ComputeTextFormatFlagsForCellStyleAlignment(m_viewModel.Font.RightToLeftScript);
                m_colReference.Width = DataGridViewTextBoxCell.MeasureTextWidth(g, refString,
                                                                                cellStyle.Font ?? DefaultCellStyle.Font, Int32.MaxValue, flags) +
                                       cellStyle.Padding.Horizontal + borderWidth;
            }

            CalculateMinimumWidth();

            m_bookIdUsedToSizeRefColumn = m_viewModel.CurrentBookId;
        }
        public void GetCharacterOverrideDetailsForRefRange_VerseAfterLastVerseInOverriddenChapter_ReturnsEmpty()
        {
            var bookNum     = BCVRef.BookToNumber("NEH");
            var nehemiah7_6 = new VerseRef(new BCVRef(bookNum, 7, 6), ScrVers.English);

            Assert.IsFalse(NarratorOverrides.GetCharacterOverrideDetailsForRefRange(nehemiah7_6, 6).Any());
        }
Ejemplo n.º 18
0
        private IEnumerable <string> GetUniqueOtNtBooks()
        {
            var books = new SortedSet <string>(Comparer <string> .Create((a, b) => BCVRef.BookToNumber(a).CompareTo(BCVRef.BookToNumber(b))));

            foreach (Verse reference in References)
            {
                var bcvRef = new BCVRef(reference.VerseText);
                if (bcvRef.BookIsValid)
                {
                    books.Add(BCVRef.NumberToBookCode(bcvRef.Book));
                }
                else if (Char.IsLetter(reference.VerseText.Last()))
                {
                    bcvRef = new BCVRef(reference.VerseText.Substring(0, reference.VerseText.Length - 1));
                    if (bcvRef.BookIsValid)
                    {
                        books.Add(BCVRef.NumberToBookCode(bcvRef.Book));
                    }
                    else
                    {
                        Debug.Fail(reference.VerseText);
                    }
                }
                else
                {
                    Debug.Fail(reference.VerseText);
                }
            }
            return(books);
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
        public static List <BookScript> ParseBooks(IEnumerable <UsxDocument> books, IStylesheet stylesheet, Action <int> reportProgressAsPercent)
        {
            var numBlocksPerBook = new ConcurrentDictionary <string, int>();
            var blocksInBook     = new ConcurrentDictionary <string, XmlNodeList>();

            Parallel.ForEach(books, usxDoc =>
            {
                var nodeList = usxDoc.GetChaptersAndParas();
                blocksInBook.AddOrUpdate(usxDoc.BookId, nodeList, (s, list) => nodeList);
                numBlocksPerBook.AddOrUpdate(usxDoc.BookId, nodeList.Count, (s, i) => nodeList.Count);
            });
            int allBlocks = numBlocksPerBook.Values.Sum();

            int completedBlocks = 0;
            var bookScripts     = new List <BookScript>(blocksInBook.Count);

            Parallel.ForEach(blocksInBook, book =>
            {
                var bookId     = book.Key;
                var bookScript = new UsxParser(bookId, stylesheet, book.Value).CreateBookScript();
                lock (bookScripts)
                    bookScripts.Add(bookScript);
                Logger.WriteEvent("Added bookScript ({0}, {1})", bookId, bookScript.BookId);
                completedBlocks += numBlocksPerBook[bookId];
                reportProgressAsPercent?.Invoke(MathUtilities.Percent(completedBlocks, allBlocks, 99));
            });

            // This code is an attempt to figure out how we are getting null reference exceptions on the Sort call (See PG-275 & PG-287)
            // The above call to lock bookScripts probably fixes the problem!!! :-) We hope...
            foreach (var bookScript in bookScripts)
            {
                if (bookScript?.BookId == null)
                {
                    var nonNullBookScripts    = bookScripts.Where(b => b != null).Select(b => b.BookId);
                    var nonNullBookScriptsStr = Join(";", nonNullBookScripts);
                    var initialMessage        = bookScript == null ? "BookScript is null." : "BookScript has null BookId.";
                    throw new ApplicationException($"{initialMessage} Number of BookScripts: {bookScripts.Count}. " +
                                                   $"BookScripts which are NOT null: {nonNullBookScriptsStr}");
                }
            }

            try
            {
                bookScripts.Sort((a, b) => BCVRef.BookToNumber(a.BookId).CompareTo(BCVRef.BookToNumber(b.BookId)));
            }
            catch (NullReferenceException n)
            {
                // This code is an attempt to figure out how we are getting null reference exceptions on the Sort call (See PG-275 & PG-287)
                StringBuilder sb = new StringBuilder();
                foreach (var bookScript in bookScripts)
                {
                    sb.Append(Environment.NewLine).Append(bookScript.BookId).Append("(").Append(BCVRef.BookToNumber(bookScript.BookId)).Append(")");
                }
                throw new NullReferenceException("Null reference exception while sorting books." + sb, n);
            }

            reportProgressAsPercent?.Invoke(100);
            return(bookScripts);
        }
Ejemplo n.º 21
0
        public void UseDefaultForMultipleChoiceCharacter_NoExplicitDefault_UseFirst()
        {
            var block = new Block("p", 40, 8);

            block.CharacterId = "chief cupbearer/chief baker";
            block.UseDefaultForMultipleChoiceCharacter(BCVRef.BookToNumber("GEN"));
            Assert.AreEqual("chief cupbearer", block.CharacterIdInScript);
        }
        public void GetCharacterOverrideDetailsForRefRange_EndVerseLessThanStartVerse_ThrowsArgumentOutOfRangeException()
        {
            var bookNum  = BCVRef.BookToNumber("PSA");
            var verseRef = new VerseRef(new BCVRef(bookNum, 45, 2), ScrVers.English);

            Assert.Throws <ArgumentOutOfRangeException>(() => NarratorOverrides.GetCharacterOverrideDetailsForRefRange(verseRef, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => NarratorOverrides.GetCharacterOverrideDetailsForRefRange(verseRef, 1));
        }
Ejemplo n.º 23
0
 public void GetLastChapterForBook()
 {
     Assert.AreEqual(2, VersificationTable.Get(ScrVers.English).LastChapter(
                         BCVRef.BookToNumber("HAG")));
     Assert.AreEqual(150, VersificationTable.Get(ScrVers.English).LastChapter(
                         BCVRef.BookToNumber("PSA")));
     Assert.AreEqual(0, VersificationTable.Get(ScrVers.English).LastChapter(-1));
 }
Ejemplo n.º 24
0
        public void UseDefaultForMultipleChoiceCharacter_ExplicitDefault_UseDefault()
        {
            var block = new Block("p", 9, 11);

            block.CharacterId = "Peter (Simon)/James/John";
            block.UseDefaultForMultipleChoiceCharacter(BCVRef.BookToNumber("MRK"));
            Assert.AreEqual("John", block.CharacterIdInScript);
        }
        public void GetCharacterOverrideDetailsForRefRange_LastVerseInOverride_ReturnsCorrectOverrideCharacter()
        {
            var bookNum     = BCVRef.BookToNumber("NEH");
            var nehemiah7_5 = new VerseRef(new BCVRef(bookNum, 7, 5), ScrVers.English);

            Assert.AreEqual("Nehemiah",
                            NarratorOverrides.GetCharacterOverrideDetailsForRefRange(nehemiah7_5, 5).Single().Character);
        }
        public void GetCharacterOverrideDetailsForRefRange_FirstVerseInOverride_ReturnsCorrectOverrideCharacter()
        {
            var bookNum  = BCVRef.BookToNumber("EZR");
            var ezra7_27 = new VerseRef(new BCVRef(bookNum, 7, 27), ScrVers.English);

            Assert.AreEqual("Ezra, priest and teacher",
                            NarratorOverrides.GetCharacterOverrideDetailsForRefRange(ezra7_27, 27).Single().Character);
        }
Ejemplo n.º 27
0
        public static List <BookScript> ParseProject(IEnumerable <UsxDocument> books, IStylesheet stylesheet, BackgroundWorker projectWorker)
        {
            var numBlocksPerBook = new ConcurrentDictionary <string, int>();
            var blocksInBook     = new ConcurrentDictionary <string, XmlNodeList>();

            Parallel.ForEach(books, bookScript =>
            {
                var nodeList = bookScript.GetChaptersAndParas();
                blocksInBook.AddOrUpdate(bookScript.BookId, nodeList, (s, list) => nodeList);
                numBlocksPerBook.AddOrUpdate(bookScript.BookId, nodeList.Count, (s, i) => nodeList.Count);
            });
            int allProjectBlocks = numBlocksPerBook.Values.Sum();

            int completedProjectBlocks = 0;
            var bookScripts            = new List <BookScript>();

            Parallel.ForEach(blocksInBook, book =>
            {
                var bookId = book.Key;
                Logger.WriteEvent("Creating bookScript ({0})", bookId);
                var bookScript = new BookScript(bookId, new UsxParser(bookId, stylesheet, book.Value).Parse());
                Logger.WriteEvent("Created bookScript ({0}, {1})", bookId, bookScript.BookId);
                bookScripts.Add(bookScript);
                Logger.WriteEvent("Added bookScript ({0}, {1})", bookId, bookScript.BookId);
                completedProjectBlocks += numBlocksPerBook[bookId];
                projectWorker.ReportProgress(MathUtilities.Percent(completedProjectBlocks, allProjectBlocks, 99));
            });

            // This code is an attempt to figure out how we are getting null reference exceptions on the Sort call (See PG-275 & PG-287)
            foreach (var bookScript in bookScripts)
            {
                if (bookScript == null || bookScript.BookId == null)
                {
                    var nonNullBookScripts    = bookScripts.Where(b => b != null).Select(b => b.BookId);
                    var nonNullBookScriptsStr = string.Join(";", nonNullBookScripts);
                    var initialMessage        = bookScript == null ? "BookScript is null." : "BookScript has null BookId.";
                    throw new ApplicationException(string.Format("{0} Number of BookScripts: {1}. BookScripts which are NOT null: {2}", initialMessage, bookScripts.Count, nonNullBookScriptsStr));
                }
            }

            try
            {
                bookScripts.Sort((a, b) => BCVRef.BookToNumber(a.BookId).CompareTo(BCVRef.BookToNumber(b.BookId)));
            }
            catch (NullReferenceException n)
            {
                // This code is an attempt to figure out how we are getting null reference exceptions on the Sort call (See PG-275 & PG-287)
                StringBuilder sb = new StringBuilder();
                foreach (var bookScript in bookScripts)
                {
                    sb.Append(Environment.NewLine).Append(bookScript.BookId).Append("(").Append(BCVRef.BookToNumber(bookScript.BookId)).Append(")");
                }
                throw new NullReferenceException("Null reference exception while sorting books." + sb, n);
            }

            projectWorker.ReportProgress(100);
            return(bookScripts);
        }
Ejemplo n.º 28
0
        public static int MigrateDeprecatedCharacterIds(Project project)
        {
            var cvInfo = new CombinedCharacterVerseData(project);
            var characterDetailDictionary = project.AllCharacterDetailDictionary;
            int numberOfChangesMade       = 0;       // For testing

            foreach (BookScript book in project.Books)
            {
                int bookNum = BCVRef.BookToNumber(book.BookId);

                foreach (Block block in book.GetScriptBlocks().Where(block => block.CharacterId != null &&
                                                                     block.CharacterId != CharacterVerseData.kUnknownCharacter &&
                                                                     !CharacterVerseData.IsCharacterStandard(block.CharacterId)))
                {
                    if (block.CharacterId == CharacterVerseData.kAmbiguousCharacter)
                    {
                        if (block.UserConfirmed)
                        {
                            block.UserConfirmed = false;
                            numberOfChangesMade++;
                        }
                    }
                    else
                    {
                        var unknownCharacter = !characterDetailDictionary.ContainsKey(block.CharacterIdInScript);
                        if (unknownCharacter && project.ProjectCharacterVerseData.GetCharacters(bookNum, block.ChapterNumber, block.InitialStartVerseNumber,
                                                                                                block.InitialEndVerseNumber, block.LastVerseNum).
                            Any(c => c.Character == block.CharacterId && c.Delivery == (block.Delivery ?? "")))
                        {
                            // PG-471: This is a known character who spoke in an unexpected location and was therefore added to the project CV file,
                            // but was subsequently removed or renamed from the master character detail list.
                            project.ProjectCharacterVerseData.Remove(bookNum, block.ChapterNumber, block.InitialStartVerseNumber,
                                                                     block.InitialEndVerseNumber, block.CharacterId, block.Delivery ?? "");
                            block.CharacterId         = CharacterVerseData.kUnknownCharacter;
                            block.CharacterIdInScript = null;
                            numberOfChangesMade++;
                        }
                        else
                        {
                            var characters = cvInfo.GetCharacters(bookNum, block.ChapterNumber, block.InitialStartVerseNumber, block.InitialEndVerseNumber, block.LastVerseNum).ToList();
                            if (unknownCharacter || !characters.Any(c => c.Character == block.CharacterId && c.Delivery == (block.Delivery ?? "")))
                            {
                                if (characters.Count(c => c.Character == block.CharacterId) == 1)
                                {
                                    block.Delivery = characters.First(c => c.Character == block.CharacterId).Delivery;
                                }
                                else
                                {
                                    block.SetCharacterAndDelivery(characters);
                                }
                                numberOfChangesMade++;
                            }
                        }
                    }
                }
            }
            return(numberOfChangesMade);
        }
Ejemplo n.º 29
0
        public void SetCharacterAndCharacterIdInScript_NotMultipleChoice_CharacterIdInScriptRemainsNull()
        {
            var block = new Block("p", 40, 8);

            block.SetCharacterAndCharacterIdInScript("chief monkey", BCVRef.BookToNumber("EXO"));
            Assert.AreEqual("chief monkey", block.CharacterId);
            Assert.AreEqual("chief monkey", block.CharacterIdInScript);
            Assert.IsNull(block.CharacterIdOverrideForScript);
        }
Ejemplo n.º 30
0
 public QuoteParser(ICharacterVerseInfo cvInfo, string bookId, IEnumerable <Block> blocks, ScrVers versification = null)
 {
     m_cvInfo        = cvInfo;
     m_bookId        = bookId;
     m_bookNum       = BCVRef.BookToNumber(bookId);
     m_inputBlocks   = blocks;
     m_versification = versification ?? ScrVers.English;
     GetRegExesForSplittingQuotes();
 }