コード例 #1
0
ファイル: ProjectTests.cs プロジェクト: witheej/Glyssen
        public void SetReferenceText_ChangeFromEnglishToFrenchWithOneBlockMismatched_ReferenceTextClearedForAllRelatedBlocks()
        {
            var testProject = TestProject.CreateTestProject(TestProject.TestBook.MRK);

            testProject.ReferenceText = ReferenceText.GetStandardReferenceText(ReferenceTextType.English);
            testProject.IsOkayToClearExistingRefBlocksWhenChangingReferenceText = () => true;
            var mark   = testProject.IncludedBooks[0];
            var blocks = mark.GetScriptBlocks();

            var mark5V41 = blocks.IndexOf(b => b.ChapterNumber == 5 && b.InitialStartVerseNumber == 41);
            var matchup  = testProject.ReferenceText.GetBlocksForVerseMatchedToReferenceText(mark, mark5V41, testProject.Versification);

            Assert.AreEqual(5, matchup.CorrelatedBlocks.Count);
            Assert.AreEqual(40, matchup.CorrelatedBlocks[0].InitialStartVerseNumber);
            Assert.AreEqual(41, matchup.CorrelatedBlocks[1].InitialStartVerseNumber);
            Assert.IsTrue(matchup.CorrelatedBlocks.All(b => b.ReferenceBlocks.Count == 1));
            matchup.MatchAllBlocks(null);
            matchup.SetReferenceText(3, "this won't match.");
            matchup.Apply(null);
            var matchedVernBlocks = blocks.Skip(mark5V41).Take(4).ToList();

            Assert.IsTrue(matchedVernBlocks.All(b => b.MatchesReferenceText));
            Assert.IsTrue(matchedVernBlocks.All(b => b.ReferenceBlocks.Single().ReferenceBlocks.Count == 0));
            Assert.IsFalse(matchedVernBlocks.Any(b => string.IsNullOrEmpty(b.GetPrimaryReferenceText())));

            ReferenceText rtFrench = TestReferenceText.CreateCustomReferenceText(TestReferenceText.TestReferenceTextResource.FrenchMRK);

            testProject.ReferenceText = rtFrench;

            Assert.IsTrue(blocks.Single(b => b.ChapterNumber == 5 && b.InitialStartVerseNumber == 40).MatchesReferenceText);
            mark5V41 = blocks.IndexOf(b => b.ChapterNumber == 5 && b.InitialStartVerseNumber == 41);
            var vernBlocksForMark5V41 = blocks.Skip(mark5V41).Take(4).ToList();

            Assert.IsFalse(vernBlocksForMark5V41.Any(b => b.MatchesReferenceText));
        }
