public void CreateScrBookRefs() { ReflectionHelper.CallMethod(typeof(TeScrBookRefsInit), "SetNamesAndAbbreviations", new DummyProgressDlg(), Cache); IFdoOwningSequence <IScrBookRef> books = Cache.ServiceLocator.GetInstance <IScrRefSystemRepository>().Singleton.BooksOS; // Make sure the right number of books was generated. Assert.AreEqual(66, books.Count); ILgWritingSystemFactory wsf = Cache.WritingSystemFactory; int wsEnglish = wsf.GetWsFromStr("en"); int wsSpanish = wsf.GetWsFromStr("es"); // Check English Genesis IScrBookRef genesis = books[0]; Assert.AreEqual("Genesis", genesis.BookName.get_String(wsEnglish).Text); Assert.AreEqual("Gen", genesis.BookAbbrev.get_String(wsEnglish).Text); Assert.IsNull(genesis.BookNameAlt.get_String(wsEnglish).Text); // Check Spanish Matthew IScrBookRef mateo = books[39]; Assert.AreEqual("Mateo", mateo.BookName.get_String(wsSpanish).Text); Assert.AreEqual("Mt", mateo.BookAbbrev.get_String(wsSpanish).Text); Assert.IsNull(mateo.BookNameAlt.get_String(wsSpanish).Text); // Check English 2 Corinthians IScrBookRef iiCor = books[46]; Assert.AreEqual("2 Corinthians", iiCor.BookName.get_String(wsEnglish).Text); Assert.AreEqual("2Cor", iiCor.BookAbbrev.get_String(wsEnglish).Text); Assert.AreEqual("II Corinthians", iiCor.BookNameAlt.get_String(wsEnglish).Text); // Check Spanish Revelation IScrBookRef apocalipsis = books[65]; Assert.AreEqual("Apocalipsis", apocalipsis.BookName.get_String(wsSpanish).Text); Assert.AreEqual("Ap", apocalipsis.BookAbbrev.get_String(wsSpanish).Text); Assert.IsNull(apocalipsis.BookNameAlt.get_String(wsSpanish).Text); MultilingScrBooks mlsb = new MultilingScrBooks(m_scr.ScrProjMetaDataProvider); foreach (IScrBookRef brf in books) { Assert.IsTrue(!String.IsNullOrEmpty(brf.BookName.get_String(wsEnglish).Text)); Assert.IsTrue(!String.IsNullOrEmpty(brf.BookAbbrev.get_String(wsEnglish).Text)); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initialize a list of book names available from the import file list. /// </summary> /// <returns>the number of books available for import</returns> /// ------------------------------------------------------------------------------------ private int InitBookNameList() { List<int> booksPresent = null; try { booksPresent = m_importSettings.BooksForProject(); } catch { // TODO: Add a message to tell the user that the paratext project could // not be loaded. } if (booksPresent == null || booksPresent.Count == 0) { // This can probably only happen in the weird case where a Paratext project // that previously had books now has none. radImportRange.Enabled = scrPsgFrom.Enabled = scrPsgTo.Enabled = false; return 0; } radImportRange.Enabled = true; scrPsgFrom.Enabled = scrPsgTo.Enabled = radImportRange.Checked; MultilingScrBooks mlBook = new MultilingScrBooks((IScrProjMetaDataProvider)m_scr); // Get list of books in import files BookLabel[] bookNames = new BookLabel[booksPresent.Count]; int iName = 0; foreach (int bookOrd in booksPresent) bookNames[iName++] = new BookLabel(mlBook.GetBookName(bookOrd), bookOrd); scrPsgFrom.BookLabels = bookNames; scrPsgTo.BookLabels = bookNames; return bookNames.Length; }
internal static int MakeStandardFormatQuestions(StreamReader reader, StreamWriter writer, IScrVers vers) { int problemsFound = 0; MultilingScrBooks multilingScrBooks = new MultilingScrBooks(); Regex regexChapterBreak = new Regex(@"\" + s_kSectionHead + @" (?<bookAndChapter>.+ \d+)", RegexOptions.Compiled); Regex regexAnswer = new Regex(@"\" + s_kAnswerMarker + @" .+", RegexOptions.Compiled); Regex regexQuestion = new Regex(@"\d+\. +(?<question>.+[?.])( (?<versesCovered>\(\d+(-\d+)?\)))?", RegexOptions.Compiled); string sVersesCoveredByQuestion = null; string sLine; while ((sLine = reader.ReadLine()) != null) { sLine = sLine.Replace(" ", " ").Trim(); if (sLine.Length == 0 || sLine.StartsWith("Back to top")) { continue; } Match match = regexChapterBreak.Match(sLine); if (match.Success) { string sBookAndChapter = match.Result("${bookAndChapter}"); BCVRef reference = multilingScrBooks.ParseRefString(sBookAndChapter + ":1"); int lastVerse = vers.GetLastVerse(reference.Book, reference.Chapter); sLine += ":1-" + lastVerse; writer.WriteLine(); writer.WriteLine(sLine); writer.WriteLine(s_kDetailsMarker + " Details"); writer.WriteLine(s_kRefMarker + " " + reference + "-" + lastVerse); continue; } match = regexAnswer.Match(sLine); if (match.Success) { writer.WriteLine(match + (string.IsNullOrEmpty(sVersesCoveredByQuestion) ? "" : " " + sVersesCoveredByQuestion)); continue; } sVersesCoveredByQuestion = null; match = regexQuestion.Match(sLine); if (match.Success) { string sQuestion = match.Result("${question}"); writer.WriteLine(s_kQuestionMarker + " " + sQuestion); sVersesCoveredByQuestion = match.Result("${versesCovered}"); } else { writer.WriteLine("PROBLEM: " + sLine); problemsFound++; } } return(problemsFound); }
public void ValidateReferencesWithDB() { m_mlscrBook = new DBMultilingScrBooks(m_scr); m_mlscrBook.InitializeWritingSystems( m_fdoCache.LanguageWritingSystemFactoryAccessor); Assert.IsFalse(m_mlscrBook.IsBookAvailableInDb(1), "Genesis found"); Assert.IsTrue("genesis" != m_mlscrBook.GetBookName(1).ToLower(), "Genesis found"); Assert.IsFalse(m_mlscrBook.IsReferenceValid("GEN 1:4"), "GEN 1:4 said to be a valid Reference"); Assert.IsTrue(m_mlscrBook.IsBookAvailableInDb(59), "James not found"); Assert.AreEqual("James".ToLower(), m_mlscrBook.GetBookName(59).ToLower(), "James found"); Assert.IsTrue(m_mlscrBook.IsReferenceValid("JAS 1:12"), "JAS 1:12 said to be an invalid Reference"); // These were removed because setting a reference to out of range values will // cause the values to be set to 1 and then the reference is valid. // Assert.IsFalse(mlscrBook.IsReferenceValid("JAS 50:1"), // "JAS 50:1 is valid Reference... go figure"); // Assert.IsFalse(mlscrBook.IsReferenceValid("JAS 1:50"), // "JAS 1:50 is valid Reference... go figure"); }
public void CreateScrBookRefs() { CheckDisposed(); IScrRefSystem scr = Cache.ScriptureReferenceSystem; m_scrInitializer.CallCreateScrBookRefs(Cache); FdoOwningSequence <IScrBookRef> books = scr.BooksOS; // Make sure the right number of books was generated. Assert.AreEqual(66, books.Count); ILgWritingSystemFactory wsf = Cache.LanguageWritingSystemFactoryAccessor; int wsEnglish = wsf.GetWsFromStr("en"); int wsSpanish = wsf.GetWsFromStr("es"); // Check English Genesis IScrBookRef genesis = books[0]; Assert.AreEqual("Genesis", genesis.BookName.GetAlternative(wsEnglish)); Assert.AreEqual("Gen", genesis.BookAbbrev.GetAlternative(wsEnglish)); Assert.IsNull(genesis.BookNameAlt.GetAlternative(wsEnglish)); // Check Spanish Matthew IScrBookRef mateo = books[39]; Assert.AreEqual("Mateo", mateo.BookName.GetAlternative(wsSpanish)); Assert.AreEqual("Mt", mateo.BookAbbrev.GetAlternative(wsSpanish)); Assert.IsNull(mateo.BookNameAlt.GetAlternative(wsSpanish)); // Check English 2 Corinthians IScrBookRef iiCor = books[46]; Assert.AreEqual("2 Corinthians", iiCor.BookName.GetAlternative(wsEnglish)); Assert.AreEqual("2Cor", iiCor.BookAbbrev.GetAlternative(wsEnglish)); Assert.AreEqual("II Corinthians", iiCor.BookNameAlt.GetAlternative(wsEnglish)); // Check Spanish Revelation IScrBookRef apocalipsis = books[65]; Assert.AreEqual("Apocalipsis", apocalipsis.BookName.GetAlternative(wsSpanish)); Assert.AreEqual("Ap", apocalipsis.BookAbbrev.GetAlternative(wsSpanish)); Assert.IsNull(apocalipsis.BookNameAlt.GetAlternative(wsSpanish)); MultilingScrBooks mlsb = new MultilingScrBooks(m_scr); mlsb.InitializeWritingSystems(Cache.LanguageWritingSystemFactoryAccessor); foreach (IScrBookRef brf in books) { string sBookName = brf.BookName.GetAlternative(wsEnglish); Assert.IsTrue(sBookName != null && sBookName != string.Empty); string sBookAbbrev = brf.BookAbbrev.GetAlternative(wsEnglish); Assert.IsTrue(sBookAbbrev != null && sBookAbbrev != string.Empty); } }
/// ----------------------------------------------------------------------------------- /// <summary> /// Get the name of the current book as a string. /// </summary> /// <param name="selLimitType">Specify Top or Bottom</param> /// <returns>The name of the current book, or <c>string.Empty</c> if we don't have a /// selection or the selection is in a place we don't know how to handle.</returns> /// ----------------------------------------------------------------------------------- public virtual string CurrentBook(SelectionHelper.SelLimitType selLimitType) { CheckDisposed(); // if there is no selection then there can be no book if (CurrentSelection == null || m_cache == null) return string.Empty; int iBook = ((ITeView)Control).LocationTracker.GetBookIndex( CurrentSelection, selLimitType); if (iBook < 0) return string.Empty; ScrBook book = BookFilter.GetBook(iBook); string sBook = book.Name.UserDefaultWritingSystem; if (sBook != null) return sBook; MultilingScrBooks multiScrBooks = new MultilingScrBooks((IScrProjMetaDataProvider)m_scr); multiScrBooks.InitializeWritingSystems(m_cache.LanguageWritingSystemFactoryAccessor); return multiScrBooks.GetBookName(book.CanonicalNum); }
public void DataIntegrity_Headings_HaveConsistentReferences() { var englishVersification = ScrVers.English; var regexHeading = new Regex("<Section", RegexOptions.Compiled); // Although these references are regarded as human-readable, the current state of the data is that in some cases, // instead of book names, there is just an abbreviation, either in mixed case or all caps. Probably not ideal, but // not really a problem. var regexHeadingHumanReadableRef = new Regex(" heading=\"(?<bookName>([1-3] ?)?(([A-Z][A-Za-z]+))( [A-Za-z]+){0,2}) (?<chapterAndVerse>((?<chapter>[1-9][0-9]*):)?(?<startVerse>[1-9][0-9]*)(?<startVerseSegment>[b])?((?<connector>-|(, ?))(((?<endChapter>[1-9][0-9]*)?):)?(?<endVerse>[1-9][0-9]*)(?<endVerseSegment>a)?)?)", RegexOptions.Compiled); var regexWellFormedScrRef = new Regex(" scrref=\"(?<bookId>([1-3][A-Z]{2})|([A-Z]{3})) (?<chapterAndVerseInScrRef>[^\"]*[0-9a-b])\"", RegexOptions.Compiled); var regexScrRefAttrib = new Regex(" scrref=", RegexOptions.Compiled); var bbbcccvvvRef = "((?<zero>0)|(?<bookNum>0?[0-9]{1,2})(?<chapterNum>[0-9]{3})(?<verseNum>[0-9]{3}))"; var regexStartRef = new Regex($" startref=\"{bbbcccvvvRef}\"", RegexOptions.Compiled); var regexEndRef = new Regex($" endref=\"{bbbcccvvvRef}\"", RegexOptions.Compiled); var multilingScrBooks = new MultilingScrBooks(); string bookId = null; var bookNum = -1; var chapter = -1; var startVerse = -1; var endVerse = -1; var endChapter = -1; var prevBookNum = -1; var prevSectionEndedWithSegment = false; var prevSectionEndCCCVVV = -1; var inSingleChapterBook = false; foreach (var matchedLine in GetMatchingLines(regexHeading, m_regexQuestion)) { var line = matchedLine.Line; var startPos = matchedLine.MatchEndPosition; switch (matchedLine.Level) { case 0: var matchHeadingHumanReadableRef = regexHeadingHumanReadableRef.Match(line, startPos); Assert.That(matchHeadingHumanReadableRef.Success, "Section head does not contain a valid human-readable reference: " + line); var chapterAndVerse = matchHeadingHumanReadableRef.Groups["chapterAndVerse"].Value.Replace(":", "."); var bookName = matchHeadingHumanReadableRef.Groups["bookName"].Value; var chapterStr = matchHeadingHumanReadableRef.Result("${chapter}"); chapter = IsNullOrEmpty(chapterStr) ? 1 : Parse(chapterStr); startVerse = Parse(matchHeadingHumanReadableRef.Groups["startVerse"].Value); var connector = matchHeadingHumanReadableRef.Result("${connector}"); var endVerseStr = matchHeadingHumanReadableRef.Result("${endVerse}"); endVerse = IsNullOrEmpty(endVerseStr) ? startVerse : Parse(endVerseStr); var endChapterStr = matchHeadingHumanReadableRef.Result("${endChapter}"); endChapter = IsNullOrEmpty(endChapterStr) ? chapter : Parse(endChapterStr); if (connector.StartsWith(",")) { Assert.AreEqual(chapter, endChapter, "If human-readable section reference uses a comma, there must not be an end chapter: " + line); Assert.AreEqual(startVerse + 1, endVerse, "If human-readable section reference uses a comma, end verse must be the verse following the start verse: " + line); chapterAndVerse = chapterAndVerse.Replace(connector, "-"); } var matchScrRef = regexWellFormedScrRef.Match(line, startPos); Assert.That(matchScrRef.Success, "Section head does not contain a valid scrref attribute: " + line); var chapterAndVerseInScrRef = matchScrRef.Groups["chapterAndVerseInScrRef"].Value; if (chapterAndVerse != chapterAndVerseInScrRef) { // Sub-verse letters sometimes occur in the section reference but not in the scrref attribute. These // should probably be consistent, but unfortunately are not. I started to change them, but since this // could At this point Assert.AreEqual(chapterAndVerse.Replace("a", "").Replace("b", ""), chapterAndVerseInScrRef, "Chapter and verse in scrref attribute do not match human readable chapter and verse: " + line); } bookId = matchScrRef.Groups["bookId"].Value; bookNum = BCVRef.BookToNumber(bookId); if (bookNum != prevBookNum) { Assert.That(bookNum >= 1 && bookNum <= 66, $"Book ID ({bookId}) does not correspond to a valid book: " + line); inSingleChapterBook = englishVersification.GetLastChapter(bookNum) == 1; } if (!bookId.Equals(bookName, StringComparison.OrdinalIgnoreCase)) { var expectedBookName = multilingScrBooks.GetBookName(bookNum); Assert.That(expectedBookName.StartsWith(bookName), "Book code in scrref attribute does not correspond to book Name in section heading: " + line); } var matchStartRef = regexStartRef.Match(line, startPos); Assert.That(matchStartRef.Success, "Section head does not contain a valid startref attribute: " + line); Assert.That(matchStartRef.Groups["zero"].Value == Empty, "startref=\"0\" not allowed in section head: " + line); Assert.AreEqual(bookNum, Parse(matchStartRef.Groups["bookNum"].Value), "Book in startref attribute does not match section book: " + line); Assert.AreEqual(chapter, Parse(matchStartRef.Groups["chapterNum"].Value), "Chapter in startref attribute does not match section start chapter: " + line); Assert.AreEqual(startVerse, Parse(matchStartRef.Groups["verseNum"].Value), "Verse in startref attribute does not match section start verse: " + line); var matchEndRef = regexEndRef.Match(line, startPos); Assert.That(matchEndRef.Success, "Section head does not contain a valid endref attribute: " + line); Assert.That(matchEndRef.Groups["zero"].Value == Empty, "endref=\"0\" not allowed in section head: " + line); Assert.AreEqual(bookNum, Parse(matchEndRef.Groups["bookNum"].Value), "Book in endref attribute does not match section book: " + line); Assert.AreEqual(endChapter, Parse(matchEndRef.Groups["chapterNum"].Value), "Chapter in endref attribute does not match section end chapter: " + line); Assert.AreEqual(endVerse, Parse(matchEndRef.Groups["verseNum"].Value), "Verse in endref attribute does not match section end verse: " + line); if (bookNum == prevBookNum) { var currSectionStartsWithSegment = matchHeadingHumanReadableRef.Groups["startVerseSegment"].Value != Empty; var currSectionEndsWithSegment = matchHeadingHumanReadableRef.Groups["endVerseSegment"].Value != Empty; var currSectionEndCCCVVV = endChapter * 1000 + endVerse; var currSectionStartCCCVVV = chapter * 1000 + startVerse; // Ensure references are in ascending order if (prevSectionEndedWithSegment) { Assert.That(currSectionStartsWithSegment && prevSectionEndCCCVVV == currSectionStartCCCVVV, "Section out of order: " + line); } else { Assert.That(prevSectionEndCCCVVV < currSectionStartCCCVVV, "Section out of order: " + line); } prevSectionEndCCCVVV = currSectionEndCCCVVV; prevSectionEndedWithSegment = currSectionEndsWithSegment; } else { prevBookNum = bookNum; prevSectionEndCCCVVV = -1; Assert.False(prevSectionEndedWithSegment); } break; case 1: matchScrRef = regexWellFormedScrRef.Match(line, startPos); if (matchScrRef.Success) { Assert.AreEqual(bookId, matchScrRef.Groups["bookId"].Value, "Question scrref attribute has incorrect book: " + line); Assert.That(inSingleChapterBook || matchScrRef.Groups["chapterAndVerseInScrRef"].Value.Contains("."), "Question scrref is missing the chapter or verse: " + line); } else { Assert.IsFalse(regexScrRefAttrib.IsMatch(line, startPos), "Question contains ill-formed scrref attribute" + line); } matchStartRef = regexStartRef.Match(line, startPos); Assert.That(matchStartRef.Success, "Question does not contain a valid startref attribute: " + line); var questionStartCccVvv = 0; var startRefSpecifiedExplicitly = matchStartRef.Groups["zero"].Value == Empty; if (startRefSpecifiedExplicitly) { Assert.AreEqual(bookNum, Parse(matchStartRef.Groups["bookNum"].Value), "Unexpected book number in startRef: " + line); var questionStartChapter = Parse(matchStartRef.Groups["chapterNum"].Value); var questionStartVerse = Parse(matchStartRef.Groups["verseNum"].Value); questionStartCccVvv = questionStartChapter * 1000 + questionStartVerse; if (chapter * 1000 + startVerse > questionStartCccVvv) { Assert.That(line.Contains("multiSectionSummary=\"true\""), "Question unexpectedly starts outside of containing section: " + line); } } else { // This is important because the logic in MasterQuestionParser only fills in the // start and end references from the section (typical for Overview questions) if // the scrref attribute is not defined. If those values are not set, then sorting // and filtering gets messed up. Assert.IsFalse(matchScrRef.Success, "If scrref is defined, start and end refs should be non-zero: " + line); } matchEndRef = regexEndRef.Match(line, startPos); Assert.That(matchEndRef.Success, "Question does not contain a valid endref attribute: " + line); if (startRefSpecifiedExplicitly) { Assert.That(matchEndRef.Groups["zero"].Value == Empty, "Start and end ref must both be explicit or both be implicit: " + line); Assert.AreEqual(bookNum, Parse(matchEndRef.Groups["bookNum"].Value)); var questionEndChapter = Parse(matchEndRef.Groups["chapterNum"].Value); var questionEndVerse = Parse(matchEndRef.Groups["verseNum"].Value); var questionEndCccVvv = questionEndChapter * 1000 + questionEndVerse; Assert.That(endChapter * 1000 + endVerse >= questionEndCccVvv, "Question ends outside of containing section: " + line); Assert.That(questionStartCccVvv <= questionEndCccVvv, "Question start reference is later than the end reference: " + line); } else { Assert.That(matchEndRef.Groups["zero"].Value != Empty, "Start and end ref must both be explicit or both be implicit: " + line); } break; } } }
public void TestSetup() { m_mlscrBook = new MultilingScrBooks(); }
public void Setup() { m_mlscrBook = new MultilingScrBooks(m_scr); m_mlscrBook.InitializeWritingSystems( m_fdoCache.LanguageWritingSystemFactoryAccessor); }
public void CreateScrBookRefs() { CheckDisposed(); IScrRefSystem scr = Cache.ScriptureReferenceSystem; m_scrInitializer.CallCreateScrBookRefs(Cache); FdoOwningSequence<IScrBookRef> books = scr.BooksOS; // Make sure the right number of books was generated. Assert.AreEqual(66, books.Count); ILgWritingSystemFactory wsf = Cache.LanguageWritingSystemFactoryAccessor; int wsEnglish = wsf.GetWsFromStr("en"); int wsSpanish = wsf.GetWsFromStr("es"); // Check English Genesis IScrBookRef genesis = books[0]; Assert.AreEqual("Genesis", genesis.BookName.GetAlternative(wsEnglish)); Assert.AreEqual("Gen", genesis.BookAbbrev.GetAlternative(wsEnglish)); Assert.IsNull(genesis.BookNameAlt.GetAlternative(wsEnglish)); // Check Spanish Matthew IScrBookRef mateo = books[39]; Assert.AreEqual("Mateo", mateo.BookName.GetAlternative(wsSpanish)); Assert.AreEqual("Mt", mateo.BookAbbrev.GetAlternative(wsSpanish)); Assert.IsNull(mateo.BookNameAlt.GetAlternative(wsSpanish)); // Check English 2 Corinthians IScrBookRef iiCor = books[46]; Assert.AreEqual("2 Corinthians", iiCor.BookName.GetAlternative(wsEnglish)); Assert.AreEqual("2Cor", iiCor.BookAbbrev.GetAlternative(wsEnglish)); Assert.AreEqual("II Corinthians", iiCor.BookNameAlt.GetAlternative(wsEnglish)); // Check Spanish Revelation IScrBookRef apocalipsis = books[65]; Assert.AreEqual("Apocalipsis", apocalipsis.BookName.GetAlternative(wsSpanish)); Assert.AreEqual("Ap", apocalipsis.BookAbbrev.GetAlternative(wsSpanish)); Assert.IsNull(apocalipsis.BookNameAlt.GetAlternative(wsSpanish)); MultilingScrBooks mlsb = new MultilingScrBooks(m_scr); mlsb.InitializeWritingSystems(Cache.LanguageWritingSystemFactoryAccessor); foreach (IScrBookRef brf in books) { string sBookName = brf.BookName.GetAlternative(wsEnglish); Assert.IsTrue(sBookName != null && sBookName != string.Empty); string sBookAbbrev = brf.BookAbbrev.GetAlternative(wsEnglish); Assert.IsTrue(sBookAbbrev != null && sBookAbbrev != string.Empty); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initialize a list of book names available from the import file list. /// </summary> /// <returns>the number of books available for import</returns> /// ------------------------------------------------------------------------------------ private int InitBookNameList() { List<int> booksPresent = null; try { booksPresent = m_importSettings.BooksForProject; } catch { // TODO: Add a message to tell the user that the paratext project could // not be loaded. } if (booksPresent == null || booksPresent.Count == 0) { // This can probably only happen in the weird case where a Paratext project // that previously had books now has none. radImportRange.Enabled = scrPsgFrom.Enabled = scrPsgTo.Enabled = false; return 0; } radImportRange.Enabled = scrPsgFrom.Enabled = scrPsgTo.Enabled = true; MultilingScrBooks mlBook = new MultilingScrBooks((IScrProjMetaDataProvider)m_cache.LangProject.TranslatedScriptureOA); // Get list of books in import files BookLabel[] bookNames = new BookLabel[booksPresent.Count]; int iName = 0; foreach (int bookOrd in booksPresent) bookNames[iName++] = new BookLabel(mlBook.GetBookName(bookOrd), bookOrd); scrPsgFrom.BookLabels = bookNames; scrPsgTo.BookLabels = bookNames; return bookNames.Length; }