Esempio n. 1
0
        void VerifyLabel(int iseg, string label)
        {
            int hvoSeg           = Cache.GetVectorItem(m_para.Hvo, kflidSegments, iseg);
            CmBaseAnnotation seg = CmObject.CreateFromDBObject(Cache, hvoSeg, false) as CmBaseAnnotation;

            Assert.IsTrue(SegmentBreaker.HasLabelText(m_para.Contents.UnderlyingTsString, seg.BeginOffset, seg.EndOffset), label);
        }
Esempio n. 2
0
        /// <summary>
        /// Here we have a reference to IText, which can reference ScrFdo, so unlike the base class
        /// we can give a meaningful definition to label segment.
        /// </summary>
        /// <param name="hvo"></param>
        /// <returns></returns>
        protected override bool IsLabelSegment(int hvo)
        {
            CmBaseAnnotation seg  = (CmBaseAnnotation)CmObject.CreateFromDBObject(Cache, hvo);
            StTxtPara        para = seg.BeginObjectRA as StTxtPara;

            return(SegmentBreaker.HasLabelText(para.Contents.UnderlyingTsString, seg.BeginOffset, seg.EndOffset));
        }
Esempio n. 3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Given a target verse label, see if there is a matching verse label in the BT. If so,
 /// return its index; otherwise, return -1.
 /// </summary>
 /// <param name="target">Text to search for</param>
 /// <param name="iSegMin">The segment where searching should begin</param>
 /// ------------------------------------------------------------------------------------
 private int IndexOfMatchingVerseSegInBt(ITsString target, int iSegMin)
 {
     for (int iTrans = iSegMin; iTrans < m_BtSegs.Count; iTrans++)
     {
         ITsString segText = m_BtSegs[iTrans].String;
         if (SegmentBreaker.HasLabelText(segText) && StringsEndWithSameWord(segText, target))
         {
             return(iTrans);
         }
     }
     return(-1);
 }
Esempio n. 4
0
 /// <summary>
 /// Given a target verse label, see if there is a matching verse label in the BT. If so, return its index;
 /// otherwise, return -1.
 /// </summary>
 /// <param name="target"></param>
 /// <returns></returns>
 int IndexOfMatchingVerseInBt(string target)
 {
     for (int iTrans = 0; iTrans < m_BtSegs.Count; iTrans++)
     {
         ITsString segText = m_BtSegs[iTrans].Text;
         if (StringsEqualExceptSpace(segText.Text, target) && SegmentBreaker.HasLabelText(segText, 0, segText.Length))
         {
             return(iTrans);
         }
     }
     return(-1);
 }
Esempio n. 5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates analyses for the words and punctuation forms of the specified segment. Words
        /// will have WfiWordforms created if they don't already exist.
        /// </summary>
        /// <param name="segment">The segment.</param>
        /// <param name="paraContents">The para contents.</param>
        /// <param name="ichBeginOffset">The beginning character offset.</param>
        /// <param name="ichLimOffset">The character offset limit.</param>
        /// <param name="fCreateGlosses">if set to <c>true</c> create glosses in addition to the
        /// WfiWordforms for each surface form.</param>
        /// ------------------------------------------------------------------------------------
        public static void CreateAnalyses(ISegment segment, ITsString paraContents,
                                          int ichBeginOffset, int ichLimOffset, bool fCreateGlosses)
        {
            FdoCache           cache   = segment.Cache;
            IFdoServiceLocator servloc = cache.ServiceLocator;

            if (SegmentBreaker.HasLabelText(paraContents, ichBeginOffset, ichLimOffset))
            {
                IPunctuationForm labelPunc = servloc.GetInstance <IPunctuationFormFactory>().Create();
                segment.AnalysesRS.Add(labelPunc);
                labelPunc.Form = paraContents.GetSubstring(ichBeginOffset, ichLimOffset);
            }
            else
            {
                ParseSegBaseline(segment, ichBeginOffset, ichLimOffset, (iForm, word, iAnalysis) =>
                {
                    CreateAnalysisForWord(word, segment, cache.DefaultAnalWs, fCreateGlosses);
                    return(true);
                },
                                 (sPunc, iAnalysis) => CreatePuncForm(segment, cache.TsStrFactory.MakeString(sPunc, cache.DefaultVernWs)),
                                 (ichOrc, iAnalysis) => CreatePuncForm(segment, paraContents.Substring(segment.BeginOffset + ichOrc, 1)));
            }
        }