コード例 #2
0
        public void CreateGlyssenScript_HasPrimaryAndSecondaryReferenceTexts_ProcessedCorrectly()
        {
            var project = TestProject.CreateBasicTestProject();

            project.ReferenceText = ReferenceText.GetStandardReferenceText(ReferenceTextType.Russian);
            var glyssenScript = ScriptExporter.CreateGlyssenScript(project, s_lukChapter1);

            var block1 = glyssenScript.Script.Books[0].Chapters[0].Blocks[0];

            Assert.That(block1.VernacularText.BlockElements.Count, Is.EqualTo(2));

            var primaryRefText = block1.ReferenceTexts[0];

            Assert.That(primaryRefText.BlockElements.Count, Is.EqualTo(4));
            Assert.That(primaryRefText.BlockElements.First(), Is.TypeOf(typeof(Verse)));
            Assert.That(((Verse)primaryRefText.BlockElements.First()).Number, Is.EqualTo("1"));
            Assert.That(primaryRefText.BlockElements.Skip(1).First(), Is.TypeOf(typeof(ScriptText)));
            Assert.That(((ScriptText)primaryRefText.BlockElements.Skip(1).First()).Content, Is.EqualTo("Bikman Tiofilus, "));
            Assert.That(primaryRefText.BlockElements.Skip(2).First(), Is.TypeOf(typeof(Verse)));
            Assert.That(((Verse)primaryRefText.BlockElements.Skip(2).First()).Number, Is.EqualTo("2"));
            Assert.That(primaryRefText.BlockElements.Skip(3).First(), Is.TypeOf(typeof(ScriptText)));
            Assert.That(((ScriptText)primaryRefText.BlockElements.Skip(3).First()).Content, Is.EqualTo("Ol i bihainim tok bilong"));
            Assert.That(primaryRefText.Text, Is.EqualTo("Bikman Tiofilus, Ol i bihainim tok bilong"));

            var secondaryRefText = block1.ReferenceTexts[1];

            Assert.That(secondaryRefText.BlockElements.Count, Is.EqualTo(4));
            Assert.That(secondaryRefText.BlockElements.First(), Is.TypeOf(typeof(Verse)));
            Assert.That(((Verse)secondaryRefText.BlockElements.First()).Number, Is.EqualTo("1"));
            Assert.That(secondaryRefText.BlockElements.Skip(1).First(), Is.TypeOf(typeof(ScriptText)));
            Assert.That(((ScriptText)secondaryRefText.BlockElements.Skip(1).First()).Content, Is.EqualTo("Many have undertaken to set "));
            Assert.That(secondaryRefText.BlockElements.Skip(2).First(), Is.TypeOf(typeof(Verse)));
            Assert.That(((Verse)secondaryRefText.BlockElements.Skip(2).First()).Number, Is.EqualTo("2"));
            Assert.That(secondaryRefText.BlockElements.Skip(3).First(), Is.TypeOf(typeof(ScriptText)));
            Assert.That(((ScriptText)secondaryRefText.BlockElements.Skip(3).First()).Content, Is.EqualTo("just as they were handed"));
            Assert.That(secondaryRefText.Text, Is.EqualTo("Many have undertaken to set just as they were handed"));
        }
