internal static AnalysisOccurrence GetNewAnalysisOccurence(LCModel.IText text, int iPara, int iSeg, int iSegForm) { IStTxtPara para = text.ContentsOA.ParagraphsOS[iPara] as IStTxtPara; var seg = para.SegmentsOS[iSeg]; return(new AnalysisOccurrence(seg, iSegForm)); }
/// <summary> /// non-undoable task /// </summary> private void DoSetupFixture() { var textFactory = Cache.ServiceLocator.GetInstance <ITextFactory>(); var stTextFactory = Cache.ServiceLocator.GetInstance <IStTextFactory>(); m_text1 = textFactory.Create(); //Cache.LangProject.TextsOC.Add(m_text1); var stText1 = stTextFactory.Create(); m_text1.ContentsOA = stText1; var para1 = stText1.AddNewTextPara(null); (m_text1.ContentsOA[0]).Contents = TsStringUtils.MakeString("xxxa xxxb xxxc xxxd xxxe, xxxa xxxb.", Cache.DefaultVernWs); InterlinMaster.LoadParagraphAnnotationsAndGenerateEntryGuessesIfNeeded(stText1, false); // setup language project parts of speech var partOfSpeechFactory = Cache.ServiceLocator.GetInstance <IPartOfSpeechFactory>(); var adjunct = partOfSpeechFactory.Create(); var noun = partOfSpeechFactory.Create(); var verb = partOfSpeechFactory.Create(); var transitiveVerb = partOfSpeechFactory.Create(); Cache.LangProject.PartsOfSpeechOA.PossibilitiesOS.Add(adjunct); Cache.LangProject.PartsOfSpeechOA.PossibilitiesOS.Add(noun); Cache.LangProject.PartsOfSpeechOA.PossibilitiesOS.Add(verb); verb.SubPossibilitiesOS.Add(transitiveVerb); adjunct.Name.set_String(Cache.DefaultAnalWs, "adjunct"); noun.Name.set_String(Cache.DefaultAnalWs, "noun"); verb.Name.set_String(Cache.DefaultAnalWs, "verb"); transitiveVerb.Name.set_String(Cache.DefaultAnalWs, "transitive verb"); }
public void SandBoxWithGlossConfig_LoadsGuessForGlossFromAnalysis() { var mockRb = MockRepository.GenerateMock <IVwRootBox>(); mockRb.Expect(rb => rb.DataAccess).Return(Cache.MainCacheAccessor); var textFactory = Cache.ServiceLocator.GetInstance <ITextFactory>(); var stTextFactory = Cache.ServiceLocator.GetInstance <IStTextFactory>(); text = textFactory.Create(); var stText1 = stTextFactory.Create(); text.ContentsOA = stText1; var para1 = stText1.AddNewTextPara(null); (text.ContentsOA[0]).Contents = TsStringUtils.MakeString("xxxa xxxa xxxa.", Cache.DefaultVernWs); InterlinMaster.LoadParagraphAnnotationsAndGenerateEntryGuessesIfNeeded(stText1, true); using (var mockInterlinDocForAnalyis = new MockInterlinDocForAnalyis(stText1) { MockedRootBox = mockRb }) { m_sandbox.SetInterlinDocForTest(mockInterlinDocForAnalyis); var cba0_0 = AddWordsToLexiconTests.GetNewAnalysisOccurence(text, 0, 0, 0); var wf = Cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(TsStringUtils.MakeString("xxxa", Cache.DefaultVernWs)); cba0_0.Analysis = Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>().Create(wf, Cache.ServiceLocator.GetInstance <IWfiGlossFactory>()); var gloss = cba0_0.Analysis.Analysis.MeaningsOC.First(); var glossTss = TsStringUtils.MakeString("I did it", Cache.DefaultAnalWs); gloss.Form.set_String(Cache.DefaultAnalWs, glossTss); m_sandbox.SwitchWord(cba0_0); // Verify that the wordgloss was loaded into the m_sandbox Assert.AreNotEqual(0, m_sandbox.WordGlossHvo, "The gloss was not set to Default gloss from the analysis."); Assert.AreEqual(m_sandbox.WordGlossHvo, gloss.Hvo, "The gloss was not set to Default gloss from the analysis."); } }
/// <summary> /// non-undoable task /// </summary> private void DoSetupFixture() { // setup default vernacular ws. CoreWritingSystemDefinition wsXkal = Cache.ServiceLocator.WritingSystemManager.Set("qaa-x-kal"); wsXkal.DefaultFont = new FontDefinition("Times New Roman"); Cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Add(wsXkal); Cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Insert(0, wsXkal); var textFactory = Cache.ServiceLocator.GetInstance <ITextFactory>(); var stTextFactory = Cache.ServiceLocator.GetInstance <IStTextFactory>(); m_text0 = textFactory.Create(); //Cache.LangProject.TextsOC.Add(m_text0); m_stText0 = stTextFactory.Create(); m_text0.ContentsOA = m_stText0; m_para0_0 = m_stText0.AddNewTextPara(null); m_para0_0.Contents = TsStringUtils.MakeString("Xxxhope xxxthis xxxwill xxxdo. xxxI xxxhope.", wsXkal.Handle); InterlinMaster.LoadParagraphAnnotationsAndGenerateEntryGuessesIfNeeded(m_stText0, false); // paragraph 0_0 simply has wordforms as analyses foreach (var occurence in SegmentServices.GetAnalysisOccurrences(m_para0_0)) { if (occurence.HasWordform) { m_analysis_para0_0.Add(new AnalysisTree(occurence.Analysis)); } } }
public DiscourseTestHelper(LcmCache cache) { m_cache = cache; #region Load Factories and Repositories m_servLoc = m_cache.ServiceLocator; m_wAnalysisFact = m_servLoc.GetInstance <IWfiAnalysisFactory>(); m_wGlossFact = m_servLoc.GetInstance <IWfiGlossFactory>(); m_rowFact = m_servLoc.GetInstance <IConstChartRowFactory>(); m_wordGrpFact = m_servLoc.GetInstance <IConstChartWordGroupFactory>(); m_ccTagFact = m_servLoc.GetInstance <IConstChartTagFactory>(); m_mtmFact = m_servLoc.GetInstance <IConstChartMovedTextMarkerFactory>(); m_clauseMrkrFact = m_servLoc.GetInstance <IConstChartClauseMarkerFactory>(); m_partRepo = m_servLoc.GetInstance <IConstituentChartCellPartRepository>(); m_rowRepo = m_servLoc.GetInstance <IConstChartRowRepository>(); #endregion m_text = m_servLoc.GetInstance <ITextFactory>().Create(); m_stText = m_servLoc.GetInstance <IStTextFactory>().Create(); m_text.ContentsOA = m_stText; m_allOccurrences = new Dictionary <IStTxtPara, AnalysisOccurrence[]>(); m_firstPara = MakeParagraph(); }
private ITextTag MakeTag(LCModel.IText text, ICmPossibility tag, ISegment beginSeg, int begin, ISegment endSeg, int end) { ITextTag ttag = Cache.ServiceLocator.GetInstance <ITextTagFactory>().Create(); text.ContentsOA.TagsOC.Add(ttag); ttag.TagRA = tag; ttag.BeginSegmentRA = beginSeg; ttag.BeginAnalysisIndex = begin; ttag.EndSegmentRA = endSeg; ttag.EndAnalysisIndex = end; return(ttag); }
protected override void CreateTestData() { m_noun = MakePartOfSpeech("noun"); m_verb = MakePartOfSpeech("verb"); m_adj = MakePartOfSpeech("adj"); IFsFeatureSystem msFeatSys = Cache.LanguageProject.MsFeatureSystemOA; m_inflType = AddFSType(msFeatSys, "infl", AddComplexFeature(msFeatSys, "nounAgr", AddClosedFeature(msFeatSys, "num", "sg", "pl")), AddClosedFeature(msFeatSys, "tense", "pres")); m_np = Cache.LangProject.GetDefaultTextTagList().ReallyReallyAllPossibilities.Single(poss => poss.Abbreviation.BestAnalysisAlternative.Text == "Noun Phrase"); ILexEntry ni = MakeEntry("ni-", m_verb, "1SgSubj"); ILexEntry him = MakeEntry("him-", m_verb, "3SgObj"); ILexEntry bili = MakeEntry("bili", m_verb, "to see"); ILexEntry ra = MakeEntry("-ra", m_verb, "Pres", new FS { { GetFeature("tense"), GetValue("pres") } }); ILexEntry pus = MakeEntry("pus", m_adj, "green"); ILexEntry yalo = MakeEntry("yalo", m_noun, "mat"); ILexEntry la = MakeEntry("-la", m_noun, "1SgPoss", new FS { { GetFeature("nounAgr"), new FS { { GetFeature("num"), GetValue("sg") } } } }); MakeWordform("nihimbilira", "I see", m_verb, ni, him, bili, ra); MakeWordform("pus", "green", m_adj, pus); MakeWordform("yalola", "my mat", m_noun, yalo, la); MakeWordform("ban", "test", MakePartOfSpeech("pos")); m_text = MakeText("nihimbilira pus, yalola ban."); var para = (IStTxtPara)m_text.ContentsOA.ParagraphsOS.First(); MakeTag(m_text, m_np, para.SegmentsOS.First(), 1, para.SegmentsOS.First(), 3); }
/// <summary> /// Do the conversion. The signature of this method is required for use with ProgressDialogWithTask.RunTask, /// but the parameters and return result are not actually used. /// </summary> private object DoConversion(IThreadedProgress dlg, object[] parameters) { m_firstNewText = null; foreach (var path1 in InputFiles) { var path = path1.Trim(); if (!File.Exists(path)) { continue; // report? } var input = new ByteReader(path); var converterStage1 = GetSfmConverter(); var stage1 = converterStage1.Convert(input, m_mappings, m_cache.ServiceLocator.WritingSystemManager); // Skip actual import if SHIFT was held down. if (secretShiftText.Visible == true) { continue; } DoStage2Conversion(stage1, dlg); } return(null); }
/// <summary> /// non-undoable task /// </summary> private void DoSetupFixture() { // setup default vernacular ws. m_wsXkal = Cache.ServiceLocator.WritingSystemManager.Set("qaa-x-kal"); m_wsXkal.DefaultFont = new FontDefinition("Times New Roman"); Cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Add(m_wsXkal); Cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Insert(0, m_wsXkal); m_textsDefn = new XmlDocument(); m_tagRepo = Cache.ServiceLocator.GetInstance <ITextTagRepository>(); string textDefinitionsPath = Path.Combine(FwDirectoryFinder.SourceDirectory, "LexText", "Interlinear", "ITextDllTests", "ParagraphParserTestTexts.xml"); m_text1 = LoadTestText(textDefinitionsPath, 1, m_textsDefn); m_para1 = m_text1.ContentsOA.ParagraphsOS[0] as IStTxtPara; ParseTestText(); m_tagChild = new TestTaggingChild(Cache); m_tagChild.SetText(m_text1.ContentsOA); // This could change, but at least it gives a reasonably stable list to test from. m_textMarkupTags = Cache.LangProject.GetDefaultTextTagList(); LoadTagListPossibilities(); }
/// <summary> /// This method (as far as I know) will be first called on the StText object, and then recursively from the /// base implementation for vector items in component objects. /// </summary> /// <param name="tag"></param> /// <param name="vc"></param> /// <param name="frag"></param> public override void AddObjVecItems(int tag, IVwViewConstructor vc, int frag) { ICmObject text = null; switch (frag) { case InterlinVc.kfragInterlinPara: m_writer.WriteStartElement("interlinear-text"); //here the m_hvoCurr object is an StText object, store the IText owner //so that we can pull data from it to close out the interlinear-text element //Naylor 11-2011 text = m_repoObj.GetObject(m_hvoCurr).Owner; if (text is IScrBook || text is IScrSection) { m_writer.WriteAttributeString("guid", m_repoObj.GetObject(m_hvoCurr).Guid.ToString()); } else { m_writer.WriteAttributeString("guid", text.Guid.ToString()); } foreach (var mTssPendingTitle in pendingTitles) { var hystericalRaisens = mTssPendingTitle; WritePendingItem("title", ref hystericalRaisens); } foreach (var mTssPendingAbbrev in pendingAbbreviations) { var hystericalRaisens = mTssPendingAbbrev; WritePendingItem("title-abbreviation", ref hystericalRaisens); } foreach (var source in pendingSources) { var hystericalRaisens = source; WritePendingItem("source", ref hystericalRaisens); } foreach (var desc in pendingComments) { var hystericalRaisens = desc; WritePendingItem("comment", ref hystericalRaisens); } m_writer.WriteStartElement("paragraphs"); break; case InterlinVc.kfragParaSegment: m_writer.WriteStartElement("phrases"); break; case InterlinVc.kfragBundle: m_writer.WriteStartElement("words"); break; case InterlinVc.kfragMorphBundle: m_writer.WriteStartElement("morphemes"); break; default: break; } base.AddObjVecItems(tag, vc, frag); switch (frag) { case InterlinVc.kfragInterlinPara: m_writer.WriteEndElement(); // paragraphs m_writer.WriteStartElement("languages"); foreach (int wsActual in m_usedWritingSystems) { m_writer.WriteStartElement("language"); // we don't have enough context at this point to get all the possible writing system // information we may encounter in the word bundles. string icuCode = m_cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(wsActual); m_writer.WriteAttributeString("lang", icuCode); CoreWritingSystemDefinition ws = m_wsManager.Get(wsActual); string fontName = ws.DefaultFontName; m_writer.WriteAttributeString("font", fontName); if (m_cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Contains(ws)) { m_writer.WriteAttributeString("vernacular", "true"); } if (ws.RightToLeftScript) { m_writer.WriteAttributeString("RightToLeft", "true"); } m_writer.WriteEndElement(); } m_writer.WriteEndElement(); // languages //Media files section if (text != null && text is LCModel.IText && ((LCModel.IText)text).MediaFilesOA != null) { LCModel.IText theText = (LCModel.IText)text; m_writer.WriteStartElement("media-files"); m_writer.WriteAttributeString("offset-type", theText.MediaFilesOA.OffsetType); foreach (var mediaFile in theText.MediaFilesOA.MediaURIsOC) { m_writer.WriteStartElement("media"); m_writer.WriteAttributeString("guid", mediaFile.Guid.ToString()); m_writer.WriteAttributeString("location", mediaFile.MediaURI); m_writer.WriteEndElement(); //media } m_writer.WriteEndElement(); //media-files } m_writer.WriteEndElement(); // interlinear-text //wipe out the pending items to be clean for next text. pendingTitles.Clear(); pendingSources.Clear(); pendingAbbreviations.Clear(); pendingComments.Clear(); break; case InterlinVc.kfragParaSegment: case InterlinVc.kfragBundle: case InterlinVc.kfragMorphBundle: m_writer.WriteEndElement(); break; default: break; } }
/// <summary> /// Set text metadata, create or merge media file URI's. /// <note>media files (ELAN initiated) need to be processed before the paragraphs, as segments could reference these parts.</note> /// </summary> /// <param name="cache"></param> /// <param name="interlinText">The source text</param> /// <param name="wsFactory"></param> /// <param name="newText">The target text</param> /// <param name="merging">True if we are merging into an existing text; False if we are creating everything new</param> private static void SetTextMetaAndMergeMedia(LcmCache cache, Interlineartext interlinText, ILgWritingSystemFactory wsFactory, LCModel.IText newText, bool merging) { if (interlinText.Items != null) // apparently it is null if there are no items. { foreach (var item in interlinText.Items) { switch (item.type) { case "title": newText.Name.set_String(GetWsEngine(wsFactory, item.lang).Handle, item.Value); break; case "title-abbreviation": newText.Abbreviation.set_String(GetWsEngine(wsFactory, item.lang).Handle, item.Value); break; case "source": newText.Source.set_String(GetWsEngine(wsFactory, item.lang).Handle, item.Value); break; case "comment": newText.Description.set_String(GetWsEngine(wsFactory, item.lang).Handle, item.Value); break; } } } if (interlinText.mediafiles != null) { if (newText.MediaFilesOA == null) { newText.MediaFilesOA = cache.ServiceLocator.GetInstance <ICmMediaContainerFactory>().Create(); } newText.MediaFilesOA.OffsetType = interlinText.mediafiles.offsetType; foreach (var mediaFile in interlinText.mediafiles.media) { ICmObject extantObject; cache.ServiceLocator.ObjectRepository.TryGetObject(new Guid(mediaFile.guid), out extantObject); var media = extantObject as ICmMediaURI; if (media == null) { media = cache.ServiceLocator.GetInstance <ICmMediaURIFactory>().Create(cache, new Guid(mediaFile.guid)); newText.MediaFilesOA.MediaURIsOC.Add(media); } else if (!merging) { // If a media URI with the same GUID exists, and we are not merging, create a new media URI with a new GUID media = cache.ServiceLocator.GetInstance <ICmMediaURIFactory>().Create(); newText.MediaFilesOA.MediaURIsOC.Add(media); // Update references to this Media URI foreach (var phrase in interlinText.paragraphs.SelectMany(para => para.phrases)) { if (mediaFile.guid.Equals(phrase.mediaFile)) { phrase.mediaFile = media.Guid.ToString(); } } } // else, the media URI already exists and we are merging; simply update the location media.MediaURI = mediaFile.location; } } }
/// <summary> /// This method will create a new Text document from the given BIRD format Interlineartext. If this fails /// for some reason then return false to tell the calling method to abort the import. /// </summary> /// <param name="newText">The text to populate, could be set to null.</param> /// <param name="textParams">This contains the interlinear text.</param> /// <returns>The imported text may be in a writing system that is not part of this project. Return false if the user /// rejects the text which tells the caller of this method to abort the import.</returns> private static bool PopulateTextFromBIRDDoc(ref LCModel.IText newText, TextCreationParams textParams) { s_importOptions = textParams.ImportOptions; Interlineartext interlinText = textParams.InterlinText; LcmCache cache = textParams.Cache; IThreadedProgress progress = textParams.Progress; if (s_importOptions.CheckAndAddLanguages == null) { s_importOptions.CheckAndAddLanguages = CheckAndAddLanguagesInternal; } ILgWritingSystemFactory wsFactory = cache.WritingSystemFactory; const char space = ' '; //handle the languages(writing systems) section alerting the user if new writing systems are encountered if (!s_importOptions.CheckAndAddLanguages(cache, interlinText, wsFactory, progress)) { return(false); } //handle the header(info or meta) information SetTextMetaAndMergeMedia(cache, interlinText, wsFactory, newText, false); //create all the paragraphs foreach (var paragraph in interlinText.paragraphs) { if (newText.ContentsOA == null) { newText.ContentsOA = cache.ServiceLocator.GetInstance <IStTextFactory>().Create(); } IStTxtPara newTextPara = newText.ContentsOA.AddNewTextPara(""); int offset = 0; if (paragraph.phrases == null) { continue; } foreach (var phrase in paragraph.phrases) { ICmObject oldSegment = null; //Try and locate a segment with this Guid. if (!String.IsNullOrEmpty(phrase.guid)) { if (cache.ServiceLocator.ObjectRepository.TryGetObject(new Guid(phrase.guid), out oldSegment)) { //We aren't merging, but we have this guid in our system; ignore the file Guid oldSegment = cache.ServiceLocator.GetInstance <ISegmentFactory>().Create(newTextPara, offset); } else { //The segment is identified by a Guid, but apparently we don't have it in our current document, so make one with the guid oldSegment = cache.ServiceLocator.GetInstance <ISegmentFactory>().Create(newTextPara, offset, cache, new Guid(phrase.guid)); } } //set newSegment to the old, or create a brand new one. ISegment newSegment = oldSegment as ISegment ?? cache.ServiceLocator.GetInstance <ISegmentFactory>().Create(newTextPara, offset); //Fill in the ELAN time information if it is present. AddELANInfoToSegment(cache, phrase, newSegment); ITsString phraseText = null; bool textInFile = false; //Add all of the data from <item> elements into the segment. AddSegmentItemData(cache, wsFactory, phrase, newSegment, ref textInFile, ref phraseText); bool lastWasWord = false; if (phrase.WordsContent != null && phrase.WordsContent.Words != null) { if (textParams.Version == 0 && PhraseHasExactlyOneTxtItemNotAKnownWordform(newSegment.Cache, phrase)) { // It might be a SayMore text that makes the whole segment a single txt item. // We want to add the text anyway (unless a higher level did so), but we will skip making // a wordform. Eventual parsing of the text will do so. if (!textInFile) { UpdatePhraseTextForWordItems(wsFactory, ref phraseText, phrase.WordsContent.Words[0], ref lastWasWord, space); } } else { foreach (var word in phrase.WordsContent.Words) { //If the text of the phrase was not given in the document build it from the words. if (!textInFile) { UpdatePhraseTextForWordItems(wsFactory, ref phraseText, word, ref lastWasWord, space); } AddWordToSegment(newSegment, word); } } } UpdateParagraphTextForPhrase(newTextPara, ref offset, phraseText); } } return(true); }
/// <summary> /// Merge the contents of the given Text into the exising one. If this fails /// for some reason then return false to tell the calling method to abort the import. /// </summary> /// <param name="newText"></param> /// <param name="textParams"></param> /// <returns>The imported text may be in a writing system that is not part of this project. Return false if the user /// rejects the text which tells the caller of this method to abort the import.</returns> private static bool MergeTextWithBIRDDoc(ref LCModel.IText newText, TextCreationParams textParams) { s_importOptions = textParams.ImportOptions; Interlineartext interlinText = textParams.InterlinText; LcmCache cache = textParams.Cache; IThreadedProgress progress = textParams.Progress; if (s_importOptions.CheckAndAddLanguages == null) { s_importOptions.CheckAndAddLanguages = CheckAndAddLanguagesInternal; } ILgWritingSystemFactory wsFactory = cache.WritingSystemFactory; char space = ' '; //handle the languages(writing systems) section alerting the user if new writing systems are encountered if (!s_importOptions.CheckAndAddLanguages(cache, interlinText, wsFactory, progress)) { return(false); } //handle the header(info or meta) information as well as any media-files sections SetTextMetaAndMergeMedia(cache, interlinText, wsFactory, newText, true); IStText newContents = newText.ContentsOA; //create or reuse the paragraphs available. NOTE: Currently the paragraph guids are being ignored, this might be wrong. foreach (var paragraph in interlinText.paragraphs) { IStTxtPara newTextPara = null; if (newContents == null) { newContents = cache.ServiceLocator.GetInstance <IStTextFactory>().Create(); newText.ContentsOA = newContents; newTextPara = newContents.AddNewTextPara(""); } int offset = 0; if (paragraph.phrases == null) { continue; } foreach (var phrase in paragraph.phrases) { ICmObject oldSegment = null; //Try and locate a segment with this Guid. Assign newTextPara to the paragraph we're working on if we haven't already if (!String.IsNullOrEmpty(phrase.guid)) { if (cache.ServiceLocator.ObjectRepository.TryGetObject(new Guid(phrase.guid), out oldSegment)) { if (oldSegment as ISegment != null) //The segment matches, add it into our paragraph. { IStTxtPara segmentOwner = newContents.ParagraphsOS.FirstOrDefault(para => para.Guid.Equals((oldSegment as ISegment).Owner.Guid)) as IStTxtPara; if (segmentOwner != null && newTextPara == null) //We found the StTxtPara that correspond to this paragraph { newTextPara = segmentOwner; } } else if (oldSegment == null) //The segment is identified by a Guid, but apparently we don't have it in our current document, so make one { if (newTextPara == null) { newTextPara = newContents.AddNewTextPara(""); } oldSegment = cache.ServiceLocator.GetInstance <ISegmentFactory>().Create(newTextPara, offset, cache, new Guid(phrase.guid)); } else //The Guid is in use, but not by a segment. This is bad. { return(false); } } } //If newTextPara is null, try to use a paragraph that a sibling phrase belongs to. //Note: newTextPara is only assigned once, and won't be reassigned until we iterate through a new paragraph. if (newTextPara == null) { var phraseGuids = paragraph.phrases.Select(p => p.guid); foreach (IStTxtPara para in newContents.ParagraphsOS) { if (para.SegmentsOS.Any(seg => phraseGuids.Contains(seg.Guid.ToString()))) { newTextPara = para; break; } } } //Can't find any paragraph for our phrase, create a brand new paragraph if (newTextPara == null) { newTextPara = newContents.AddNewTextPara(""); } //set newSegment to the old, or create a brand new one. ISegment newSegment = oldSegment as ISegment; if (newSegment == null) { if (!string.IsNullOrEmpty(phrase.guid)) { //The segment is identified by a Guid, but apparently we don't have it in our current document, so make one with the guid newSegment = cache.ServiceLocator.GetInstance <ISegmentFactory>().Create(newTextPara, offset, cache, new Guid(phrase.guid)); } else { newSegment = cache.ServiceLocator.GetInstance <ISegmentFactory>().Create(newTextPara, offset); } } //Fill in the ELAN time information if it is present. AddELANInfoToSegment(cache, phrase, newSegment); ITsString phraseText = null; bool textInFile = false; //Add all of the data from <item> elements into the segment. AddSegmentItemData(cache, wsFactory, phrase, newSegment, ref textInFile, ref phraseText); bool lastWasWord = false; if (phrase.WordsContent != null && phrase.WordsContent.Words != null) { //Rewrite our analyses newSegment.AnalysesRS.Clear(); foreach (var word in phrase.WordsContent.Words) { //If the text of the phrase was not found in a "txt" item for this segment then build it from the words. if (!textInFile) { UpdatePhraseTextForWordItems(wsFactory, ref phraseText, word, ref lastWasWord, space); } MergeWordToSegment(newSegment, word); } } UpdateParagraphTextForPhrase(newTextPara, ref offset, phraseText); } } return(true); }