Esempio n. 6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Find a group of BT segments starting at the specified index and continuing up to,
        /// but not including, the first label segment (e.g., a chapter or verse number) that
        /// corresponds to something in the main paragraph. This can return an empty list if
        /// segment iStartTrans itself is a label segment. Label segments are not included,
        /// though ones that don't match anything in
        /// the paragraph may be skipped over.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private List <TsStringSegment> GetSegGroup(int iStartTrans)
        {
            int iLimTrans;

            for (iLimTrans = iStartTrans; iLimTrans < m_BtSegs.Count; iLimTrans++)
            {
                ITsString tssSeg = m_BtSegs[iLimTrans].String;
                if (SegmentBreaker.HasLabelText(tssSeg) && MatchesSomeParaLabel(tssSeg))
                {
                    break;
                }
            }
            List <TsStringSegment> result = new List <TsStringSegment>(iLimTrans - iStartTrans);

            for (int i = iStartTrans; i < iLimTrans; i++)
            {
                ITsString tssSeg = m_BtSegs[i].String;
                if (!SegmentBreaker.HasLabelText(tssSeg))
                {
                    result.Add(m_BtSegs[i]);
                }
            }
            return(result);
        }
Esempio n. 7
0
        public static void UpdateMainTransFromSegmented(StTxtPara para, int[] wss)
        {
            if (!para.IsValidObject())
            {
                return;                 // in merge, paragraph may be modified then deleted.
            }
            FdoCache cache = para.Cache;

            BtConverter.EnsureMainParaSegments(para, wss[0]);
            ISilDataAccess sda         = cache.MainCacheAccessor;
            List <int>     segments    = para.Segments;
            int            kflidFT     = StTxtPara.SegmentFreeTranslationFlid(cache);
            ITsString      tssContents = para.Contents.UnderlyingTsString;
            IScripture     scr         = para.Cache.LangProject.TranslatedScriptureOA;
            ICmTranslation originalBT  = para.GetBT();            // Can be null
            string         sUnfinished = BackTranslationStatus.Unfinished.ToString();

            foreach (int ws in wss)
            {
                ITsStrBldr bldr          = TsStrBldrClass.Create();
                bool       wantNextSpace = false;        // suppresses space before the first thing we add.
                bool       haveBtText    = false;        // Text that isn't segment label text
                foreach (int hvoSeg in segments)
                {
                    // If it's a label, insert it directly. Suppress following space.
                    int       beginOffset = sda.get_IntProp(hvoSeg, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset);
                    int       endOffset   = sda.get_IntProp(hvoSeg, (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidEndOffset);
                    ITsString tssFt;
                    // Whether we want to insert a space before the current segment is determined by the previous one.
                    // Save that value so we can set wantSpace appropriately for the following one.
                    bool wantSpace = wantNextSpace;
                    if (SegmentBreaker.HasLabelText(tssContents, beginOffset, endOffset))
                    {
                        tssFt         = (new CmBaseAnnotation(cache, hvoSeg)).TextAnnotated;
                        tssFt         = scr.ConvertCVNumbersInStringForBT(CorrectFootnotes(tssFt), ws);
                        wantNextSpace = false;
                    }
                    else
                    {
                        int hvoFt = sda.get_ObjectProp(hvoSeg, kflidFT);
                        tssFt         = sda.get_MultiStringAlt(hvoFt, (int)CmAnnotation.CmAnnotationTags.kflidComment, ws);
                        haveBtText   |= (tssFt.Length > 0);
                        wantNextSpace = EndsWithNonSpace(tssFt);
                    }
                    if (tssFt.Length > 0)
                    {
                        if (wantSpace)
                        {
                            // The preceding segment should typically be followed by a space.
                            if (!StartsWithSpaceOrOrc(tssFt))
                            {
                                bldr.Replace(bldr.Length, bldr.Length, " ", null);
                            }
                        }
                        bldr.ReplaceTsString(bldr.Length, bldr.Length, tssFt);
                    }
                }

                // If the back translation doesn't have text, we don't want to create verse
                // segment labels. This prevents the problem where the book thinks it has a
                // back translation because of automatically generated verse labels (TE-8283).
                if (!haveBtText)
                {
                    // This check might not be needed, but it shouldn't hurt anything.
                    if (originalBT != null)
                    {
                        if (originalBT.Translation.GetAlternative(ws).Length > 0)
                        {
                            string origStatus = originalBT.Status.GetAlternative(ws);
                            if (!String.IsNullOrEmpty(origStatus) && origStatus != sUnfinished)
                            {
                                originalBT.Status.SetAlternative(sUnfinished, ws);
                            }
                        }
                    }
                    continue;
                }

                ITsString      newFt = bldr.GetString();
                ICmTranslation trans;
                if (newFt.Length == 0)
                {
                    trans = para.GetBT();
                    if (trans == null)
                    {
                        return;                         // don't bother creating one to store an empty translation!
                    }
                }
                else
                {
                    trans = para.GetOrCreateBT();
                }
                // Don't write unless it changed...PropChanged can be expensive.
                if (!trans.Translation.GetAlternative(ws).UnderlyingTsString.Equals(newFt))
                {
                    trans.Translation.SetAlternative(newFt, ws);
                    trans.Status.SetAlternative(sUnfinished, ws);
                }
            }
        }
Esempio n. 8
0
 private bool IsLabelSeg(ICmBaseAnnotation seg)
 {
     return(SegmentBreaker.HasLabelText(m_para.Contents.UnderlyingTsString, seg.BeginOffset, seg.EndOffset));
 }