コード例 #3
0
ファイル: ProjectTests.cs プロジェクト: witheej/Glyssen
        public void SetReferenceText_ChangeFromEnglishToFrench_MatchedBlocksGetMigrated()
        {
            var testProject = TestProject.CreateTestProject(TestProject.TestBook.MRK);

            testProject.ReferenceText = ReferenceText.GetStandardReferenceText(ReferenceTextType.English);
            var mark   = testProject.IncludedBooks[0];
            var blocks = mark.GetScriptBlocks();

            // Case where the vern blocks match 1-for-1 to the English reference text
            var mark8V5 = blocks.IndexOf(b => b.ChapterNumber == 8 && b.InitialStartVerseNumber == 5);
            var matchup = testProject.ReferenceText.GetBlocksForVerseMatchedToReferenceText(mark, mark8V5, testProject.Versification);

            Assert.AreEqual(4, matchup.CorrelatedBlocks.Count);
            Assert.IsTrue(matchup.CorrelatedBlocks.All(b => b.ReferenceBlocks.Count == 1));
            matchup.MatchAllBlocks(null);
            matchup.Apply(null);
            var matchedVernBlocks = blocks.Skip(mark8V5).Take(4).ToList();

            Assert.IsTrue(matchedVernBlocks.All(b => b.MatchesReferenceText));
            Assert.IsTrue(matchedVernBlocks.All(b => b.ReferenceBlocks.Single().ReferenceBlocks.Count == 0));
            Assert.IsFalse(matchedVernBlocks.Any(b => string.IsNullOrEmpty(b.GetPrimaryReferenceText())));

            // Case where two of the English reference text blocks get combined to match a vern block
            var mark9V9               = blocks.IndexOf(b => b.ChapterNumber == 9 && b.InitialStartVerseNumber == 9);
            var englishRefBlocks      = testProject.ReferenceText.Books.Single(b => b.BookId == "MRK").GetScriptBlocks();
            var mark9V9EnglishRefText = englishRefBlocks.IndexOf(b => b.ChapterNumber == 9 && b.InitialStartVerseNumber == 9);

            Assert.AreEqual(9, englishRefBlocks[mark9V9EnglishRefText + 1].InitialStartVerseNumber);
            matchup = testProject.ReferenceText.GetBlocksForVerseMatchedToReferenceText(mark, mark9V9, testProject.Versification);
            Assert.AreEqual(3, matchup.CorrelatedBlocks.Count);
            Assert.IsTrue(matchup.CorrelatedBlocks.All(b => b.ReferenceBlocks.Count == 1));
            var expectedEnglishRefTextForMark9V9 = englishRefBlocks[mark9V9EnglishRefText].GetText(true) + " " +
                                                   englishRefBlocks[mark9V9EnglishRefText + 1].GetText(true);

            Assert.AreEqual(expectedEnglishRefTextForMark9V9, matchup.CorrelatedBlocks[0].GetPrimaryReferenceText());
            matchup.MatchAllBlocks(null);
            matchup.Apply(null);
            matchedVernBlocks = blocks.Skip(mark9V9).Take(3).ToList();
            Assert.IsTrue(matchedVernBlocks.All(b => b.MatchesReferenceText));
            Assert.IsTrue(matchedVernBlocks.All(b => b.ReferenceBlocks.Single().ReferenceBlocks.Count == 0));
            Assert.IsFalse(matchedVernBlocks.Any(b => string.IsNullOrEmpty(b.GetPrimaryReferenceText())));

            ReferenceText rtFrench = TestReferenceText.CreateCustomReferenceText(TestReferenceText.TestReferenceTextResource.FrenchMRK);

            testProject.ReferenceText = rtFrench;

            var frenchRefBlocks = rtFrench.Books.Single(b => b.BookId == "MRK").GetScriptBlocks();

            // Verify results for case where the vern blocks match 1-for-1 to the English reference text
            matchedVernBlocks = blocks.Skip(mark8V5).Take(4).ToList();
            Assert.IsTrue(matchedVernBlocks.All(b => b.MatchesReferenceText));
            Assert.IsFalse(matchedVernBlocks.Any(b => string.IsNullOrEmpty(b.GetPrimaryReferenceText())));
            Assert.IsTrue(matchedVernBlocks.All(b => b.ReferenceBlocks.Single().ReferenceBlocks.Count == 1));
            Assert.IsFalse(matchedVernBlocks.All(b => string.IsNullOrEmpty(b.ReferenceBlocks.Single().GetPrimaryReferenceText())));
            Assert.IsTrue(matchedVernBlocks.All(b => frenchRefBlocks.Any(fb => fb.GetText(true) == b.GetPrimaryReferenceText() &&
                                                                         fb.ChapterNumber == b.ChapterNumber && fb.InitialVerseNumberOrBridge == b.InitialVerseNumberOrBridge &&
                                                                         b.ReferenceBlocks.Single().GetPrimaryReferenceText() == fb.GetPrimaryReferenceText())));

            // Verify results for case where two of the English reference text blocks get combined to match a vern block
            matchedVernBlocks = blocks.Skip(mark9V9).Take(3).ToList();
            Assert.IsTrue(matchedVernBlocks.All(b => b.MatchesReferenceText));
            Assert.IsFalse(matchedVernBlocks.Any(b => string.IsNullOrEmpty(b.GetPrimaryReferenceText())));
            Assert.IsTrue(matchedVernBlocks.All(b => b.ReferenceBlocks.Single().ReferenceBlocks.Count == 1));
            Assert.IsFalse(matchedVernBlocks.All(b => string.IsNullOrEmpty(b.ReferenceBlocks.Single().GetPrimaryReferenceText())));
            var mark9V9FrenchRefText = frenchRefBlocks.IndexOf(b => b.ChapterNumber == 9 && b.InitialStartVerseNumber == 9);

            Assert.AreEqual(frenchRefBlocks[mark9V9FrenchRefText].GetText(true) + " " + frenchRefBlocks[mark9V9FrenchRefText + 1].GetText(true),
                            matchedVernBlocks[0].GetPrimaryReferenceText());
            Assert.AreEqual(expectedEnglishRefTextForMark9V9, matchedVernBlocks[0].ReferenceBlocks.Single().GetPrimaryReferenceText());
            Assert.IsTrue(matchedVernBlocks.Skip(1).All(b => frenchRefBlocks.Any(fb => fb.GetText(true) == b.GetPrimaryReferenceText() &&
                                                                                 fb.ChapterNumber == b.ChapterNumber && fb.InitialVerseNumberOrBridge == b.InitialVerseNumberOrBridge &&
                                                                                 b.ReferenceBlocks.Single().GetPrimaryReferenceText() == fb.GetPrimaryReferenceText())));
        }