Esempio n. 1
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Check whether this paragraph has the data for a segmented back translation, and if
		/// it does, create it.
		/// </summary>
		/// <param name="para"></param>
		/// <param name="segmentBTsForPara"></param>
		/// <returns>true if a segmented back translation is created, false otherwise</returns>
		/// -----------------------------------------------------------------------------------
		private bool ProcessSegmentInformation(IStTxtPara para, List<BTSegment> segmentBTsForPara)
		{
			ITsString tssPara = para.Contents.UnderlyingTsString.get_NormalizedForm(FwNormalizationMode.knmNFD);
			SegmentCollector collector = new SegmentCollector(tssPara, m_cache.LanguageWritingSystemFactoryAccessor);
			collector.Run();
			List<TsStringSegment> segs = collector.Segments;
			bool fMatchingSegs = false;
			if (segs.Count == segmentBTsForPara.Count)
			{
				fMatchingSegs = true;
				for (int i = 0; i < segs.Count; ++i)
				{
					if (segs[i].BeginOffset != segmentBTsForPara[i].BeginOffset ||
						segs[i].EndOffset != segmentBTsForPara[i].EndOffset ||
						!segs[i].Text.Equals(segmentBTsForPara[i].Text))
					{
						fMatchingSegs = false;
						break;
					}
				}
			}
			if (fMatchingSegs)
			{
				CreateSegmentedBackTranslation(para, segmentBTsForPara);
				return true;
			}
			else
			{
//#if DEBUG
//                Debug.WriteLine(String.Format("Unmatched Paragraph Segment Offsets:"));
//                for (int i = 0; i < segmentBTsForPara.Count; ++i)
//                {
//                    Debug.WriteLine(String.Format("    [{0,2}] begin={1,4}, end={2,4};  TR='{3}'",
//                        i, segmentBTsForPara[i].BeginOffset, segmentBTsForPara[i].EndOffset,
//                        segmentBTsForPara[i].Text.Text));
//                    foreach (int ws in segmentBTsForPara[i].AvailableBackTranslations)
//                    {
//                        string sWs = m_cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(ws);
//                        Debug.WriteLine(String.Format("                            BT[{0}]='{1}'",
//                            sWs, segmentBTsForPara[i].GetBackTransForWs(ws).Text));
//                    }
//                    if (i < segs.Count)
//                        Debug.WriteLine(String.Format("    [{0,2}] Begin={1,4}, End={2,4};  SG='{3}'",
//                            i, segs[i].BeginOffset, segs[i].EndOffset,
//                            segs[i].Text == null ? String.Empty : segs[i].Text.Text));
//                }
//                for (int i = segmentBTsForPara.Count; i < segs.Count; ++i)
//                {
//                    Debug.WriteLine(String.Format("    [{0,2}] Begin={1,4}, End={2,4};  SG='{3}'",
//                        i, segs[i].BeginOffset, segs[i].EndOffset,
//                        segs[i].Text == null ? String.Empty : segs[i].Text.Text));
//                }
//#endif
				return false;
			}
		}
Esempio n. 2
0
		/// <summary>
		/// This is very similar to CollectSegmentAnnotations on the base class, but does not make
		/// even dummy annotations, just TsStringSegments.
		/// </summary>
		/// <param name="tssText"></param>
		/// <param name="ichMinSegBreaks"></param>
		/// <returns></returns>
		internal List<TsStringSegment> CollectTempSegmentAnnotations(ITsString tssText, out List<int> ichMinSegBreaks)
		{
			SegmentCollector collector = new SegmentCollector(tssText, m_cache.LanguageWritingSystemFactoryAccessor);
			collector.Run();
			ichMinSegBreaks = collector.EosPositions;
			return collector.Segments;
		}
Esempio n. 3
0
		// Segment the current CmTranslation back translation that we want to convert, using the same algorithm
		// as for the main paragraph contents, but not actually making segment annotations.
		private void GetOriginalBtSegments()
		{
			ICmTranslation translation = m_para.GetBT();
			if (translation == null)
			{
				// No existing translation, can't have any segments.
				m_BtSegs = new List<TsStringSegment>();
			}
			else
			{
				ITsString trans = translation.Translation.GetAlternativeTss(m_wsBt);
				SegmentCollector collector = new SegmentCollector(trans, m_para.Cache.LanguageWritingSystemFactoryAccessor);
				collector.Run();
				m_BtSegs = collector.Segments;
			}
		}