private void SaveAnalysisForAnnotation(AnalysisOccurrence occurrence, AnalysisTree newAnalysisTree)
        {
            Debug.Assert(occurrence != null);
            // Record the old wordform before we alter InstanceOf.
            IWfiWordform oldWf = occurrence.Analysis.Wordform;

            var wfToTryDeleting = occurrence.Analysis as IWfiWordform;

            // This is the property that each 'in context' object has that points at one of the WfiX classes as the
            // analysis of the word.
            occurrence.Analysis = newAnalysisTree.Analysis;

            // In case the wordform we point at has a form that doesn't match, we may need to set up an overidden form for the annotation.
            IWfiWordform targetWordform = newAnalysisTree.Wordform;

            if (targetWordform != null)
            {
                TryCacheRealWordForm(occurrence);
            }

            // It's possible if the new analysis is a different case form that the old wordform is now
            // unattested and should be removed.
            if (wfToTryDeleting != null && wfToTryDeleting != occurrence.Analysis.Wordform)
            {
                wfToTryDeleting.DeleteIfSpurious();
            }
        }
        /// <summary>
        /// Using the current focus box content, approve it and apply it to all unanalyzed matching
        /// wordforms in the text.  See LT-8833.
        /// </summary>
        /// <returns></returns>
        public void ApproveGuessOrChangesForWholeTextAndMoveNext(Command cmd)
        {
            // Go through the entire text looking for matching analyses that can be set to the new
            // value.
            if (SelectedOccurrence == null)
            {
                return;
            }
            var oldWf  = SelectedOccurrence.Analysis.Wordform;
            var stText = SelectedOccurrence.Paragraph.Owner as IStText;

            if (stText == null || stText.ParagraphsOS.Count == 0)
            {
                return;                 // paranoia, we should be in one of its paragraphs.
            }
            // We don't need to discard existing guesses, even though we will modify Segment.Analyses,
            // since guesses for other wordforms will not be affected, and there will be no remaining
            // guesses for the word we're confirming everywhere. (This needs to be outside the block
            // for the UOW, since what we are suppressing happens at the completion of the UOW.)
            InterlinDoc.SuppressResettingGuesses(
                () =>
            {
                // Needs to include GetRealAnalysis, since it might create a new one.
                UndoableUnitOfWorkHelper.Do(cmd.UndoText, cmd.RedoText, Cache.ActionHandlerAccessor,
                                            () =>
                {
                    IWfiAnalysis obsoleteAna;
                    AnalysisTree newAnalysisTree = InterlinWordControl.GetRealAnalysis(true, out obsoleteAna);
                    var wf = newAnalysisTree.Wordform;
                    if (newAnalysisTree.Analysis == wf)
                    {
                        // nothing significant to confirm, so move on
                        // (return means get out of this lambda expression, not out of the method).
                        return;
                    }
                    SaveAnalysisForAnnotation(SelectedOccurrence, newAnalysisTree);
                    // determine if we confirmed on a sentence initial wordform to its lowercased form
                    bool fIsSentenceInitialCaseChange = oldWf != wf;
                    if (wf != null)
                    {
                        ApplyAnalysisToInstancesOfWordform(newAnalysisTree.Analysis, oldWf, wf);
                    }
                    // don't try to clean up the old analysis until we've finished walking through
                    // the text and applied all our changes, otherwise we could delete a wordform
                    // that is referenced by dummy annotations in the text, and thus cause the display
                    // to treat them like pronunciations, and just show an unanalyzable text (LT-9953)
                    FinishSettingAnalysis(newAnalysisTree, InitialAnalysis);
                    if (obsoleteAna != null)
                    {
                        obsoleteAna.Delete();
                    }
                });
            });
            // This should not make any data changes, since we're telling it not to save and anyway
            // we already saved the current annotation. And it can't correctly place the focus box
            // until the change we just did are completed and PropChanged sent. So keep this outside the UOW.
            OnNextBundle(cmd, false, false, false, true);
        }
		/// <summary>
		/// Initially, the analysis we based the list on. After the user makes a selection,
		/// the selection he made.
		/// </summary>
		public AnalysisTree GetAnalysisTree()
		{
				var analysisTree = new AnalysisTree();
				if (m_hvoAnalysis != 0)
				{
					var analysisObj = (IAnalysis)m_cache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(m_hvoAnalysis);
					analysisTree.Analysis = analysisObj;
				}
				return analysisTree;
		}
