private void WriteSegmentedBackTrans(BTSegment bts) { CloseTranslationElementIfNeeded(); foreach (int ws in bts.AvailableTranslations) { ITsString tssSeg = bts.GetTransForWs(ws); string data = tssSeg.Text; if (!string.IsNullOrEmpty(tssSeg.Text)) { OpenTrGroupIfNeeded(); MarkBackTranslation(ws, bts.GetBtStatusForWs(ws), true); m_writer.Formatting = Formatting.None; WriteSegmentAnnotations(bts, data, ws); WriteBtSegment(tssSeg); m_writer.WriteEndElement(); if (!InFootnote) // Don't want to add whitespace if we're in a footnote or picture since they need to be inline. m_writer.Formatting = Formatting.Indented; } } CloseTrGroupIfNeeded(); // Write any annotations for back translation. if (bts.TargetObject is IStTxtPara && ((IStTxtPara)bts.TargetObject).TranslationsOC.Count > 0) { BackTranslationInfo btInfo = GetBackTranslationForPara((IStTxtPara)bts.TargetObject); if (btInfo != null) ExportAnnotationsForObj(btInfo.Hvo); } }
private void WriteSegmentAnnotations(BTSegment bts, string data, int ws) { if (m_rgSegAnn.Count == 0) return; List<int> rgws = bts.AvailableTranslations; List<IScrScriptureNote> rgWritten = new List<IScrScriptureNote>(); for (int i = 0; i < m_rgSegAnn.Count; ++i) { IScrScriptureNote note = m_rgSegAnn[i]; ICmIndirectAnnotation cia = note.BeginObjectRA as ICmIndirectAnnotation; Debug.Assert(cia != null); foreach (ICmAnnotation ann in cia.AppliesToRS) { ICmBaseAnnotation ba = ann as ICmBaseAnnotation; Debug.Assert(ba != null); if (ba != null) { //Debug.WriteLine(String.Format("WriteSegmentAnnotations(bts=({0},{1},{2}), data='{3}', ws={4})", // bts.BeginOffset, bts.EndOffset, bts.TargetObject.Hvo, data, ws)); //Debug.WriteLine(String.Format(" note.BeginOffset={0}, note.EndOffset={1}, note.BeginObjectRAHvo={2}, note.CitedText='{3}'", // note.BeginOffset, note.EndOffset, note.BeginObjectRAHvo, note.CitedText)); //Debug.WriteLine(String.Format(" ba.BeginOffset={0}, ba.EndOffset={1}, ba.BeginObjectRAHvo={2}", // ba.BeginOffset, ba.EndOffset, ba.BeginObjectRAHvo)); if ((ba.BeginOffset <= bts.BeginOffset && ba.EndOffset >= bts.EndOffset) || (ba.BeginOffset >= bts.BeginOffset && ba.EndOffset <= bts.EndOffset) || (ba.EndOffset >= bts.BeginOffset && ba.EndOffset <= bts.EndOffset)) { Debug.Assert(ba.BeginObjectRA == bts.TargetObject); string sLanguageInFocus = null; int idxStart = -1; //int idxEnd = -1; if (!String.IsNullOrEmpty(data) && !String.IsNullOrEmpty(note.CitedText)) { idxStart = data.IndexOf(note.CitedText); if (idxStart >= 0) { m_mapWsRFC.TryGetValue(ws, out sLanguageInFocus); //idxEnd = idxStart + note.CitedText.Length; } } if (idxStart < 0) { if (ws != rgws[rgws.Count - 1]) continue; } //Debug.WriteLine(String.Format(" idxStart={0}, idxEnd={1}, sLang='{2}'", // idxStart, idxEnd, sLanguageInFocus == null ? "<NULL>" : sLanguageInFocus)); XmlScrNote.Serialize(m_writer, note, sLanguageInFocus); rgWritten.Add(note); } } } } foreach (IScrScriptureNote note in rgWritten) m_rgSegAnn.Remove(note); }
private List<BTSegment> GetSegmentedBTInfo(IStTxtPara para) { List<BTSegment> rgBTSeg = new List<BTSegment>(); if (para == null || !para.IsValidObject) return rgBTSeg; // Backtranslation must exist if segmented BT exists ICmTranslation backtran = para.GetBT(); if (backtran == null) return rgBTSeg; // create list of WS used for back translations. List<int> rgWsBt = m_dictAnalLangs.Keys.ToList(); // Segment all BTs that aren't currently segmented if (rgWsBt.Count > 0) { foreach (ISegment segment in para.SegmentsOS) { BTSegment bts = new BTSegment(segment, para); foreach (int ws in rgWsBt) { ITsString tss = segment.FreeTranslation.get_String(ws); bts.SetTransForWs(ws, tss); string status = backtran.Status.get_String(ws).Text; if (!String.IsNullOrEmpty(status)) bts.SetBtStatusForWs(ws, status); } rgBTSeg.Add(bts); } } return rgBTSeg; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Write out the picture as a <figure> element. /// </summary> /// ------------------------------------------------------------------------------------ private void ExportPicture(ICmPicture pict) { ITsString tssCaption = pict.Caption.BestVernacularAlternative; string sCaption; if (tssCaption.Length > 0 && !tssCaption.Equals(pict.Caption.NotFoundTss)) sCaption = tssCaption.Text.Normalize(); else sCaption = String.Empty; m_writer.WriteStartElement("figure"); m_fInFigure = true; try { string sPath = pict.PictureFileRA.AbsoluteInternalPath.Normalize(); string sFile = Path.GetFileName(sPath); WriteFigureAttributes(sCaption, sFile); m_writer.WriteComment(String.Format("path=\"{0}\"", sPath)); m_writer.WriteStartElement("caption"); List<BTSegment> rgbts = new List<BTSegment>(); BTSegment bts = new BTSegment(tssCaption, 0, sCaption.Normalize(NormalizationForm.FormD).Length, pict); foreach (int ws in m_dictAnalLangs.Keys) { ITsString tss = pict.Caption.get_String(ws); if (tss.Length > 0 && tss != pict.Caption.NotFoundTss) bts.SetTransForWs(ws, tss.get_NormalizedForm(FwNormalizationMode.knmNFC)); } rgbts.Add(bts); if (sCaption.Length > 0) // Don't export caption with "NotFoundTss" text ExportParagraphData(tssCaption, rgbts); m_writer.WriteEndElement(); //</caption> m_writer.WriteEndElement(); //</figure> } finally { m_fInFigure = false; } }
/// -------------------------------------------------------------------------------- /// <summary> /// Adds text to a new segment or append text to an existing segment if needed. /// </summary> /// <param name="ichBeginTR">The beginning character offset of the segment.</param> /// <param name="segmentBTsForPara">List of segments for the para.</param> /// <param name="tssAppendKey">The TSS append key.</param> /// <param name="tssAddKey">The TSS add key.</param> /// -------------------------------------------------------------------------------- private void AddOrAppendToSegIfNeeded(int ichBeginTR, List<BTSegment> segmentBTsForPara, ITsString tssAppendKey, ITsString tssAddKey) { int ichEndTR = NormalizedLength(m_ParaBldr.StringBuilder); if (ichEndTR <= ichBeginTR) return; // no paragraph contents to add or append int iseg = segmentBTsForPara.Count - 1; if (iseg >= 0 && segmentBTsForPara[iseg] != null && (segmentBTsForPara[iseg].GetBackTransForWs(0) == m_tssChapterStartKey || segmentBTsForPara[iseg].GetBackTransForWs(0) == m_tssLabelTrKey || segmentBTsForPara[iseg].GetBackTransForWs(0) == m_tssVerseStartKey) && segmentBTsForPara[iseg].Text != null) { // Found a previous segment to which we need to append BTSegment bts = segmentBTsForPara[iseg]; bts.EndOffset = ichEndTR; ITsStrBldr tsb = bts.Text.GetBldr(); tsb.Append(NormalizedSegment(m_ParaBldr.StringBuilder, ichBeginTR)); bts.Text = tsb.GetString(); bts.SetBackTransForWs(0, tssAppendKey); } else { // Need to create a new segment BTSegment bts = new BTSegment(ichBeginTR, ichEndTR, NormalizedSegment(m_ParaBldr.StringBuilder, ichBeginTR)); bts.SetBackTransForWs(0, tssAddKey); segmentBTsForPara.Add(bts); } }
/// ----------------------------------------------------------------------------------- /// <summary> /// Read in one paragraph's worth of data. This includes both the translated data and /// the back translated data, as well as any footnotes or annotations encountered along /// the way. The footnotes and annotations are created, but the translated data and /// back translated data are left waiting for a call to StoreXmlParagraphData(). /// </summary> /// <param name="xnPara">XML node with paragraph information</param> /// <param name="fNew"><c>true</c> to start a new paragraph; <c>false</c> to continue /// adding content to an existing paragraph</param> /// <param name="sect">The section of which this paragraph is a part</param> /// <param name="annotationsForPara">List of any annotations added or modified for this /// paragraph (needed so that the begin/end object properties can be set once the para /// is actually created)</param> /// <param name="segmentBTsForPara"></param> /// <returns>true if any data was read, false otherwise</returns> /// ----------------------------------------------------------------------------------- private bool ReadXmlParagraphData(XmlNode xnPara, bool fNew, IScrSection sect, List<IScrScriptureNote> annotationsForPara, List<BTSegment> segmentBTsForPara) { if (fNew) ClearParagraphStringBuilders(); bool fData = false; // the following strings are used as markers in the rgmapwstssBT list. ITsString tssChapterStart = m_cache.MakeUserTss("chapterStart"); ITsString tssVerseStart = m_cache.MakeUserTss("verseStart"); ITsString tssChapterVerse = m_cache.MakeUserTss("chapter:verse"); ITsString tssNote = m_cache.MakeUserTss("note"); ITsString tssFigure = m_cache.MakeUserTss("figure"); Dictionary<int, ITsString> mapwstss = new Dictionary<int, ITsString>(); List<IScrScriptureNote> rgnotesForSegment = new List<IScrScriptureNote>(); bool fImportSegmentedBT = true; foreach (XmlNode node in xnPara.ChildNodes) { int ichBeginTR = NormalizedLength(m_ParaBldr.StringBuilder); mapwstss.Clear(); if (node.Name == "trGroup") { fImportSegmentedBT &= Options.UseInterlinearBackTranslation; foreach (XmlNode xn in node.ChildNodes) { string sLang = XmlUtils.GetOptionalAttributeValue(xn, "xml:lang", null); int ws; if (String.IsNullOrEmpty(sLang)) ws = xn.Name == "bt" ? m_wsAnal : m_wsVern; else ws = GetWsForLang(sLang); if (xn.Name == "tr") { ReadXmlStringElement(xn, ws, null, m_ParaBldr.StringBuilder); fData = true; } else if (xn.Name == "bt") { fImportSegmentedBT &= XmlUtils.GetOptionalBooleanAttributeValue(xn, "segmented", false); ITsStrBldr tsb = GetBackTransStringBuilder(ws); ITsStrBldr tsbNumber = GetBackTransNumberStringBuilder(ws); if (tsbNumber.Length > 0) { tsb.ReplaceTsString(tsb.Length, tsb.Length, tsbNumber.GetString()); tsbNumber.Clear(); } int cchBegin = NormalizedLength(tsb); ReadXmlStringElement(xn, ws, null, tsb); string status = XmlUtils.GetOptionalAttributeValue(xn, "status"); string statusT; if (!String.IsNullOrEmpty(status) && !m_BTStatus.TryGetValue(ws, out statusT)) m_BTStatus.Add(ws, status); fData = true; mapwstss.Add(ws, NormalizedSegment(tsb, cchBegin)); foreach (XmlNode xnChild in xn.ChildNodes) { if (xnChild.Name == "annotation") { IScrScriptureNote ann = XmlScrNote.Deserialize(xnChild, m_scr, m_styleSheet); if (ann != null) rgnotesForSegment.Add(ann); } } } else if (xn is XmlElement) { throw new Exception("OXES validation failed to detect an unexpected tag in the <trGroup>."); } } int ichEndTR = NormalizedLength(m_ParaBldr.StringBuilder); if (ichEndTR > ichBeginTR || rgnotesForSegment.Count > 0) { BTSegment bts = new BTSegment(ichBeginTR, ichEndTR, NormalizedSegment(m_ParaBldr.StringBuilder, ichBeginTR)); foreach (int ws in mapwstss.Keys) bts.SetBackTransForWs(ws, mapwstss[ws]); if (rgnotesForSegment.Count > 0) { bts.Annotations = rgnotesForSegment; rgnotesForSegment.Clear(); } segmentBTsForPara.Add(bts); } } else if (node.Name == "chapterStart" || node.Name == "chapterEnd") { ProcessChapterNumber(node); if (m_ParaBldr.Length > 0) fData = true; int ichEndTR = NormalizedLength(m_ParaBldr.StringBuilder); if (ichEndTR > ichBeginTR) { BTSegment bts = new BTSegment(ichBeginTR, ichEndTR, NormalizedSegment(m_ParaBldr.StringBuilder, ichBeginTR)); bts.SetBackTransForWs(0, tssChapterStart); segmentBTsForPara.Add(bts); } } else if (node.Name == "verseStart" || node.Name == "verseEnd") { ProcessVerseNumber(node); if (m_ParaBldr.Length > 0) fData = true; int ichEndTR = NormalizedLength(m_ParaBldr.StringBuilder); if (ichEndTR > ichBeginTR) { int iseg = segmentBTsForPara.Count - 1; if (iseg >= 0 && segmentBTsForPara[iseg] != null && segmentBTsForPara[iseg].GetBackTransForWs(0) == tssChapterStart && segmentBTsForPara[iseg].Text != null && segmentBTsForPara[iseg].Text.Length <= 3 && ichEndTR - ichBeginTR <= 9) // allows verse "100b-101a" { BTSegment bts = segmentBTsForPara[iseg]; bts.EndOffset = ichEndTR; ITsStrBldr tsb = bts.Text.GetBldr(); tsb.ReplaceTsString(tsb.Length, tsb.Length, NormalizedSegment(m_ParaBldr.StringBuilder, ichBeginTR)); bts.Text = tsb.GetString(); bts.SetBackTransForWs(0, tssChapterVerse); } else { BTSegment bts = new BTSegment(ichBeginTR, ichEndTR, NormalizedSegment(m_ParaBldr.StringBuilder, ichBeginTR)); bts.SetBackTransForWs(0, tssVerseStart); segmentBTsForPara.Add(bts); } } } else if (node.Name == "note") { ProcessFootnote(node); int ichEndTR = NormalizedLength(m_ParaBldr.StringBuilder); if (ichEndTR > ichBeginTR) { BTSegment bts = new BTSegment(ichBeginTR, ichEndTR, NormalizedSegment(m_ParaBldr.StringBuilder, ichBeginTR)); bts.SetBackTransForWs(0, tssNote); segmentBTsForPara.Add(bts); } } else if (node.Name == "annotation") { IScrScriptureNote ann = XmlScrNote.Deserialize(node, m_scr, m_styleSheet); if (ann != null) annotationsForPara.Add(ann); } else if (node.Name == "figure") { ProcessFigure(node); int ichEndTR = NormalizedLength(m_ParaBldr.StringBuilder); if (ichEndTR > ichBeginTR) { BTSegment bts = new BTSegment(ichBeginTR, ichEndTR, NormalizedSegment(m_ParaBldr.StringBuilder, ichBeginTR)); bts.SetBackTransForWs(0, tssFigure); segmentBTsForPara.Add(bts); } } else if (node.Name == "p") { if (m_stackXmlContext.Count == 0) { throw new ScriptureUtilsException(SUE_ErrorCode.UnexpectedParagraph, m_sOXESFile, (m_reader != null) ? m_reader.LineNumber : 0, node.OuterXml.Substring(0, node.OuterXml.IndexOf(">") + 1), m_currentRef); } string sContext = m_stackXmlContext.Peek(); if ((sContext == ScrStyleNames.ListItem1 || sContext == ScrStyleNames.ListItem2) && sect != null) { if (fData) StoreXmlParagraphData(sect.ContentOAHvo, sContext, annotationsForPara, segmentBTsForPara); string sStyle = (sContext == ScrStyleNames.ListItem1) ? ScrStyleNames.ListItem1Additional : ScrStyleNames.ListItem2Additional; if (ReadXmlParagraphData(node, true, sect, annotationsForPara, segmentBTsForPara)) StoreXmlParagraphData(sect.ContentOAHvo, sStyle, annotationsForPara, segmentBTsForPara); fData = false; } else if (node is XmlElement) { throw new Exception("OXES validation failed to detect a <p> tag within a <p> tag."); } } else if (node is XmlElement) { throw new Exception("OXES validation failed to find a valid tag within a <p> tag."); } } if (!fImportSegmentedBT) segmentBTsForPara.Clear(); return fData; }
private void WriteSegmentedBackTrans(BTSegment bts, int iseg) { //#if DEBUG // WriteSegmentedBackTransDebugInfo(bts, iseg); //#endif CloseTranslationElementIfNeeded(); foreach (int ws in bts.AvailableTranslations) { ITsString tss = bts.GetTransForWs(ws); string data = tss.Text; if (!String.IsNullOrEmpty(data)) { OpenTrGroupIfNeeded(); m_writer.WriteStartElement("bt"); m_writer.WriteAttributeString("xml", "lang", null, m_dictAnalLangs[ws]); m_writer.WriteAttributeString("segmented", "true"); string status = bts.GetBtStatusForWs(ws); if (!String.IsNullOrEmpty(status)) m_writer.WriteAttributeString("status", status.ToLower()); // OxesInfo xinfo = OxesInfo.GetOxesInfoForCharStyle(styleName); // if (!String.IsNullOrEmpty(xinfo.XmlTag)) // { // m_writer.WriteStartElement(xinfo.XmlTag); // if (!String.IsNullOrEmpty(xinfo.AttrName) && !String.IsNullOrEmpty(xinfo.AttrValue)) // m_writer.WriteAttributeString(xinfo.AttrName, xinfo.AttrValue); // } m_writer.Formatting = Formatting.None; WriteSegmentAnnotations(bts, data, ws); m_writer.WriteString(data.Normalize()); m_writer.WriteEndElement(); m_writer.Formatting = Formatting.Indented; } } CloseTrGroupIfNeeded(); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Read in one paragraph's worth of data. This includes both the translated data and /// the back translated data, as well as any footnotes or annotations encountered along /// the way. The footnotes and annotations are created, but the translated data and /// back translated data are left waiting for a call to StoreXmlParagraphData(). /// </summary> /// <param name="xnPara">XML node with paragraph information</param> /// <param name="fNew"><c>true</c> to start a new paragraph; <c>false</c> to continue /// adding content to an existing paragraph</param> /// <param name="sect">The section of which this paragraph is a part</param> /// <param name="annotationsForPara">List of any annotations added or modified for this /// paragraph (needed so that the begin/end object properties can be set once the para /// is actually created)</param> /// <param name="segmentBTsForPara"></param> /// <returns>true if any data was read, false otherwise</returns> /// ----------------------------------------------------------------------------------- private bool ReadXmlParagraphData(XmlNode xnPara, bool fNew, IScrSection sect, List<IScrScriptureNote> annotationsForPara, List<BTSegment> segmentBTsForPara) { if (fNew) ClearParagraphStringBuilders(); bool fData = false; Dictionary<int, ITsString> mapwstss = new Dictionary<int, ITsString>(); List<IScrScriptureNote> rgnotesForSegment = new List<IScrScriptureNote>(); bool fImportSegmentedBT = true; foreach (XmlNode node in xnPara.ChildNodes) { int ichBeginTR = NormalizedLength(m_ParaBldr.StringBuilder); mapwstss.Clear(); if (node.Name == "trGroup") { foreach (XmlNode xn in node.ChildNodes) { string sLang = XmlUtils.GetOptionalAttributeValue(xn, "xml:lang", null); int ws; if (String.IsNullOrEmpty(sLang)) ws = xn.Name == "bt" ? m_wsAnal : m_wsVern; else ws = GetWsForLang(sLang); if (xn.Name == "tr") { ReadXmlStringElement(xn, ws, null, m_ParaBldr.StringBuilder); fData = true; } else if (xn.Name == "bt") { fImportSegmentedBT &= XmlUtils.GetOptionalBooleanAttributeValue(xn, "segmented", false); ITsStrBldr tsb = GetBackTransStringBuilder(ws); ITsStrBldr tsbNumber = GetBackTransNumberStringBuilder(ws); if (tsbNumber.Length > 0) { tsb.ReplaceTsString(tsb.Length, tsb.Length, tsbNumber.GetString()); tsbNumber.Clear(); } int cchBegin = NormalizedLength(tsb); ReadXmlStringElement(xn, ws, null, tsb); string status = XmlUtils.GetOptionalAttributeValue(xn, "status"); string statusT; if (!String.IsNullOrEmpty(status) && !m_BTStatus.TryGetValue(ws, out statusT)) m_BTStatus.Add(ws, status); fData = true; mapwstss.Add(ws, NormalizedSegment(tsb, cchBegin)); foreach (XmlNode xnChild in xn.ChildNodes) { if (xnChild.Name == "annotation") { IScrScriptureNote ann = XmlScrNote.Deserialize(xnChild, m_scr, m_styleSheet); if (ann != null) rgnotesForSegment.Add(ann); } } } else if (xn is XmlElement) { throw new Exception("OXES validation failed to detect an unexpected tag in the <trGroup>."); } } int ichEndTR = NormalizedLength(m_ParaBldr.StringBuilder); if (ichEndTR > ichBeginTR || rgnotesForSegment.Count > 0) { BTSegment bts = new BTSegment(ichBeginTR, ichEndTR, NormalizedSegment(m_ParaBldr.StringBuilder, ichBeginTR)); foreach (int ws in mapwstss.Keys) bts.SetBackTransForWs(ws, mapwstss[ws]); if (rgnotesForSegment.Count > 0) { bts.Annotations = rgnotesForSegment; rgnotesForSegment.Clear(); } segmentBTsForPara.Add(bts); } } else if (node.Name == "chapterStart" || node.Name == "chapterEnd") { ProcessChapterNumber(node); if (m_ParaBldr.Length > 0) fData = true; AddOrAppendToSegIfNeeded(ichBeginTR, segmentBTsForPara, m_tssChapterStartKey, m_tssChapterStartKey); } else if (node.Name == "verseStart" || node.Name == "verseEnd") { ProcessVerseNumber(node); if (m_ParaBldr.Length > 0) fData = true; AddOrAppendToSegIfNeeded(ichBeginTR, segmentBTsForPara, m_tssVerseStartKey, m_tssVerseStartKey); } else if (node.Name == "note") { if (XmlUtils.GetOptionalAttributeValue(node, "Id") != null) { ProcessFootnote(node); int ichEndTR = NormalizedLength(m_ParaBldr.StringBuilder); if (ichEndTR > ichBeginTR) { BTSegment bts = new BTSegment(ichBeginTR, ichEndTR, NormalizedSegment(m_ParaBldr.StringBuilder, ichBeginTR)); bts.SetBackTransForWs(0, m_tssNoteKey); segmentBTsForPara.Add(bts); } } else { Debug.Fail("Need to handle note references."); //Debug.Assert(XmlUtils.GetOptionalAttributeValue(node, "Ref") != null, // "Did not find expected reference to a footnote"); //ProcessFootnoteRef(node); } } else if (node.Name == "annotation") { IScrScriptureNote ann = XmlScrNote.Deserialize(node, m_scr, m_styleSheet); if (ann != null) annotationsForPara.Add(ann); } else if (node.Name == "figure") { ProcessFigure(node); int ichEndTR = NormalizedLength(m_ParaBldr.StringBuilder); if (ichEndTR > ichBeginTR) { BTSegment bts = new BTSegment(ichBeginTR, ichEndTR, NormalizedSegment(m_ParaBldr.StringBuilder, ichBeginTR)); bts.SetBackTransForWs(0, m_tssFigureKey); segmentBTsForPara.Add(bts); } } else if (node.Name == "p") { if (m_stackXmlContext.Count == 0) throw new Exception("OXES validation failed to detect an unexpected paragraph element"); string sContext = m_stackXmlContext.Peek(); if ((sContext == ScrStyleNames.ListItem1 || sContext == ScrStyleNames.ListItem2) && sect != null) { if (fData) StoreXmlParagraphData(sect.ContentOA, sContext, annotationsForPara, segmentBTsForPara); string sStyle = (sContext == ScrStyleNames.ListItem1) ? ScrStyleNames.ListItem1Additional : ScrStyleNames.ListItem2Additional; if (ReadXmlParagraphData(node, true, sect, annotationsForPara, segmentBTsForPara)) StoreXmlParagraphData(sect.ContentOA, sStyle, annotationsForPara, segmentBTsForPara); fData = false; } else if (node is XmlElement) { throw new Exception("OXES validation failed to detect a <p> tag within a <p> tag."); } } else if (node.Name == "labelTr") { ReadXmlStringElement(node, m_wsVern, null, m_ParaBldr.StringBuilder); fData = true; AddOrAppendToSegIfNeeded(ichBeginTR, segmentBTsForPara, m_tssLabelTrKey, m_tssLabelTrKey); } else if (node is XmlElement) { throw new Exception("OXES validation failed to find a valid tag within a <p> tag."); } } if (!fImportSegmentedBT) segmentBTsForPara.Clear(); return fData; }
private string GetPartialRunData(ITsString tssPara, ref TsRunInfo tri, BTSegment bts) { ITsStrBldr tsb = tssPara.GetBldr(); int iMin = Math.Max(tri.ichMin, bts.BeginOffset); int iLim = Math.Min(tri.ichLim, bts.EndOffset); Debug.Assert(iMin <= iLim); tsb.ReplaceTsString(iLim, tssPara.Length, null); tsb.ReplaceTsString(0, iMin, null); string dataSeg = tsb.Text; string dataNFC = String.Empty; if (dataSeg != null) dataNFC = dataSeg.Normalize(); return dataNFC; }
private void WritePartialRunWithBTSegment(ITsString tssPara, int irun, ref TsRunInfo tri, List<int> rgws, List<OxesInfo> rgInfo, int iseg, BTSegment bts) { string dataNFC = GetPartialRunData(tssPara, ref tri, bts); OpenTrGroupIfNeeded(); OpenTranslationElementIfNeeded(); WriteRunDataWithEmbeddedStyleInfo(rgInfo, rgws, irun, m_cache.DefaultVernWs, dataNFC); if (bts.EndOffset <= tri.ichLim) WriteSegmentedBackTrans(bts, iseg); }
private void CloseTranslationElementIfNeededAndWriteBackTrans(BTSegment bts, TsRunInfo tri, Guid guidFootnote) { CloseTranslationElementIfNeeded(); WriteSegmentedBackTrans(bts, -1); CloseTrGroupIfNeeded(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Write out the picture as a <figure> element. /// </summary> /// <param name="pict"></param> /// ------------------------------------------------------------------------------------ private void ExportPicture(ICmPicture pict) { ITsString tssCaption = pict.Caption.BestVernacularAlternative; string sCaption; if (tssCaption.Length > 0 && !tssCaption.Equals(pict.Caption.NotFoundTss)) sCaption = tssCaption.Text.Normalize(); else sCaption = String.Empty; m_writer.WriteStartElement("figure"); string sPath = pict.PictureFileRA.AbsoluteInternalPath.Normalize(); string sFile = Path.GetFileName(sPath); WriteFigureAttributes(sCaption, sFile); m_writer.WriteComment(String.Format("path=\"{0}\"", sPath)); m_writer.WriteStartElement("caption"); OpenTrGroupIfNeeded(); List<BTSegment> rgbts = null; BackTranslationInfo trans = null; if (Options.UseInterlinearBackTranslation) { rgbts = new List<BTSegment>(); BTSegment bts = new BTSegment(0, sCaption.Normalize(NormalizationForm.FormD).Length, pict); foreach (int ws in m_dictAnalLangs.Keys) { ITsString tss = pict.Caption.GetAlternative(ws).UnderlyingTsString; if (tss.Length > 0 && tss != pict.Caption.NotFoundTss) bts.SetTransForWs(ws, tss.get_NormalizedForm(FwNormalizationMode.knmNFC)); } rgbts.Add(bts); } else { trans = new BackTranslationInfo(pict); } if (tssCaption.Length > 0) ExportParagraphData(0, tssCaption, trans, rgbts); CloseTrGroupIfNeeded(); m_writer.WriteEndElement(); //</caption> m_writer.WriteEndElement(); //</figure> }
private List<BTSegment> GetSegmentedBTInfo(IStTxtPara para) { List<BTSegment> rgBTSeg = new List<BTSegment>(); if (para == null || para.Hvo == 0) return rgBTSeg; // Backtranslation must exist if segmented BT exists ICmTranslation backtran = (para as StTxtPara).GetBT(); if (backtran == null) return rgBTSeg; // Check to see if there is at least one segmented BT bool hasSegmentedBT = false; foreach (int ws in m_dictAnalLangs.Keys) { if (backtran.Translation.GetAlternative(ws).Length > 0) { if (!(para as StTxtPara).HasNoSegmentBt(ws)) { hasSegmentedBT = true; break; } } } if (!hasSegmentedBT) return rgBTSeg; // create list of WS used for back translations. Segment all // BTs that aren't currently segmented List<int> rgWsBt = new List<int>(); foreach (int ws in m_dictAnalLangs.Keys) { if (backtran.Translation.GetAlternative(ws).Length > 0) { if ((para as StTxtPara).HasNoSegmentBt(ws)) new BtConverter(para).ConvertCmTransToInterlin(ws); rgWsBt.Add(ws); } } if (rgWsBt.Count > 0) { int kflidSegments = StTxtPara.SegmentsFlid(m_cache); int kflidFt = StTxtPara.SegmentFreeTranslationFlid(m_cache); ISilDataAccess sda = m_cache.MainCacheAccessor; int cseg = sda.get_VecSize(para.Hvo, kflidSegments); for (int iseg = 0; iseg < cseg; iseg++) { int hvoSeg = sda.get_VecItem(para.Hvo, kflidSegments, iseg); BTSegment bts = new BTSegment(m_cache, hvoSeg, para); int hvoFt = sda.get_ObjectProp(hvoSeg, kflidFt); foreach (int ws in rgWsBt) { ITsString tss = sda.get_MultiStringAlt(hvoFt, (int)CmAnnotation.CmAnnotationTags.kflidComment, ws); bts.SetTransForWs(ws, tss); string status = backtran.Status.GetAlternative(ws); if (!String.IsNullOrEmpty(status)) bts.SetBtStatusForWs(ws, status); } rgBTSeg.Add(bts); } } return rgBTSeg; }