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()); }
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()); }
private bool BlocksEndWithSameVerse(int bookNum, Block vernBlock, Block refBlock, ScrVers vernacularVersification) { var lastVernVerse = new VerseRef(bookNum, vernBlock.ChapterNumber, vernBlock.LastVerseNum, vernacularVersification); var lastRefVerse = new VerseRef(bookNum, refBlock.ChapterNumber, refBlock.LastVerseNum, Versification); return(lastVernVerse.CompareTo(lastRefVerse) == 0); }
public BookBlockIndices GetIndicesOfFirstBlockAtReference(VerseRef verseRef) { var bookId = verseRef.Book; int bookIndex = -1; BookScript book = null; for (int i = 0; i < m_books.Count; i++) { book = m_books[i]; if (book.BookId == bookId) { bookIndex = i; break; } } if (bookIndex == -1 || book == null) { return(null); } var blockIndex = book.Blocks.IndexOf( a => a.ChapterNumber == verseRef.ChapterNum && a.InitialStartVerseNumber <= verseRef.VerseNum && a.LastVerse >= verseRef.VerseNum); return(blockIndex == -1 ? null : new BookBlockIndices(bookIndex, blockIndex)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load the Paratext project and enumerator, preparing us to read the data files. /// </summary> /// <param name="paratextProjectId">3-letter Paratext project ID</param> /// <returns>true if the project was loaded, else false</returns> /// ------------------------------------------------------------------------------------ protected virtual void LoadParatextProject(string paratextProjectId) { try { m_ptProjectText = new ScrText(paratextProjectId); } catch (Exception e) { // Can't load Paratext project if Paratext is not installed. throw new ParatextLoadException( TeResourceHelper.GetResourceString("kstidCheckParatextInstallation"), e); } try { // create ref objs of the Paratext lib Logger.WriteEvent("Loading Paratext project " + paratextProjectId + " to import from " + m_settings.StartRef.AsString + " to " + m_settings.EndRef.AsString); // Now initialize the TextEnum with the range of Scripture text we want m_ptParser = m_ptProjectText.Parser(); m_ptCurrBook = new VerseRef(m_settings.StartRef.Book, 0, 0); ResetParatextState(); } catch (Exception e) { string msg = string.Format( TeResourceHelper.GetResourceString("kstidParatextProjectLoadFailure"), paratextProjectId); throw new ParatextLoadException(msg, e); } }
public virtual void AddEntriesFor(int bookNumber, Block block) { bool added = false; foreach (var verse in block.AllVerses) { if (!ControlCharacterVerseData.Singleton.GetCharacters(bookNumber, block.ChapterNumber, verse, m_versification, true, true) .Any(c => c.Character == block.CharacterId && c.Delivery == (block.Delivery ?? Empty))) { foreach (var v in verse.AllVerseNumbers) { var verseRef = new VerseRef(bookNumber, block.ChapterNumber, v, m_versification); verseRef.ChangeVersification(ScrVers.English); added |= base.AddCharacterVerse(new CharacterVerse(verseRef.BBBCCCVVV, block.CharacterId, block.Delivery ?? Empty, Empty, true)); } } } if (added) { Analytics.Track("AddCharacter", new Dictionary <string, string> { { "verseReference", block.GetReferenceString(BCVRef.NumberToBookCode(bookNumber)) }, { "characterId", block.CharacterId }, { "delivery", block.Delivery } }); } }
public static bool ChangeToEnglishVersification(ref VerseRef startRef, ref int endVerse, out int endChapter) { if (endVerse < startRef.VerseNum) { throw new ArgumentOutOfRangeException(nameof(endVerse), "Range must be in a single chapter and end verse must be greater than start verse. " + $"Details: {nameof(startRef)} = {startRef}; {nameof(endVerse)} = {endVerse}"); } bool endAndStartAreSame = endVerse == startRef.VerseNum; VerseRef endRef = endAndStartAreSame ? startRef : new VerseRef(startRef) { VerseNum = endVerse }; startRef.ChangeVersification(ScrVers.English); if (startRef.VerseNum == 0) // Currently, we don't support overriding verse 0 (Hebrew subtitle in Psalms) -- this allows us to define overrides with chapter ranges. { endChapter = -1; return(false); } if (endAndStartAreSame) // Calling change versification is kind of expensive, so this is a helpful optimization { endRef = startRef; } else { endRef.ChangeVersification(ScrVers.English); } endVerse = endRef.VerseNum; endChapter = endRef.ChapterNum; return(true); }
public override void Verse(UsfmParserState state, string number, string marker, string altNumber, string pubNumber) { prevCharMarker = null; if (state.ParaTag == null) { if (!pendingVerseNoParaError.IsDefault) { pendingVerseNoParaError.Verse = pendingVerseNoParaError.VerseNum + "-" + state.VerseRef.VerseNum; } else { pendingVerseNoParaError = new VerseRef(state.VerseRef); pendingVerseNoParaErrorOffset = state.VerseOffset; pendingVerseNoParaErrorMarker = "\\" + marker; } } else { if (state.CharTag != null) { recordError(lastCharMarkerVerse, "\\" + state.CharTag.Marker, lastCharMarkerOffset, GetErrorMessage(charStyleNotClosedMessage, state.CharTag.Marker)); } ValidateOccursUnder(state, marker, state.ParaTag.Marker, false); } prevMarkerWasChapter = false; }
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()); }
public void ParseMappingLine_CompareBaseToCustomized() { Versification vers2 = ScrVersReflectionHelper.CreateClonedVers(versification.VersInfo, versification.Name + "-monkey"); ScrVers versification2 = new ScrVers(vers2); versification.ParseChapterVerseLine( "ACT 1:26 2:47 3:26 4:37 5:42 6:15 7:60 8:40 9:43 10:48 11:30 12:25 13:52 14:28 15:41 16:40 17:34 18:28 19:41 20:38 21:40 22:30 23:35 24:27 25:27 26:32 27:44 28:31"); versification2.ParseChapterVerseLine( "ACT 1:26 2:47 3:26 4:37 5:42 6:15 7:60 8:40 9:43 10:48 11:30 12:25 13:52 14:28 15:41 16:40 17:34 18:28 19:41 20:38 21:40 22:30 23:35 24:27 25:27 26:32 27:44 28:31"); versification2.ParseMappingLine("ACT 19:41 = ACT 19:40"); versification.ParseMappingLine("ACT 19:41 = ACT 19:40"); // Even tho we have both vers 40 and 41 mapped to the same verse, doing a conversion between the // two versification should not cause the original distinction to be lost if both versifications are // based on the same original versification. VerseRef vref = new VerseRef("ACT 19:40", versification); versification2.ChangeVersification(ref vref); Assert.AreEqual(new VerseRef("ACT 19:40", versification2), vref); vref = new VerseRef("ACT 19:41", versification); versification2.ChangeVersification(ref vref); Assert.AreEqual(new VerseRef("ACT 19:41", versification2), vref); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set scripture reference using TE's object. /// </summary> /// <param name="reference">The reference.</param> /// ------------------------------------------------------------------------------------ public void SetTeScriptureReference(ScrReference reference) { VerseRef ref2 = new VerseRef(reference.Book, reference.Chapter, reference.Verse); ref2.Versification = new ScrVers(reference.Versification.ToString()); SetScriptureReference(ref2); }
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()); }
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()); }
[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 UsfmParserState(ScrStylesheet scrStylesheet) { ScrStylesheet = scrStylesheet; Stack = new List <UsfmParserElement>(); VerseRef = new VerseRef(); VerseOffset = 0; }
public UsfmParserState(ScrStylesheet scrStylesheet, VerseRef verseRef) { ScrStylesheet = scrStylesheet; Stack = new List <UsfmParserElement>(); VerseRef = verseRef.Clone(); VerseOffset = 0; }
public int ChangeVersification(int bbbcccvvv, IScrVers otherVersification) { VerseRef vRef = new VerseRef(bbbcccvvv, (ScrVers)otherVersification); ChangeVersification(ref vRef); return(vRef.BBBCCCVVV); }
public void ParseRangeToOneMappingLine_OneToManyMapping() { versification.ParseRangeToOneMappingLine("&ACT 19:39 = ACT 19:38-40"); VerseRef vref = new VerseRef("ACT 19:38", versification); ScrVers.Original.ChangeVersification(ref vref); Assert.AreEqual(new VerseRef("ACT 19:38", ScrVers.Original), vref); vref = new VerseRef("ACT 19:39", versification); ScrVers.Original.ChangeVersification(ref vref); Assert.AreEqual(new VerseRef("ACT 19:38", ScrVers.Original), vref); vref = new VerseRef("ACT 19:40", versification); ScrVers.Original.ChangeVersification(ref vref); Assert.AreEqual(new VerseRef("ACT 19:40", ScrVers.Original), vref); vref = new VerseRef("ACT 19:38", ScrVers.Original); versification.ChangeVersification(ref vref); Assert.AreEqual(new VerseRef("ACT 19:39", versification), vref); vref = new VerseRef("ACT 19:39", ScrVers.Original); versification.ChangeVersification(ref vref); Assert.AreEqual(new VerseRef("ACT 19:39", versification), vref); vref = new VerseRef("ACT 19:40", ScrVers.Original); versification.ChangeVersification(ref vref); Assert.AreEqual(new VerseRef("ACT 19:39", versification), vref); }
/// <summary> /// Creates a USFM parser /// </summary> /// <param name="scrStylesheet"></param> /// <param name="tokens">list of tokens to parse</param> /// <param name="verseRef">initial reference for the parser</param> /// <param name="sink">optional sink to send parse events to. Null for none</param> public UsfmParser(ScrStylesheet scrStylesheet, List <UsfmToken> tokens, VerseRef verseRef, UsfmParserSink sink) { this.scrStylesheet = scrStylesheet; this.tokens = tokens; this.state = new UsfmParserState(scrStylesheet, verseRef); this.sink = sink; }
private static void AdvanceToLastSegment(VerseRef vref) { string[] segments = vref.GetSegments(null); if (segments != null && segments.Length > 0) { vref.Verse += segments[segments.Length - 1]; } }
private static void DoRead(ScrText scr, VerseRef vref, string file) { string text = scr.GetText(vref, vref.ChapterNum != 0, false); using (StreamWriter writer = new StreamWriter(file, false, Encoding.UTF8)) { writer.Write(text); } }
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)); }
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); }
/// <summary> /// Sends a "Santa Fe" focus message which can be used by other applications (such as Paratext) /// to navigate to the same Scripture reference /// </summary> /// <param name="currRef"></param> public static void SendScrReference(this VerseRef currRef) { if (currRef != null && currRef.Valid) { currRef.ChangeVersification(ScrVers.English); SantaFeFocusMessageHandler.SendFocusMessage(currRef.ToString()); } }
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); }
/// <summary> /// The Transcribed Data is moved to Paratext SFM /// </summary> /// <param name="taskId">Task Id</param> /// <param name="heading">Heading for scripture</param> /// <returns>true if upload successful</returns> public static bool Upload(string taskId, string heading) { if (!ParatextInfo.IsParatextInstalled) { return(false); } try { // Get Task Details var currentTask = new Task(); currentTask = currentTask.GetTask(taskId); // Get the Task Transcription Text from EAF var folder = Util.FileFolder(taskId); string eafFilePath = Path.Combine(folder, Path.GetFileNameWithoutExtension(taskId) + ".eaf"); var transcriptionArray = GetTranscriptionTextFromEaf(eafFilePath); if (transcriptionArray[0].Trim().ToUpper().StartsWith("File Error:")) { return(false); } ParatextData.Initialize(); var paratextProject = ScrTextCollection.Find(currentTask.Project); if (paratextProject == null) { return(false); } var bookNum = paratextProject.BookNames.ScrText.BookNames.GetBookNumFromName(currentTask.BookName, true, BookNameSource.Abbreviation); if (bookNum == 0) { bookNum = (from i in paratextProject.BookNames.GetBookNames() where i.BookCode == currentTask.BookName select i.BookNum).FirstOrDefault(); } var vRef = new VerseRef(bookNum, currentTask.ChapterNumber, Convert.ToInt32(currentTask.VerseStart), paratextProject.Settings.Versification); var chapterContent = paratextProject.GetText(vRef, true, true); var sb = GenerateParatextData(currentTask, chapterContent, transcriptionArray[1], heading); paratextProject.PutText(bookNum, currentTask.ChapterNumber, true, sb.ToString(), null); return(true); } catch (Exception ex) { var error = ex.Message; Debug.Print(error); Logger.WriteEvent(error); } return(false); }
/// <summary> /// This method is preferred over the string bookId counterpart for performance reasons (so we don't have to look up the book number) /// </summary> public IEnumerable <CharacterVerse> GetCharacters(int bookId, int chapter, int initialStartVerse, int initialEndVerse = 0, int finalVerse = 0, ScrVers versification = null) { if (versification == null) { versification = ScrVers.English; } IEnumerable <CharacterVerse> result; if (initialEndVerse == 0 || initialStartVerse == initialEndVerse) { var verseRef = new VerseRef(bookId, chapter, initialStartVerse, versification); verseRef.ChangeVersification(ScrVers.English); result = m_lookup[verseRef.BBBCCCVVV]; } else { int start = new BCVRef(bookId, chapter, initialStartVerse).BBCCCVVV; int end = new BCVRef(bookId, chapter, initialEndVerse).BBCCCVVV; result = Enumerable.Empty <CharacterVerse>(); for (int i = start; i <= end; i++) { result = result.Union(m_lookup[i]); } } if (finalVerse == 0 || result.Count() == 1) { return(result); } var nextVerse = Math.Max(initialStartVerse, initialEndVerse) + 1; while (nextVerse <= finalVerse) { var verseRef = new VerseRef(bookId, chapter, nextVerse, versification); verseRef.ChangeVersification(ScrVers.English); IEnumerable <CharacterVerse> nextResult = m_lookup[verseRef.BBBCCCVVV]; if (!nextResult.Any()) { nextVerse++; continue; } if (!result.Any()) { result = nextResult; nextVerse++; continue; } var intersection = nextResult.Intersect(result, m_characterDeliveryEqualityComparer); if (intersection.Count() == 1) { result = intersection; break; } nextVerse++; } return(result); }
internal void ReportPendingVerseNoParaError() { if (!pendingVerseNoParaError.IsDefault) { recordError(pendingVerseNoParaError, pendingVerseNoParaErrorMarker, pendingVerseNoParaErrorOffset, "#" + verseNoParaMessage); pendingVerseNoParaError = new VerseRef(); } }
private bool BlocksMatch(int bookNum, Block vernBlock, Block refBlock, ScrVers vernacularVersification) { var vernInitStartVerse = new VerseRef(bookNum, vernBlock.ChapterNumber, vernBlock.InitialStartVerseNumber, vernacularVersification); var refInitStartVerse = new VerseRef(bookNum, refBlock.ChapterNumber, refBlock.InitialStartVerseNumber, Versification); return(vernInitStartVerse.CompareTo(refInitStartVerse) == 0 && (vernBlock.CharacterId == refBlock.CharacterId || vernBlock.CharacterIsUnclear()) && BlocksEndWithSameVerse(bookNum, vernBlock, refBlock, vernacularVersification)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a BCVRef from a VerseRef. /// </summary> /// ------------------------------------------------------------------------------------ private static BCVRef MakeBCVRef(VerseRef verseRef) { int segment = string.IsNullOrEmpty(verseRef.Segment) ? 0 : verseRef.Segment[0] - 'a'; if (segment < 0 || segment > 2) { segment = 0; } return(new BCVRef(verseRef.BookNum, verseRef.ChapterNum, verseRef.VerseNum, segment)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Restore settings (currently the list of texts displayed). /// </summary> /// <param name="key">The key.</param> /// ------------------------------------------------------------------------------------ public void LoadSettings(RegistryKey key) { try { m_floaty.LoadSettings(key); string texts = key.GetValue("UsfmTexts", "") as string; if (string.IsNullOrEmpty(texts)) return; // foreach below does one iteration for empty string, which is bad. List<TextCollectionItem> items = new List<TextCollectionItem>(); foreach (string name in texts.Split(',')) { ScrText text = null; try { foreach (ScrText st in ScrTextCollection.ScrTexts(true, true)) { if (st.Name == name) { text = st; break; } } } catch (Exception) { // If we for some reason can't make that text, carry on with the others. continue; } if (text == null) continue; // forget any saved item that is no longer an option. items.Add(new TextCollectionItem(text, 1.0)); } m_textCollection.Items = items; string curItemName = key.GetValue("UsfmCurItem", "") as string; if (string.IsNullOrEmpty(curItemName)) { for (int i = 0; i < m_textCollection.Items.Count; i++) { if (m_textCollection.Items[i].ScrText.Name == curItemName) { m_textCollection.CurItem = i; break; } } } // Paratext now requires a versification for Reload(), // so we'll default to English at this point. m_textCollection.Reference = new VerseRef("MAT 1:1", ScrVers.English); tryReloadTextCollection(); VerseRef vr = new VerseRef("MAT 1:1"); // default string reference = key.GetValue("UsfmCurRef", null) as string; if (!string.IsNullOrEmpty(reference)) vr = new VerseRef(reference); m_textCollection.CurItem = (int)key.GetValue("UsfmCurSel", -1); SetScriptureReference(vr); } catch { // ignore any problems. } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set the location in scripture we are to show. /// </summary> /// <param name="reference">The reference.</param> /// ------------------------------------------------------------------------------------ public void SetScriptureReference(VerseRef reference) { if (reference.ChapterNum == 0) { // When the chapter is zero, we are trying to select a reference in a title // (only place this should happen). Paratext doesn't handle this well (crashes). reference.ChapterNum = 1; } m_textCollection.Reference = reference; tryReloadTextCollection(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Set scripture reference using TE's object. /// </summary> /// <param name="reference">The reference.</param> /// ------------------------------------------------------------------------------------ public void SetTeScriptureReference(ScrReference reference) { VerseRef ref2 = new VerseRef(reference.Book, reference.Chapter, reference.Verse); ref2.Versification = new ScrVers(reference.Versification.ToString()); SetScriptureReference(ref2); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load the Paratext project and enumerator, preparing us to read the data files. /// </summary> /// <param name="paratextProjectId">3-letter Paratext project ID</param> /// <returns>true if the project was loaded, else false</returns> /// ------------------------------------------------------------------------------------ protected virtual void LoadParatextProject(string paratextProjectId) { try { m_ptProjectText = new ScrText(paratextProjectId); } catch (Exception e) { // Can't load Paratext project if Paratext is not installed. throw new ParatextLoadException( TeResourceHelper.GetResourceString("kstidCheckParatextInstallation"), e); } try { // create ref objs of the Paratext lib Logger.WriteEvent("Loading Paratext project " + paratextProjectId + " to import from " + m_settings.StartRef.AsString + " to " + m_settings.EndRef.AsString); // Now initialize the TextEnum with the range of Scripture text we want m_ptParser = m_ptProjectText.Parser; m_ptCurrBook = new VerseRef(m_settings.StartRef.Book, 0, 0); ResetParatextState(); } catch (Exception e) { string msg = string.Format( TeResourceHelper.GetResourceString("kstidParatextProjectLoadFailure"), paratextProjectId); throw new ParatextLoadException(msg, e); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a BCVRef from a VerseRef. /// </summary> /// ------------------------------------------------------------------------------------ private static BCVRef MakeBCVRef(VerseRef verseRef) { int segment = string.IsNullOrEmpty(verseRef.Segment()) ? 0 : verseRef.Segment()[0] - 'a'; if (segment < 0 || segment > 2) segment = 0; return new BCVRef(verseRef.BookNum, verseRef.ChapterNum, verseRef.VerseNum, segment); }