示例#4
0
        /// <summary>
        /// Initially, the analysis we based the list on. After the user makes a selection,
        /// the selection he made.
        /// </summary>
        public AnalysisTree GetAnalysisTree()
        {
            var analysisTree = new AnalysisTree();

            if (m_hvoAnalysis != 0)
            {
                var analysisObj = (IAnalysis)m_cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(m_hvoAnalysis);
                analysisTree.Analysis = analysisObj;
            }
            return(analysisTree);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="fSaveGuess"></param>
        protected virtual void ApproveAnalysis(bool fSaveGuess)
        {
            IWfiAnalysis obsoleteAna;
            AnalysisTree newAnalysisTree = InterlinWordControl.GetRealAnalysis(fSaveGuess, out obsoleteAna);

            // if we've made it this far, might as well try to go the whole way through the UOW.
            SaveAnalysisForAnnotation(SelectedOccurrence, newAnalysisTree);
            FinishSettingAnalysis(newAnalysisTree, InitialAnalysis);
            if (obsoleteAna != null)
            {
                obsoleteAna.Delete();
            }
        }
示例#6
0
 public virtual void SelectOccurrence(AnalysisOccurrence selected)
 {
     SelectedOccurrence = selected;
     InitialAnalysis    = new AnalysisTree();
     if (SelectedOccurrence != null)
     {
         if (Cache == null)
         {
             Cache = SelectedOccurrence.Analysis.Cache;
         }
         InitialAnalysis.Analysis = SelectedOccurrence.Analysis;
     }
     ChangeOrCreateSandbox(selected);
 }
        private void FinishSettingAnalysis(AnalysisTree newAnalysisTree, AnalysisTree oldAnalysisTree)
        {
            if (newAnalysisTree.Analysis == oldAnalysisTree.Analysis)
            {
                return;
            }
            List <int> msaHvoList = new List <int>();
            // Collecting for the new analysis is probably overkill, since the MissingEntries combo will only have MSAs
            // that are already referenced outside of the focus box (namely by the Senses). It's unlikely, therefore,
            // that we could configure the Focus Box in such a state as to remove the last link to an MSA in the
            // new analysis.  But just in case it IS possible...
            IWfiAnalysis newWa = newAnalysisTree.WfiAnalysis;

            if (newWa != null)
            {
                // Make sure this analysis is marked as user-approved (green check mark)
                Cache.LangProject.DefaultUserAgent.SetEvaluation(newWa, Opinions.approves);
            }
        }
示例#8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="undoRedoText">Approving the state of the FocusBox can be associated with
        /// different user actions (ie. UOW)</param>
        /// <param name="fSaveGuess"></param>
        /// <param name="nextWordform"></param>
        internal void UpdateRealFromSandbox(ICommandUndoRedoText undoRedoText, bool fSaveGuess,
                                            AnalysisOccurrence nextWordform)
        {
            if (!ShouldCreateAnalysisFromSandbox(fSaveGuess))
            {
                return;
            }

            var origWordform = SelectedOccurrence;

            if (!origWordform.IsValid)
            {
                return;                 // something (editing elsewhere?) has put things in a bad state; cf LTB-1665.
            }
            var origWag     = new AnalysisTree(origWordform.Analysis);
            var undoText    = undoRedoText != null ? undoRedoText.UndoText : ITextStrings.ksUndoApproveAnalysis;
            var redoText    = undoRedoText != null ? undoRedoText.RedoText : ITextStrings.ksRedoApproveAnalysis;
            var oldAnalysis = SelectedOccurrence.Analysis;

            try
            {
                // Updating one of a segment's analyses would normally reset the analysis cache.
                // And we may have to: UpdatingOccurrence will figure out whether to do it or not.
                // But we don't want it to happen as an automatic side effect of the PropChanged.
                InterlinDoc.SuspendResettingAnalysisCache = true;
                UndoableUnitOfWorkHelper.Do(undoText, redoText,
                                            Cache.ActionHandlerAccessor, () => ApproveAnalysisAndMove(fSaveGuess, nextWordform));
            }
            finally
            {
                InterlinDoc.SuspendResettingAnalysisCache = false;
            }
            var newAnalysis = SelectedOccurrence.Analysis;

            InterlinDoc.UpdatingOccurrence(oldAnalysis, newAnalysis);
            var newWag    = new AnalysisTree(origWordform.Analysis);
            var wordforms = new HashSet <IWfiWordform> {
                origWag.Wordform, newWag.Wordform
            };

            InterlinDoc.UpdateGuesses(wordforms);
        }
			public GetRealAnalysisMethod(IHelpTopicProvider helpTopicProvider, SandboxBase owner,
				CachePair caches, int hvoSbWord, AnalysisTree oldAnalysis, IWfiAnalysis wa,
				IWfiGloss gloss, InterlinLineChoices choices, ITsString tssForm,
				bool fWantOnlyWfiAnalysis) : this()
			{
				m_helpTopicProvider = helpTopicProvider;
				m_sandbox = owner;
				m_caches = caches;
				m_hvoSbWord = hvoSbWord;
				m_oldAnalysis = oldAnalysis;
				m_wf = oldAnalysis.Wordform;
				m_wa = wa;
				m_wg = gloss;
				m_sda = m_caches.DataAccess;
				m_sdaMain = m_caches.MainCache.MainCacheAccessor;
				m_cmorphs = m_sda.get_VecSize(m_hvoSbWord, ktagSbWordMorphs);
				m_choices = choices;
				m_tssForm = tssForm;
				m_fWantOnlyWfiAnalysis = fWantOnlyWfiAnalysis;
			}
		public void ImportNewHumanApprovedByDefaultWordGloss()
		{
			var wsf = Cache.WritingSystemFactory;

			const string xml = "<document><interlinear-text>" +
				"<paragraphs><paragraph><phrases><phrase><words>" +
					"<word>" +
						"<item type='txt' lang='en'>supercalifragilisticexpialidocious</item>" +
						"<item type='gls' lang='pt'>absurdo</item>" +
					"</word>" +
				"</words></phrase></phrases></paragraph></paragraphs></interlinear-text></document>";

			var li = new BIRDFormatImportTests.LLIMergeExtension(Cache, null, null);
			FDO.IText importedText = null;
			var options = CreateImportInterlinearOptions(xml);
			li.ImportInterlinear(options, ref importedText);
			using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
			{
				firstEntry.MoveNext();
				var imported = firstEntry.Current;
				Assert.IsNotNull(imported);
				var para = imported.ContentsOA.ParagraphsOS[0] as IStTxtPara;
				Assert.IsNotNull(para);
				Assert.That(para.Analyses.Count(), Is.EqualTo(1));
				var wfiWord = para.Analyses.First().Wordform;
				int wsWordform = wsf.get_Engine("en").Handle;
				Assert.That(wfiWord.Form.get_String(wsf.get_Engine("en").Handle).Text,
					Is.EqualTo("supercalifragilisticexpialidocious"));

				Assert.That(wfiWord.AnalysesOC.Count, Is.GreaterThan(0));

				var wfiAnalysis = wfiWord.AnalysesOC.First();
				// make sure we also created a morpheme form
				AssertMorphemeFormMatchesWordform(wfiWord, wfiAnalysis, wsWordform);
				// make sure we created a human approved opinion
				AssertHumanApprovedOpinion(wfiWord, wfiAnalysis);

				var at = new AnalysisTree(para.Analyses.First());
				Assert.IsNotNull(at.Gloss, "IAnalysis should be WfiGloss");
				Assert.That(at.Gloss.Form.get_String(wsf.get_Engine("pt").Handle).Text, Is.EqualTo("absurdo"));

				Assert.That(Cache.ServiceLocator.GetInstance<IWfiGlossRepository>().Count, Is.EqualTo(1));
				Assert.That(Cache.ServiceLocator.GetInstance<IWfiMorphBundleRepository>().Count, Is.EqualTo(1));
				Assert.That(Cache.ServiceLocator.GetInstance<IWfiAnalysisRepository>().Count, Is.EqualTo(1));
				Assert.That(Cache.ServiceLocator.GetInstance<IWfiWordformRepository>().Count, Is.EqualTo(1));
			}
		}
示例#11
0
		/// <summary>
		/// Load guesses for the paragraph.
		/// </summary>
		/// <param name="para"></param>
		/// <param name="wordforms"></param>
		internal void LoadAnalysisData(IStTxtPara para, HashSet<IWfiWordform> wordforms)
		{
			if (para.SegmentsOS.Count == 0 || para.SegmentsOS[0].AnalysesRS.Count == 0)
				return;
			// TODO: reload decorator at the appropriate time.
			foreach (var occurrence in SegmentServices.StTextAnnotationNavigator.GetWordformOccurrencesAdvancingInPara(para))
			{
				var wag = new AnalysisTree(occurrence.Analysis);
				if (wordforms == null || wordforms.Contains(wag.Wordform))
				{
					NoteCurrentAnnotation(occurrence);
					RecordGuessIfAvailable(occurrence);
				}
			}
		}
		/// <summary>
		///
		/// </summary>
		/// <param name="undoRedoText">Approving the state of the FocusBox can be associated with
		/// different user actions (ie. UOW)</param>
		/// <param name="fSaveGuess"></param>
		/// <param name="nextWordform"></param>
		internal void UpdateRealFromSandbox(ICommandUndoRedoText undoRedoText, bool fSaveGuess,
			AnalysisOccurrence nextWordform)
		{
			if (!ShouldCreateAnalysisFromSandbox(fSaveGuess))
				return;

			var origWordform = SelectedOccurrence;
			if (!origWordform.IsValid)
				return; // something (editing elsewhere?) has put things in a bad state; cf LTB-1665.
			var origWag = new AnalysisTree(origWordform.Analysis);
			var undoText = undoRedoText != null ? undoRedoText.UndoText : ITextStrings.ksUndoApproveAnalysis;
			var redoText = undoRedoText != null ? undoRedoText.RedoText : ITextStrings.ksRedoApproveAnalysis;
			var oldAnalysis = SelectedOccurrence.Analysis;
			try
			{
				// Updating one of a segment's analyses would normally reset the analysis cache.
				// And we may have to: UpdatingOccurrence will figure out whether to do it or not.
				// But we don't want it to happen as an automatic side effect of the PropChanged.
				InterlinDoc.SuspendResettingAnalysisCache = true;
				UndoableUnitOfWorkHelper.Do(undoText, redoText,
					Cache.ActionHandlerAccessor, () => ApproveAnalysisAndMove(fSaveGuess, nextWordform));
			}
			finally
			{
				InterlinDoc.SuspendResettingAnalysisCache = false;
			}
			var newAnalysis = SelectedOccurrence.Analysis;
			InterlinDoc.UpdatingOccurrence(oldAnalysis, newAnalysis);
			var newWag = new AnalysisTree(origWordform.Analysis);
			var wordforms = new HashSet<IWfiWordform> { origWag.Wordform, newWag.Wordform };
			InterlinDoc.UpdateGuesses(wordforms);
		}
		public void ImportNewUserConfirmedWordGlossSeparatedFromToExistingWfiAnalysis()
		{
			// build pre-existing data
			var sl = Cache.ServiceLocator;
			var wsf = Cache.WritingSystemFactory;

			FDO.IText text;

			IWfiWordform word = null;
			ITsString paraContents = null;
			var segGuid = new Guid();
			NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
			{
				text = sl.GetInstance<ITextFactory>().Create(Cache, new Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"));
				//Cache.LangProject.TextsOC.Add(text);
				var sttext = sl.GetInstance<IStTextFactory>().Create();
				text.ContentsOA = sttext;
				IStTxtPara para = sl.GetInstance<IStTxtParaFactory>().Create();
				sttext.ParagraphsOS.Add(para);
				para.Contents = Cache.TsStrFactory.MakeString("supercalifragilisticexpialidocious", wsf.get_Engine("en").Handle);
				paraContents = para.Contents;
				ISegment segment = sl.GetInstance<ISegmentFactory>().Create();
				para.SegmentsOS.Add(segment);
				ITsString wform = TsStringUtils.MakeTss("supercalifragilisticexpialidocious",
					wsf.get_Engine("en").Handle);
				segGuid = segment.Guid;
				word = sl.GetInstance<IWfiWordformFactory>().Create(wform);
				var newWfiAnalysis = sl.GetInstance<IWfiAnalysisFactory>().Create();
				word.AnalysesOC.Add(newWfiAnalysis);
				segment.AnalysesRS.Add(word);
			});

			// import an analysis with word gloss
			string xml = "<document><interlinear-text guid='AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA'>" +
				"<paragraphs><paragraph><phrases><phrase guid='" + segGuid + "'><words>" +
					"<word>" +
						"<item type='txt' lang='en'>supercalifragilisticexpialidocious</item>" +
						"<item type='gls' lang='pt'>absurdo</item>" +
					"</word>" +
				"</words></phrase></phrases></paragraph></paragraphs></interlinear-text></document>";

			var li = new BIRDFormatImportTests.LLIMergeExtension(Cache, null, null);
			var options = CreateImportInterlinearOptions(xml);
			FDO.IText importedText = null;
			li.ImportInterlinear(options, ref importedText);
			using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
			{
				firstEntry.MoveNext();
				var imported = firstEntry.Current;
				Assert.IsNotNull(imported);
				var importedPara = imported.ContentsOA.ParagraphsOS[0] as IStTxtPara;
				Assert.IsNotNull(importedPara);

				// assert that new Analysis was created
				Assert.That(Cache.ServiceLocator.GetInstance<IWfiAnalysisRepository>().Count, Is.EqualTo(2));

				// make sure imported word gloss is correct
				Assert.That(importedPara.SegmentsOS[0].AnalysesRS.Count, Is.EqualTo(1));
				var importedAnalysis = importedPara.SegmentsOS[0].AnalysesRS[0];
				var skippedWord = importedAnalysis.Wordform;
				var at = new AnalysisTree(importedAnalysis);
				Assert.IsNotNull(at.Gloss, "IAnalysis should be WfiGloss");
				var newGloss = at.Gloss;
				Assert.That(newGloss.Form.get_String(wsf.get_Engine("pt").Handle).Text, Is.EqualTo("absurdo"));
				Assert.That(skippedWord.Guid, Is.EqualTo(word.Guid));

				// make sure nothing else has changed:
				Assert.That(Cache.LanguageProject.Texts.Count, Is.EqualTo(1));
				Assert.That(imported.ContentsOA.ParagraphsOS.Count, Is.EqualTo(1));
				Assert.AreEqual(paraContents.Text, importedPara.Contents.Text, "Imported Para contents differ from original");
				Assert.IsTrue(paraContents.Equals(importedPara.Contents), "Ws mismatch between imported and original paragraph");
				Assert.That(skippedWord.Form.get_String(wsf.get_Engine("en").Handle).Text,
					Is.EqualTo("supercalifragilisticexpialidocious"));
				Assert.That(skippedWord.Guid, Is.EqualTo(word.Guid));

				// make sure nothing else changed
				Assert.That(Cache.ServiceLocator.GetInstance<IWfiGlossRepository>().Count, Is.EqualTo(1));
				Assert.That(Cache.ServiceLocator.GetInstance<IWfiWordformRepository>().Count, Is.EqualTo(1));
			}
		}
		private void FinishSettingAnalysis(AnalysisTree newAnalysisTree, AnalysisTree oldAnalysisTree)
		{
			if (newAnalysisTree.Analysis == oldAnalysisTree.Analysis)
				return;
			List<int> msaHvoList = new List<int>();
			// Collecting for the new analysis is probably overkill, since the MissingEntries combo will only have MSAs
			// that are already referenced outside of the focus box (namely by the Senses). It's unlikely, therefore,
			// that we could configure the Focus Box in such a state as to remove the last link to an MSA in the
			// new analysis.  But just in case it IS possible...
			IWfiAnalysis newWa = newAnalysisTree.WfiAnalysis;
			if (newWa != null)
			{
				// Make sure this analysis is marked as user-approved (green check mark)
				Cache.LangProject.DefaultUserAgent.SetEvaluation(newWa, Opinions.approves);
			}
		}
示例#15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="word"></param>
        /// <param name="analysis">the new analysis Gloss. If multiple glosses, returns the last one created.</param>
        private static void UpgradeToWordGloss(Word word, ref IAnalysis analysis)
        {
            FdoCache cache        = analysis.Cache;
            var      tsStrFactory = cache.ServiceLocator.GetInstance <ITsStrFactory>();
            var      wsFact       = cache.WritingSystemFactory;

            if (s_importOptions.AnalysesLevel == ImportAnalysesLevel.WordGloss)
            {
                // test for adding multiple glosses in the same language. If so, create separate analyses with separate glosses.
                bool fHasMultipleGlossesInSameLanguage = false;
                var  dictMapLangToGloss = new Dictionary <string, string>();
                foreach (var wordGlossItem in word.Items.Select(i => i).Where(i => i.type == "gls"))
                {
                    string gloss;
                    if (!dictMapLangToGloss.TryGetValue(wordGlossItem.lang, out gloss))
                    {
                        dictMapLangToGloss.Add(wordGlossItem.lang, wordGlossItem.Value);
                        continue;
                    }
                    if (wordGlossItem.Value == gloss)
                    {
                        continue;
                    }
                    fHasMultipleGlossesInSameLanguage = true;
                    break;
                }

                AnalysisTree analysisTree = null;
                foreach (var wordGlossItem in word.Items.Select(i => i).Where(i => i.type == "gls"))
                {
                    if (wordGlossItem == null)
                    {
                        continue;
                    }
                    if (wordGlossItem.analysisStatusSpecified &&
                        wordGlossItem.analysisStatus != analysisStatusTypes.humanApproved)
                    {
                        continue;
                    }
                    // first make sure that an existing gloss does not already exist. (i.e. don't add duplicate glosses)
                    int       wsNewGloss  = GetWsEngine(wsFact, wordGlossItem.lang).Handle;
                    ITsString newGlossTss = tsStrFactory.MakeString(wordGlossItem.Value,
                                                                    wsNewGloss);
                    var       wfiWord       = analysis.Wordform;
                    bool      hasGlosses    = wfiWord.AnalysesOC.Any(wfia => wfia.MeaningsOC.Any());
                    IWfiGloss matchingGloss = null;
                    if (hasGlosses)
                    {
                        foreach (var wfa in wfiWord.AnalysesOC)
                        {
                            matchingGloss = wfa.MeaningsOC.FirstOrDefault(wfg => wfg.Form.get_String(wsNewGloss).Equals(newGlossTss));
                            if (matchingGloss != null)
                            {
                                break;
                            }
                        }
                    }

                    if (matchingGloss != null)
                    {
                        analysis = matchingGloss;
                    }
                    else
                    {
                        // TODO: merge with analysis having same morpheme breakdown (or at least the same stem)

                        if (analysisTree == null || dictMapLangToGloss.Count == 1 || fHasMultipleGlossesInSameLanguage)
                        {
                            // create a new WfiAnalysis to store a new gloss
                            analysisTree = WordAnalysisOrGlossServices.CreateNewAnalysisTreeGloss(wfiWord);
                        }
                        else
                        {
                            // reuse the same analysisTree for setting a gloss alternative
                        }
                        analysisTree.Gloss.Form.set_String(wsNewGloss, wordGlossItem.Value);
                        // Make sure this analysis is marked as user-approved (green check mark)
                        cache.LangProject.DefaultUserAgent.SetEvaluation(analysisTree.WfiAnalysis, Opinions.approves);
                        // Create a morpheme form that matches the wordform.
                        var morphemeBundle = cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>().Create();
                        var wordItem       = word.Items.Select(i => i).Where(i => i.type == "txt").First();
                        int wsWord         = GetWsEngine(wsFact, wordItem.lang).Handle;
                        analysisTree.WfiAnalysis.MorphBundlesOS.Add(morphemeBundle);
                        morphemeBundle.Form.set_String(wsWord, wordItem.Value);

                        analysis = analysisTree.Gloss;
                    }
                }
            }
        }
		private void SaveAnalysisForAnnotation(AnalysisOccurrence occurrence, AnalysisTree newAnalysisTree)
		{
			Debug.Assert(occurrence != null);
			// Record the old wordform before we alter InstanceOf.
			IWfiWordform oldWf = occurrence.Analysis.Wordform;

			var wfToTryDeleting = occurrence.Analysis as IWfiWordform;

			// This is the property that each 'in context' object has that points at one of the WfiX classes as the
			// analysis of the word.
			occurrence.Analysis = newAnalysisTree.Analysis;

			// In case the wordform we point at has a form that doesn't match, we may need to set up an overidden form for the annotation.
			IWfiWordform targetWordform = newAnalysisTree.Wordform;
			if (targetWordform != null)
			{
				TryCacheRealWordForm(occurrence);
			}

			// It's possible if the new analysis is a different case form that the old wordform is now
			// unattested and should be removed.
			if (wfToTryDeleting != null && wfToTryDeleting != occurrence.Analysis.Wordform)
				wfToTryDeleting.DeleteIfSpurious();
		}
示例#17
0
 internal MockSandbox()
 {
     CurrentAnalysisTree = new AnalysisTree();
     NewAnalysisTree     = new AnalysisTree();
 }
		public void SkipNewGuessedWordGloss()
		{
			var wsf = Cache.WritingSystemFactory;
			const string xml = "<document><interlinear-text>" +
				"<paragraphs><paragraph><phrases><phrase><words>" +
					"<word>" +
						"<item type='txt' lang='en'>supercalifragilisticexpialidocious</item>" +
						"<item type='gls' lang='pt' analysisStatus='guessByHumanApproved'>absurdo</item>" +
					"</word>" +
				"</words></phrase></phrases></paragraph></paragraphs></interlinear-text></document>";

			var li = new BIRDFormatImportTests.LLIMergeExtension(Cache, null, null);
			FDO.IText importedText = null;
			var options = CreateImportInterlinearOptions(xml);
			li.ImportInterlinear(options, ref importedText);
			using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator())
			{
				firstEntry.MoveNext();
				var imported = firstEntry.Current;
				Assert.IsNotNull(imported);
				var para = imported.ContentsOA.ParagraphsOS[0] as IStTxtPara;
				Assert.IsNotNull(para);
				Assert.That(para.Analyses.Count(), Is.EqualTo(1));
				Assert.That(para.Analyses.First().Wordform.Form.get_String(wsf.get_Engine("en").Handle).Text,
					Is.EqualTo("supercalifragilisticexpialidocious"));
				var at = new AnalysisTree(para.Analyses.First());
				Assert.IsNull(at.Gloss, "Analysis should not be WfiGloss");
				// assert that nothing else was created
				Assert.That(Cache.ServiceLocator.GetInstance<IWfiGlossRepository>().Count, Is.EqualTo(0));
				Assert.That(Cache.ServiceLocator.GetInstance<IWfiAnalysisRepository>().Count, Is.EqualTo(0));
				Assert.That(Cache.ServiceLocator.GetInstance<IWfiWordformRepository>().Count, Is.EqualTo(1));
			}
		}
示例#19
0
		public SandboxBase()
		{
			SubscribeToRootSiteEventHandlerEvents();
			InitializeComponent();
			CurrentAnalysisTree = new AnalysisTree();
			// Tab should move between the piles inside the focus box!  See LT-9228.
			AcceptsTab = true;
		}
示例#20
0
		public virtual void SelectOccurrence(AnalysisOccurrence selected)
		{
			SelectedOccurrence = selected;
			InitialAnalysis = new AnalysisTree();
			if (SelectedOccurrence != null)
			{
				if (Cache == null)
					Cache = SelectedOccurrence.Analysis.Cache;
				InitialAnalysis.Analysis = SelectedOccurrence.Analysis;
			}
			ChangeOrCreateSandbox(selected);
		}
		internal MockSandbox()
		{
			CurrentAnalysisTree = new AnalysisTree();
			NewAnalysisTree = new AnalysisTree();
		}
示例#22
0
		public SandboxBase()
		{
			InitializeComponent();
			CurrentAnalysisTree = new AnalysisTree();
			// Tab should move between the piles inside the focus box!  See LT-9228.
			AcceptsTab = true;
		}