internal void ChangeAnchor(Block block) { if (!CorrelatedBlocks.Contains(block)) { return; //throw new ArgumentException("Specified block is not in the collection of correlated blocks: " + block, "block"); } CorrelatedAnchorBlock = block; Debug.WriteLine("CorrelatedAnchorBlock changed to block " + CorrelatedBlocks.IndexOf(CorrelatedAnchorBlock) + " of " + CorrelatedBlocks.Count); }
public void Apply(Paratext.ScrVers versification) { if (!AllScriptureBlocksMatch) { throw new InvalidOperationException("Cannot apply reference blocks unless all Scripture blocks have corresponding reference blocks."); } var bogusRefBlock = GetInvalidReferenceBlockAtAnyLevel(CorrelatedBlocks); if (bogusRefBlock != null) { throw new InvalidReferenceTextException(bogusRefBlock); } if (m_numberOfBlocksAddedBySplitting > 0) { m_vernacularBook.ReplaceBlocks(m_iStartBlock, CorrelatedBlocks.Count - m_numberOfBlocksAddedBySplitting, CorrelatedBlocks.Select(b => b.Clone())); } int bookNum = BCVRef.BookToNumber(m_vernacularBook.BookId); var origBlocks = m_vernacularBook.GetScriptBlocks(); for (int i = 0; i < CorrelatedBlocks.Count; i++) { if (!CorrelatedBlocks[i].MatchesReferenceText) // e.g., section head { continue; } var vernBlock = origBlocks[m_iStartBlock + i]; var refBlock = CorrelatedBlocks[i].ReferenceBlocks.Single(); vernBlock.SetMatchedReferenceBlock(refBlock); vernBlock.SetCharacterAndDeliveryInfo(CorrelatedBlocks[i], bookNum, versification); if (CorrelatedBlocks[i].UserConfirmed) { if (vernBlock.CharacterIsUnclear()) { throw new InvalidOperationException("Character cannot be confirmed as ambigous or unknown."); } vernBlock.UserConfirmed = true; } //if (vernBlock.CharacterId != refBlock.CharacterId) //{ // vernBlock.CharacterId = refBlock.CharacterId; // if (refBlock.CharacterIdOverrideForScript != null) // vernBlock.CharacterIdOverrideForScript = refBlock.CharacterIdOverrideForScript; //} } m_numberOfBlocksAddedBySplitting = 0; }
public void Apply(ScrVers versification) { if (!AllScriptureBlocksMatch) { throw new InvalidOperationException("Cannot apply reference blocks unless all Scripture blocks have corresponding reference blocks."); } //var bogusRefBlock = GetInvalidReferenceBlockAtAnyLevel(CorrelatedBlocks); //if (bogusRefBlock != null) // throw new InvalidReferenceTextException(bogusRefBlock); if (m_numberOfBlocksAddedBySplitting > 0) { m_vernacularBook.ReplaceBlocks(m_iStartBlock, CorrelatedBlocks.Count - m_numberOfBlocksAddedBySplitting, CorrelatedBlocks.Select(b => b.Clone()).ToList()); } int bookNum = BCVRef.BookToNumber(m_vernacularBook.BookId); var origBlocks = m_vernacularBook.GetScriptBlocks(); for (int i = 0; i < CorrelatedBlocks.Count; i++) { var vernBlock = origBlocks[m_iStartBlock + i]; var refBlock = CorrelatedBlocks[i].ReferenceBlocks.Single(); vernBlock.SetMatchedReferenceBlock(refBlock); vernBlock.SetCharacterAndDeliveryInfo(CorrelatedBlocks[i], bookNum, versification); if (CorrelatedBlocks[i].UserConfirmed) { if (vernBlock.CharacterIsUnclear()) { throw new InvalidOperationException("Character cannot be confirmed as ambigous or unknown."); } vernBlock.UserConfirmed = true; } } if (m_numberOfBlocksAddedBySplitting == 0) { var lastBlockInMatchup = CorrelatedBlocks.Last(); foreach (var block in origBlocks.Skip(m_iStartBlock + OriginalBlockCount).TakeWhile(b => b.IsContinuationOfPreviousBlockQuote)) { block.CharacterId = lastBlockInMatchup.CharacterId; block.CharacterIdOverrideForScript = lastBlockInMatchup.CharacterIdOverrideForScript; } } else { m_numberOfBlocksAddedBySplitting = 0; } }
public Block GetCorrespondingOriginalBlock(Block block) { if (!CorrelatedBlocks.Contains(block)) { return(null); } var i = CorrelatedBlocks.Where(b => b.GetText(true).Contains(block.GetText(true))).IndexOf(block); var matches = OriginalBlocks.Where(b => b.GetText(true).Contains(block.GetText(true))).ToList(); if (matches.Count > i) { return(matches[i]); } Debug.Fail("Properly corresponding match not found in for block " + block.GetText(true)); return(matches.FirstOrDefault()); }
public Block GetCorrespondingOriginalBlock(Block block) { if (!CorrelatedBlocks.Contains(block)) { return(null); } var i = CorrelatedBlocks.Where(b => b.GetText(true).Contains(block.GetText(true))).IndexOf(block); //var matches = OriginalBlocks.Where(b => b.GetText(true).IndexOf(block.GetText(true), StringComparison.Ordinal) >= 0).ToList(); var matches = OriginalBlocks.Where(b => b.GetText(true).Contains(block.GetText(true))).ToList(); if (matches.Count > i) { return(matches[i]); } // If we're in the middle of doing a split, there can be a few moments where the block cannot be found. Let's hope // this gets called again after the split is complete. Debug.WriteLine("Properly corresponding match not found in for block " + block.GetText(true)); return(matches.FirstOrDefault()); }
public bool IncludesBlock(Block block) { return(OriginalBlocks.Contains(block) || CorrelatedBlocks.Contains(block)); }
public void Apply(ScrVers versification = null) { if (!AllScriptureBlocksMatch) { throw new InvalidOperationException("Cannot apply reference blocks unless all Scripture blocks have corresponding reference blocks."); } if (versification != null) { if (m_versification != null && m_versification != versification) { throw new ArgumentException("Apply called with unexpected versification!", nameof(versification)); } m_versification = versification; } if (m_numberOfBlocksAddedBySplitting > 0) { m_vernacularBook.ReplaceBlocks(m_iStartBlock, OriginalBlockCount, CorrelatedBlocks.Select(b => b.Clone()).ToList()); } int bookNum = BCVRef.BookToNumber(BookId); var origBlocks = m_vernacularBook.GetScriptBlocks(); for (int i = 0; i < CorrelatedBlocks.Count; i++) { var vernBlock = origBlocks[m_iStartBlock + i]; var refBlock = CorrelatedBlocks[i].ReferenceBlocks.Single(); vernBlock.SetMatchedReferenceBlock(refBlock); var basedOnBlock = CorrelatedBlocks[i].CharacterIsUnclear ? refBlock : CorrelatedBlocks[i]; vernBlock.SetCharacterAndDeliveryInfo(basedOnBlock, bookNum, m_versification); if (vernBlock.CharacterIsStandard) { vernBlock.MultiBlockQuote = MultiBlockQuote.None; } if (vernBlock.CharacterIsUnclear) { throw new InvalidOperationException("Vernacular block matched to reference block must have a CharacterId that is not ambiguous or unknown."); } if (CorrelatedBlocks[i].UserConfirmed) { vernBlock.UserConfirmed = true; } vernBlock.SplitId = CorrelatedBlocks[i].SplitId; } // No need to update following continuation blocks here if m_numberOfBlocksAddedBySplitting > 0 because the call to // ReplaceBlocks (above) already did it. if (m_numberOfBlocksAddedBySplitting == 0) { m_vernacularBook.UpdateFollowingContinuationBlocks(m_iStartBlock + OriginalBlockCount - 1); } else { m_numberOfBlocksAddedBySplitting = 0; } Debug.Assert(origBlocks.Skip(m_iStartBlock).Take(CorrelatedBlocks.Count) .All(b => !b.CharacterIsStandard || b.MultiBlockQuote == MultiBlockQuote.None), "Applying block matchup resulted in an illegal multi-block quote chain."); }