示例#1
0
        public void TwoSegsPerVerse()
        {
            string pc1    = "Das buch ist rot. ";
            string pc2    = "Das Madchen ist shon.";
            string verse1 = "9";
            string pc3    = "Der Herr ist gross.";
            string pc4    = "Ich spreche nicht viel Deutsch.";
            string verse2 = "10";
            string pc5    = "Was is das?";
            string pc6    = "Wie gehts?";

            ITsStrBldr bldr = m_tsf.MakeString(pc1 + pc2 + verse1 + pc3 + pc4 + verse2 + pc5 + pc6, m_wsVern).GetBldr();

            bldr.SetStrPropValue(pc1.Length + pc2.Length, pc1.Length + pc2.Length + verse1.Length, (int)FwTextPropType.ktptNamedStyle,
                                 ScrStyleNames.VerseNumber);
            int ichEndV1 = pc1.Length + pc2.Length + verse1.Length + pc3.Length + pc4.Length;

            bldr.SetStrPropValue(ichEndV1, ichEndV1 + verse2.Length, (int)FwTextPropType.ktptNamedStyle,
                                 ScrStyleNames.VerseNumber);
            m_para.Contents.UnderlyingTsString = bldr.GetString();
            ParagraphParser pp = new ParagraphParser(m_para);
            List <int>      eosIndexes;
            List <int>      segments = pp.CollectSegmentAnnotations(m_para.Contents.UnderlyingTsString, out eosIndexes);

            Cache.VwCacheDaAccessor.CacheVecProp(m_para.Hvo, ktagParaSegments, segments.ToArray(), segments.Count);
            Assert.AreEqual(8, segments.Count);
            Assert.AreEqual("a", AnnotationRefHandler.VerseSegLabel(m_para, 0, ktagParaSegments));
            Assert.AreEqual("b", AnnotationRefHandler.VerseSegLabel(m_para, 1, ktagParaSegments));
            Assert.AreEqual("a", AnnotationRefHandler.VerseSegLabel(m_para, 3, ktagParaSegments));
            Assert.AreEqual("b", AnnotationRefHandler.VerseSegLabel(m_para, 4, ktagParaSegments));
            Assert.AreEqual("a", AnnotationRefHandler.VerseSegLabel(m_para, 6, ktagParaSegments));
            Assert.AreEqual("b", AnnotationRefHandler.VerseSegLabel(m_para, 7, ktagParaSegments));
        }
示例#2
0
        public void MultipleParas()
        {
            ScrTxtPara paraPrev = new ScrTxtPara();

            m_stText.ParagraphsOS.InsertAt(paraPrev, 0);
            ScrTxtPara paraFirst = new ScrTxtPara();

            m_stText.ParagraphsOS.InsertAt(paraFirst, 0);
            ScrTxtPara paraNext = new ScrTxtPara();

            m_stText.ParagraphsOS.Append(paraNext);
            ScrTxtPara paraLast = new ScrTxtPara();

            m_stText.ParagraphsOS.Append(paraLast);

            string pc1    = "Das buch ist rot. ";
            string pc2    = "Das Madchen ist shon.";
            string verse1 = "9";
            string pc3    = "Der Herr ist gross.";
            string pc4    = "Ich spreche nicht viel Deutsch.";
            string verse2 = "10";
            string pc5    = "Was is das?";
            string pc6    = "Wie gehts?";

            ITsStrBldr bldr = m_tsf.MakeString(pc1 + pc2 + verse1 + pc3 + pc4 + verse2 + pc5, m_wsVern).GetBldr();

            bldr.SetStrPropValue(pc1.Length + pc2.Length, pc1.Length + pc2.Length + verse1.Length, (int)FwTextPropType.ktptNamedStyle,
                                 ScrStyleNames.VerseNumber);
            int ichEndV1 = pc1.Length + pc2.Length + verse1.Length + pc3.Length + pc4.Length;

            bldr.SetStrPropValue(ichEndV1, ichEndV1 + verse2.Length, (int)FwTextPropType.ktptNamedStyle,
                                 ScrStyleNames.VerseNumber);
            List <int> segments = GetSegments(bldr, m_para);

            string verse8 = "8";

            bldr = m_tsf.MakeString(verse8 + pc3 + pc4, m_wsVern).GetBldr();
            bldr.SetStrPropValue(0, verse8.Length, (int)FwTextPropType.ktptNamedStyle,
                                 ScrStyleNames.VerseNumber);
            GetSegments(bldr, paraFirst);

            bldr = m_tsf.MakeString(pc1 + pc2, m_wsVern).GetBldr();
            GetSegments(bldr, paraPrev);

            string verse11 = "11";

            bldr = m_tsf.MakeString(pc3 + verse11 + pc4, m_wsVern).GetBldr();
            bldr.SetStrPropValue(pc3.Length, pc3.Length + verse11.Length, (int)FwTextPropType.ktptNamedStyle,
                                 ScrStyleNames.VerseNumber);
            GetSegments(bldr, paraNext);

            string verse12 = "12";

            bldr = m_tsf.MakeString(verse12 + pc5 + pc6, m_wsVern).GetBldr();
            bldr.SetStrPropValue(0, verse12.Length, (int)FwTextPropType.ktptNamedStyle,
                                 ScrStyleNames.VerseNumber);
            GetSegments(bldr, paraLast);
            Assert.AreEqual(7, segments.Count);
            Assert.AreEqual("a", AnnotationRefHandler.VerseSegLabel(paraFirst, 1, ktagParaSegments));
            Assert.AreEqual("b", AnnotationRefHandler.VerseSegLabel(paraFirst, 2, ktagParaSegments));
            Assert.AreEqual("c", AnnotationRefHandler.VerseSegLabel(paraPrev, 0, ktagParaSegments));
            Assert.AreEqual("d", AnnotationRefHandler.VerseSegLabel(paraPrev, 1, ktagParaSegments));
            Assert.AreEqual("e", AnnotationRefHandler.VerseSegLabel(m_para, 0, ktagParaSegments));
            Assert.AreEqual("f", AnnotationRefHandler.VerseSegLabel(m_para, 1, ktagParaSegments));
            Assert.AreEqual("a", AnnotationRefHandler.VerseSegLabel(m_para, 3, ktagParaSegments));
            Assert.AreEqual("b", AnnotationRefHandler.VerseSegLabel(m_para, 4, ktagParaSegments));
            Assert.AreEqual("a", AnnotationRefHandler.VerseSegLabel(m_para, 6, ktagParaSegments), "should have label because seg in following para");
            Assert.AreEqual("b", AnnotationRefHandler.VerseSegLabel(paraNext, 0, ktagParaSegments), "should have label due to previous para");
            Assert.AreEqual("", AnnotationRefHandler.VerseSegLabel(paraNext, 2, ktagParaSegments),
                            "should have no label because next para starts with verse");
        }