Ejemplo n.º 1
0
			/// <summary>
			/// Return the segment range in terms of the segment indexes of the BeginObject segment property of the given hvoCba.
			/// </summary>
			/// <param name="cache"></param>
			/// <param name="hvoCba"></param>
			/// <param name="iBeginSegment">zero-based index into segments</param>
			/// <param name="iEndSegment">zero-based into segments</param>
			/// <returns></returns>
			static public bool TryGetSegmentRange(FdoCache cache, int hvoCba,
				out int iBeginSegment, out int iEndSegment)
			{
				iBeginSegment = -1;
				iEndSegment = -1;
				int[] segments = null;
				// if it's a twfic type, then use twfic info, otherwise find a segment range.
				ICmBaseAnnotation cba = CmBaseAnnotation.CreateFromDBObject(cache, hvoCba);
				int hvoPara = cba.BeginObjectRAHvo;
				IVwVirtualHandler vh;
				// first try to get the segments from our Segments virtual handler
				// if that has not been loaded for the paragraph, try SegmentsIgnoreTwfics
				// to save time.
				if (cache.TryGetVirtualHandler(StTxtPara.SegmentsFlid(cache), out vh) &&
					(vh as BaseFDOPropertyVirtualHandler).IsPropInCache(cache.MainCacheAccessor, hvoPara, 0))
				{
					if (cba.AnnotationTypeRAHvo != 0)
					{
						StTxtPara.TwficInfo twficInfo = new StTxtPara.TwficInfo(cache, hvoCba);
						if (twficInfo.SegmentIndex >= 0)
						{
							iBeginSegment = twficInfo.SegmentIndex;		// return zero-based index.
						}
						else if (!cache.IsDummyObject(hvoCba))
						{
							int segIndexLogical;
							string sql = string.Format("exec GetSegmentIndex {0}, {1}", hvoCba, CmAnnotationDefn.TextSegment(cache).Hvo);
							DbOps.ReadOneIntFromCommand(cache, sql, null, out segIndexLogical);
							if (segIndexLogical > 0)
								iBeginSegment = segIndexLogical - 1;	 // subtract 1 to get a zero-based index.
						}
					}
					if (iBeginSegment < 0)
						segments = cache.GetVectorProperty(hvoPara, vh.Tag, true);
				}
				else if (cache.TryGetVirtualHandler(StTxtPara.SegmentsIgnoreTwficsFlid(cache), out vh))
				{
					segments = cache.GetVectorProperty(hvoPara, vh.Tag, true);
				}
				if (iBeginSegment < 0)
				{
					// this is annotation into a paragraph (but may not be a twfic or exist in SegForms).
					// if it's not a twfic, find a segment range.
					ISilDataAccess sda = cache.MainCacheAccessor;
					int ihvoSeg = 0;
					int cbaBeginOffset = cba.BeginOffset;
					int cbaEndOffset = cba.EndOffset;
					for (; ihvoSeg < segments.Length; ihvoSeg++)
					{
						int segEndOffset = sda.get_IntProp(segments[ihvoSeg], (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidEndOffset);
						if (segEndOffset <= cbaBeginOffset)
						{
							continue;
						}
						else if (iBeginSegment < 0)
						{
							iBeginSegment = ihvoSeg;
						}
						if (segEndOffset > cbaEndOffset)
						{
							iEndSegment = ihvoSeg;
							break; // we've passed our annotation's EndOffset, so the previous segment is the last one in range.
						}
					}
					// ihvoSeg should now be one index passed the segment in our range. this eguals the logical segment number.
					if (iBeginSegment >= 0 && iEndSegment == -1)
					{
						iEndSegment = ihvoSeg < segments.Length ? ihvoSeg - 1 : segments.Length - 1;
					}
				}
				return iBeginSegment >= 0;
			}
Ejemplo n.º 2
0
			internal UndoRedoApproveAnalysis(InterlinDocChild interlinDoc, int hvoOldAnnotation,
				int hvoNewAnnotation)
			{
				m_interlinDoc = interlinDoc;
				m_cache = interlinDoc.Cache;
				if (hvoOldAnnotation != 0)
				{
					m_oldTwficInfo = new StTxtPara.TwficInfo(m_cache, hvoOldAnnotation);
					m_oldTwficInfo.CaptureObjectInfo();
				}
				if (hvoNewAnnotation != 0)
					this.NewAnnotation = hvoNewAnnotation;
			}
Ejemplo n.º 3
0
		/// <summary>
		/// Move the sandbox to the annotation hvoAnnotation, currently analyzed as hvoAnalysis
		/// (which may be a WfiWordform, WfiAnalysis, or WfiGloss).
		/// </summary>
		/// <param name="hvoAnnotation"></param>
		/// <param name="hvoAnalysis"></param>
		/// <param name="fSaveGuess">if true, saves guesses; if false, skips guesses but still saves edits.</param>
		/// <param name="fMakeDefaultSelection">true to make the default selection within the
		/// new sandbox.</param>
		public virtual void TriggerAnnotationSelected(int hvoAnnotation, int hvoAnalysis,
			bool fSaveGuess, bool fMakeDefaultSelection)
		{
			// This can happen, though it is rare...see LT-8193.
			if (hvoAnnotation == 0)
				return;
			StTxtPara.TwficInfo twficInfo = new StTxtPara.TwficInfo(Cache, hvoAnnotation);
			if (!twficInfo.IsObjectValid())
			{
				this.MessageBoxMasterRefresh();
				return;
			}
			if (Cache.IsDummyObject(hvoAnnotation))
			{
				// convert this to a real object.
				using (SuppressSubTasks supressActionHandler = new SuppressSubTasks(Cache, true))
				{
					int hvoAnnDummy = hvoAnnotation;
					CmBaseAnnotation realAnn = CmObject.ConvertDummyToReal(Cache, hvoAnnotation) as CmBaseAnnotation;
					hvoAnnotation = realAnn.Hvo;
					// re-cache items important to this view, without which some things like guesses may not appear
					// until after a refresh.
					TryCacheRealWordForm(hvoAnnotation);
					TryCacheLowercasedForm(hvoAnnotation);
				}
			}
			//if (hvoAnnotation != m_hvoAnnotation)
			//{
			TryHideFocusBox();
			Sandbox sandbox = ChangeOrCreateSandbox(hvoAnnotation, ref hvoAnalysis, fSaveGuess);
			FocusBox.InterlinWordControl = sandbox;
			if (!Controls.Contains(FocusBox))
				Controls.Add(FocusBox); // Makes it real and may give it a root box.
			SetSandboxSize();
			int hvoOldAnnotation = m_hvoAnnotation;
			HvoAnnotation = hvoAnnotation;
			m_hvoAnalysis = hvoAnalysis;
			SimulateReplaceAnnotation(hvoOldAnnotation);
			SimulateReplaceAnnotation(m_hvoAnnotation);
			MoveFocusBoxIntoPlace();
			// Now it is the right size and place we can show it.
			TryShowFocusBox();
			sandbox.Focus();
			CheckForFreeOrLitAnnotations(MakeSandboxSel());
			if (m_fCanAddFreeTrans)
			{
				// add a free translation for this segment,
				// but don't change the selection from the sandbox.
				AddFreeTrans(false);
			}
			if (fMakeDefaultSelection)
				FocusBox.InterlinWordControl.MakeDefaultSelection();
			//}
			if (AnnnotationSelected != null)
				AnnnotationSelected(this, new AnnotationSelectedArgs(hvoAnnotation, hvoAnalysis));
		}
Ejemplo n.º 4
0
		internal bool CurrentParaIsValid()
		{
			if (ForEditing == false)
				return true;	// not tracking a current annotation.
			if (HvoAnnotation == 0)
				return false;
			StTxtPara.TwficInfo currentTwficInfo = new StTxtPara.TwficInfo(Cache, HvoAnnotation);
			if (!currentTwficInfo.IsObjectValid())
				return false;
			// go through the current paragraph and validate its segments and twfics.
			StTxtPara para = currentTwficInfo.Object.BeginObjectRA as StTxtPara;

			IVwVirtualHandler vh;
			if (Cache.TryGetVirtualHandler(StTxtPara.SegmentsFlid(Cache), out vh))
			{
				BaseVirtualHandler bvh = vh as BaseVirtualHandler;
				if (!bvh.IsPropInCache(Cache.MainCacheAccessor, para.Hvo, 0))
					return false;
			}
			int twficType = CmAnnotationDefn.Twfic(Cache).Hvo;
			foreach (int hvoSegment in para.Segments)
			{
				if (!Cache.IsValidObject(hvoSegment))
					return false;
				foreach (int hvoSegform in para.SegmentForms(hvoSegment))
				{
					// kflidAnnotationType
					int hvoAnnType = Cache.GetObjProperty(hvoSegform, (int)CmBaseAnnotation.CmAnnotationTags.kflidAnnotationType);
					if (hvoAnnType == twficType)
					{
						// do extra checking on twfics.
						StTxtPara.TwficInfo twficInfo = new StTxtPara.TwficInfo(Cache, hvoSegform);
						if (!twficInfo.IsObjectValid())
							return false;
					}
					else if (!Cache.IsValidObject(hvoSegform))
					{
						return false;
					}
				}
			}
			return true;
		}
Ejemplo n.º 5
0
		internal bool CurrentAnnotationIsValid()
		{
			if (ForEditing == false)
				return true;	// not tracking a current annotation.
			if (HvoAnnotation == 0)
				return false;
			StTxtPara.TwficInfo twficInfo = new StTxtPara.TwficInfo(Cache, HvoAnnotation);
			return twficInfo.IsObjectValid();
		}
Ejemplo n.º 6
0
		/// <summary>
		/// NOTE: This can destroy any current selection, so remember to save and restore the selection as needed
		/// </summary>
		/// <param name="wficCollection"></param>
		protected virtual void UpdateAffectedBundles(Set<int> wficCollection)
		{
			foreach (int hvoWfic in wficCollection)
			{
				StTxtPara.TwficInfo ti = new StTxtPara.TwficInfo(Cache, hvoWfic);
				if (ti.SegmentIndex > -1)
					Cache.PropChanged(ti.SegmentHvo, m_vc.ktagSegmentForms, ti.SegmentIndex, 1, 1);
			}
		}
Ejemplo n.º 7
0
		public void LT7202_CrashInWordsAfterEditingBaselineText()
		{
			// Switch to Texts
			m_window.ActivateTool("interlinearEdit");
			RecordClerk clerk = m_window.ActiveClerk;
			int hvoFirstSelectedText = clerk.CurrentObject.Hvo;

			// switch to baseline tab.
			m_window.InvokeCommand("CmdInsertText");
			int hvoNewText = clerk.CurrentObject.Hvo;
			Assert.AreNotEqual(hvoFirstSelectedText, hvoNewText, "clerk current object should have changed after inserting new text.");
			// should be the text in the active clerk.
			StText stText = clerk.CurrentObject as StText;
			// Assert in new text.
			using (new UndoRedoTaskHelper(Cache, "ConcordanceControlTests - LT7202", "ConcordanceControlTests - LT7202"))
			{
				// verify we are in a blank text.
				Assert.AreEqual(null, (stText.ParagraphsOS[0] as StTxtPara).Contents.Text, "new text should be empty");
				// paste in a new paragraph
				ITsStrFactory tsf = TsStrFactoryClass.Create();
				(stText.ParagraphsOS[0] as StTxtPara).Contents.UnderlyingTsString = tsf.MakeString("aVVV boyVVV", Cache.DefaultVernWs);
			}
			// switch to InterlinearTab.
			InterlinMaster interlinMaster = m_window.FindControl("InterlinMaster") as InterlinMaster;
			TabControl interlinTabs = interlinMaster.Controls.Find("m_tabCtrl", false)[0] as TabControl;
			interlinTabs.SelectedIndex = (int)InterlinMaster.TabPageSelection.Interlinearizer;
			InterlinDocChild idc = interlinMaster.Controls.Find("m_idcPane", true)[0] as InterlinDocChild;
			Assert.IsTrue(idc.HvoAnnotation != 0, "Expected to have selected nonzero annotation");
			StTxtPara.TwficInfo currentTwficInfo = new StTxtPara.TwficInfo(Cache, idc.HvoAnnotation);
			Assert.IsTrue(currentTwficInfo.IsObjectValid() &&
				currentTwficInfo.Object.InstanceOfRA.ClassID == WfiWordform.kClassId,
				"Expected to have selected a wfiwordform annotation");
			Assert.AreEqual("aVVV", (currentTwficInfo.Object.InstanceOfRA as WfiWordform).Form.VernacularDefaultWritingSystem,
				"Expected to have selected annotation for 'aVVV'");
			// switch to wordListConcordance
			m_window.ActivateTool("wordListConcordance");
			// validate we haven't invalidated the "aVVV" wordform or its annotation (yet)
			Assert.IsTrue(currentTwficInfo.IsObjectValid() &&
				currentTwficInfo.Object.InstanceOfRA.ClassID == WfiWordform.kClassId &&
				currentTwficInfo.Object.IsValidObject(),
				"Expected to have a valid wfiwordform");
			// jump to the "aVVV" wordform.
			clerk = m_window.ActiveClerk;
			clerk.JumpToRecord(currentTwficInfo.Object.InstanceOfRAHvo);
			m_window.ProcessPendingItems();
			// validate we jumped to the right wordform.
			Assert.AreEqual("aVVV", (clerk.CurrentObject as WfiWordform).Form.VernacularDefaultWritingSystem,
				"Expected to have selected wordform 'aVVV'");
			// verify our OccurrencesOfWordform clerk sync'd properly.
			RecordClerk occurrencesClerk = RecordClerk.FindClerk(Mediator, "OccurrencesOfSelectedWordform");
			Assert.AreEqual(clerk.CurrentObject.Hvo, occurrencesClerk.OwningObject.Hvo,
				"OccurrencesOfSelectedWordform should be sync'd to the current object of the active clerk.");
			Assert.AreEqual(1, occurrencesClerk.ListSize);
			Assert.IsTrue(occurrencesClerk.CurrentObject != null);
			currentTwficInfo = new StTxtPara.TwficInfo(Cache, occurrencesClerk.CurrentObject.Hvo);
			Assert.IsTrue(currentTwficInfo.IsObjectValid() &&
				currentTwficInfo.Object.InstanceOfRA.ClassID == WfiWordform.kClassId,
				"Expected to have selected a wfiwordform annotation");
			Assert.AreEqual("aVVV", (currentTwficInfo.Object.InstanceOfRA as WfiWordform).Form.VernacularDefaultWritingSystem,
				"Expected to have selected annotation for 'aVVV'");

			interlinMaster = m_window.FindControl("InterlinMaster") as InterlinMaster;
			// switch to InterlinearTab
			interlinTabs = interlinMaster.Controls.Find("m_tabCtrl", false)[0] as TabControl;
			interlinTabs.SelectedIndex = (int)InterlinMaster.TabPageSelection.Interlinearizer;
			idc = interlinMaster.Controls.Find("m_idcPane", true)[0] as InterlinDocChild;
			// Verify we've selected the annotation for 'aVVV'
			currentTwficInfo = new StTxtPara.TwficInfo(Cache, idc.HvoAnnotation);
			Assert.IsTrue(currentTwficInfo.IsObjectValid() &&
				currentTwficInfo.Object.InstanceOfRA.ClassID == WfiWordform.kClassId,
				"Expected to have selected a wfiwordform annotation");
			Assert.AreEqual("aVVV", (currentTwficInfo.Object.InstanceOfRA as WfiWordform).Form.VernacularDefaultWritingSystem,
				"Expected to have selected annotation for 'aVVV'");

			// switch back to interlinearEdit
			m_window.ActivateTool("interlinearEdit");
			clerk = m_window.ActiveClerk;
			interlinMaster = m_window.FindControl("InterlinMaster") as InterlinMaster;
			interlinTabs = interlinMaster.Controls.Find("m_tabCtrl", false)[0] as TabControl;
			interlinTabs.SelectedIndex = (int)InterlinMaster.TabPageSelection.RawText;
			using (new UndoRedoTaskHelper(Cache, "ConcordanceControlTests - LT7202", "ConcordanceControlTests - LT7202"))
			{
				// remove the first word
				ITsStrFactory tsf = TsStrFactoryClass.Create();
				(stText.ParagraphsOS[0] as StTxtPara).Contents.UnderlyingTsString = tsf.MakeString("boyVVV", Cache.DefaultVernWs);
			}
			// parse the text again
			interlinTabs.SelectedIndex = (int)InterlinMaster.TabPageSelection.Interlinearizer;
			idc = interlinMaster.Controls.Find("m_idcPane", true)[0] as InterlinDocChild;
			currentTwficInfo = new StTxtPara.TwficInfo(Cache, idc.HvoAnnotation);
			Assert.IsTrue(currentTwficInfo.IsObjectValid() &&
				currentTwficInfo.Object.InstanceOfRA.ClassID == WfiWordform.kClassId,
				"Expected to have selected a wfiwordform annotation");
			Assert.AreEqual("boyVVV", (currentTwficInfo.Object.InstanceOfRA as WfiWordform).Form.VernacularDefaultWritingSystem,
				"Expected to have selected annotation for 'boyVVV'");
			// switch back to Word List Concordance
			// this is where it was crashing.
			m_window.ActivateTool("wordListConcordance");
			// validate we're still on the 'aVVV' wordform.
			clerk = m_window.ActiveClerk;
			Assert.AreEqual("aVVV", (clerk.CurrentObject as WfiWordform).Form.VernacularDefaultWritingSystem,
				"Expected to have selected wordform 'aVVV'");
			occurrencesClerk = RecordClerk.FindClerk(Mediator, "OccurrencesOfSelectedWordform");
			Assert.AreEqual(clerk.CurrentObject.Hvo, occurrencesClerk.OwningObject.Hvo,
				"OccurrencesOfSelectedWordform should be sync'd to the current object of the active clerk.");
			// should have cleared our occurrences list for this wordform.
			Assert.AreEqual(0, occurrencesClerk.ListSize, "Should have cleared the OccurrencesOfSelectedWordform for 'aVVV'");
		}
Ejemplo n.º 8
0
		public void FindExampleSentences()
		{
			// Make some analyses linked to the same LexSense.
			ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara);
			ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb);
			// Create a new lexical entry and sense.
			int clsidForm;
			string formLexEntry = "xnihimbilira";
			ITsString tssLexEntryForm = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs);
			ILexEntry xnihimbilira_Entry = LexEntry.CreateEntry(Cache,
				MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm,
				"xnihimbilira.sense1", null);

			ILexSense xnihimbilira_Sense1 = xnihimbilira_Entry.SensesOS[0];
			ILexSense xnihimbilira_Sense2 = LexSense.CreateSense(xnihimbilira_Entry, null, "xnihimbilira.sense2");
			//<!--xxxpus xxxyalola xxxnihimbilira. xxxnihimbilira xxxpus xxxyalola. xxxhesyla xxxnihimbilira.-->
			ArrayList moForms = new ArrayList();
			moForms.Add("xx");
			moForms.Add(xnihimbilira_Entry.LexemeFormOA);
			// 1. Establish first analysis with Sense1
			IWfiAnalysis wfiAnalysis1 = tapb.BreakIntoMorphs(1, 0, moForms);
			tapb.SetMorphSense(1, 0, 1, xnihimbilira_Sense1);
			List<int> instancesInTwfics_Sense1 = (xnihimbilira_Sense1 as LexSense).InstancesInTwfics;
			List<int> instancesInTwfics_Sense2 = (xnihimbilira_Sense2 as LexSense).InstancesInTwfics;
			Assert.AreEqual(1, instancesInTwfics_Sense1.Count,
				String.Format("Unexpected number of instances of sense '{0}'", xnihimbilira_Sense1.Gloss.AnalysisDefaultWritingSystem));
			Assert.AreEqual(0, instancesInTwfics_Sense2.Count,
				String.Format("Unexpected number of instances of sense '{0}'", xnihimbilira_Sense2.Gloss.AnalysisDefaultWritingSystem));
			StTxtPara.TwficInfo infoCba1_0 = new StTxtPara.TwficInfo(Cache, instancesInTwfics_Sense1[0]);
			Assert.AreEqual(pb.ActualParagraph.Hvo, infoCba1_0.Object.BeginObjectRAHvo);
			Assert.AreEqual(1, infoCba1_0.SegmentIndex,
				String.Format("Unexpected index of segment '{0}'", infoCba1_0.SegmentHvo));

			WfiAnalysis waCba1_0 = infoCba1_0.Object.InstanceOfRA as WfiAnalysis;
			Assert.IsNotNull(waCba1_0,
				String.Format("Unexpected class({0}) of InstanceOf({1}) for cba0.", infoCba1_0.Object.InstanceOfRA.ClassID, infoCba1_0.Object.InstanceOfRAHvo));
			Assert.AreEqual(xnihimbilira_Sense1.Hvo, waCba1_0.MorphBundlesOS[1].SenseRAHvo);

			// get the segment information for the twfics.
			List<int> segments_Sense1 = StTxtPara.TwficSegments(Cache, instancesInTwfics_Sense1);
			Assert.AreEqual(1, segments_Sense1.Count, "Unexpected number of senses for twfics.");
			Assert.AreEqual(infoCba1_0.SegmentHvo, segments_Sense1[0], "Unexpected segment hvo.");

			// 2. Establish word gloss on the existing analysis.
			string wordGloss1;
			tapb.SetDefaultWordGloss(2, 1, wfiAnalysis1, out wordGloss1);
			instancesInTwfics_Sense1 = (xnihimbilira_Sense1 as LexSense).InstancesInTwfics;
			Assert.AreEqual(2, instancesInTwfics_Sense1.Count,
				String.Format("Unexpected number of instances of sense '{0}'", xnihimbilira_Sense1.Gloss.AnalysisDefaultWritingSystem));

			infoCba1_0 = new StTxtPara.TwficInfo(Cache, instancesInTwfics_Sense1[0]);
			Assert.AreEqual(pb.ActualParagraph.Hvo, infoCba1_0.Object.BeginObjectRAHvo);
			Assert.AreEqual(1, infoCba1_0.SegmentIndex,
				String.Format("Unexpected index of segment '{0}'", infoCba1_0.SegmentHvo));

			StTxtPara.TwficInfo infoCba2_1 = new StTxtPara.TwficInfo(Cache, instancesInTwfics_Sense1[1]);
			Assert.AreEqual(pb.ActualParagraph.Hvo, infoCba2_1.Object.BeginObjectRAHvo);
			Assert.AreEqual(2, infoCba2_1.SegmentIndex,
				String.Format("Unexpected index of segment '{0}'", infoCba2_1.SegmentHvo));

			waCba1_0 = infoCba1_0.Object.InstanceOfRA as WfiAnalysis;
			Assert.IsNotNull(waCba1_0,
				String.Format("Unexpected class({0}) of InstanceOf({1}) for cba0.", infoCba1_0.Object.InstanceOfRA.ClassID, infoCba1_0.Object.InstanceOfRAHvo));
			Assert.AreEqual(xnihimbilira_Sense1.Hvo, waCba1_0.MorphBundlesOS[1].SenseRAHvo);

			WfiGloss wgCba2_1 = infoCba2_1.Object.InstanceOfRA as WfiGloss;
			Assert.IsNotNull(wgCba2_1,
				String.Format("Unexpected class({0}) of InstanceOf({1}) for cba1.", infoCba2_1.Object.InstanceOfRA.ClassID, infoCba2_1.Object.InstanceOfRAHvo));
			WfiAnalysis waCba2_1 = WfiAnalysis.CreateFromDBObject(Cache, wgCba2_1.OwnerHVO) as WfiAnalysis;
			Assert.AreEqual(xnihimbilira_Sense1.Hvo, waCba2_1.MorphBundlesOS[1].SenseRAHvo);

			segments_Sense1 = StTxtPara.TwficSegments(Cache, instancesInTwfics_Sense1);
			Assert.AreEqual(2, segments_Sense1.Count, "Unexpected number of senses for twfics.");
			Assert.AreEqual(infoCba1_0.SegmentHvo, segments_Sense1[0], "Unexpected segment hvo.");
			Assert.AreEqual(infoCba2_1.SegmentHvo, segments_Sense1[1], "Unexpected segment hvo.");

			// 3. establish a new analysis with Sense1.
			IWfiAnalysis wfiAnalysis2 = tapb.BreakIntoMorphs(0, 2, moForms); // xxxnihimbilira (first occurrence)
			tapb.SetMorphSense(0, 2, 1, xnihimbilira_Sense1);
			instancesInTwfics_Sense1 = (xnihimbilira_Sense1 as LexSense).InstancesInTwfics;
			Assert.AreEqual(3, instancesInTwfics_Sense1.Count,
				String.Format("Unexpected number of instances of sense '{0}'", xnihimbilira_Sense1.Gloss.AnalysisDefaultWritingSystem));

			StTxtPara.TwficInfo infoCba0_2 = new StTxtPara.TwficInfo(Cache, instancesInTwfics_Sense1[0]);
			Assert.AreEqual(pb.ActualParagraph.Hvo, infoCba0_2.Object.BeginObjectRAHvo);
			Assert.AreEqual(0, infoCba0_2.SegmentIndex,
				String.Format("Unexpected index of segment '{0}'", infoCba0_2.SegmentHvo));

			WfiAnalysis waCba0_2 = infoCba0_2.Object.InstanceOfRA as WfiAnalysis;
			Assert.IsNotNull(waCba0_2,
				String.Format("Unexpected class({0}) of InstanceOf({1}) for cba0.", infoCba0_2.Object.InstanceOfRA.ClassID, infoCba0_2.Object.InstanceOfRAHvo));
			Assert.AreEqual(xnihimbilira_Sense1.Hvo, waCba0_2.MorphBundlesOS[1].SenseRAHvo);

			segments_Sense1 = StTxtPara.TwficSegments(Cache, instancesInTwfics_Sense1);
			Assert.AreEqual(3, segments_Sense1.Count, "Unexpected number of senses for twfics.");
			Assert.AreEqual(infoCba0_2.SegmentHvo, segments_Sense1[0], "Unexpected segment hvo.");
			Assert.AreEqual(infoCba1_0.SegmentHvo, segments_Sense1[1], "Unexpected segment hvo.");
			Assert.AreEqual(infoCba2_1.SegmentHvo, segments_Sense1[2], "Unexpected segment hvo.");

			// 4. change an existing sense to sense2.
			tapb.SetMorphSense(0, 2, 1, xnihimbilira_Sense2);
			instancesInTwfics_Sense1 = (xnihimbilira_Sense1 as LexSense).InstancesInTwfics;
			Assert.AreEqual(2, instancesInTwfics_Sense1.Count,
				String.Format("Unexpected number of instances of sense '{0}'", xnihimbilira_Sense1.Gloss.AnalysisDefaultWritingSystem));
			instancesInTwfics_Sense2 = (xnihimbilira_Sense2 as LexSense).InstancesInTwfics;
			Assert.AreEqual(1, instancesInTwfics_Sense2.Count,
				String.Format("Unexpected number of instances of sense '{0}'", xnihimbilira_Sense2.Gloss.AnalysisDefaultWritingSystem));

			infoCba0_2 = new StTxtPara.TwficInfo(Cache, instancesInTwfics_Sense2[0]);
			Assert.AreEqual(pb.ActualParagraph.Hvo, infoCba0_2.Object.BeginObjectRAHvo);
			Assert.AreEqual(0, infoCba0_2.SegmentIndex,
				String.Format("Unexpected index of segment '{0}'", infoCba0_2.SegmentHvo));

			waCba0_2 = infoCba0_2.Object.InstanceOfRA as WfiAnalysis;
			Assert.IsNotNull(waCba0_2,
				String.Format("Unexpected class({0}) of InstanceOf({1}) for cba0.", infoCba0_2.Object.InstanceOfRA.ClassID, infoCba0_2.Object.InstanceOfRAHvo));
			Assert.AreEqual(xnihimbilira_Sense2.Hvo, waCba0_2.MorphBundlesOS[1].SenseRAHvo);

			// do multiple occurrences of the same sense in the same segment.
			IWfiAnalysis wfiAnalysis3 = tapb.BreakIntoMorphs(0, 0, moForms); // break xxxpus into xx xnihimbilira (for fun).
			tapb.SetMorphSense(0, 0, 1, xnihimbilira_Sense2);
			instancesInTwfics_Sense2 = (xnihimbilira_Sense2 as LexSense).InstancesInTwfics;
			Assert.AreEqual(2, instancesInTwfics_Sense2.Count,
				String.Format("Unexpected number of instances of sense '{0}'", xnihimbilira_Sense2.Gloss.AnalysisDefaultWritingSystem));
			StTxtPara.TwficInfo infoCba0_0 = new StTxtPara.TwficInfo(Cache, instancesInTwfics_Sense2[0]);

			// reparse paragraph to convert all segments with real analyses to real ones.
			tapb.ReparseParagraph();
			infoCba0_0.ReloadInfo();
			infoCba0_2.ReloadInfo();
			infoCba1_0.ReloadInfo();
			infoCba2_1.ReloadInfo();

			List<int> segments_Sense2 = StTxtPara.TwficSegments(Cache, instancesInTwfics_Sense2);
			Assert.AreEqual(2, segments_Sense2.Count, "Unexpected number of senses for twfics.");
			Assert.AreEqual(infoCba0_0.SegmentHvo, segments_Sense2[0], "Unexpected segment hvo.");
			Assert.AreEqual(infoCba0_2.SegmentHvo, segments_Sense2[1], "Unexpected segment hvo.");

			// Load free form annotations for segments Sense 2.
			Set<int> analWsIds = new Set<int>(Cache.LangProject.AnalysisWssRC.HvoArray);
			StTxtPara.LoadSegmentFreeformAnnotationData(Cache, new Set<int>(segments_Sense2), analWsIds);
			int tagSegFF = StTxtPara.SegmentFreeformAnnotationsFlid(Cache);
			int[] segFFs = Cache.GetVectorProperty(infoCba0_0.SegmentHvo, tagSegFF, true);
			Assert.AreEqual(0, segFFs.Length, "Segment 0 should not have any freeform annotations.");
			StTxtPara.LoadSegmentFreeformAnnotationData(Cache, pb.ActualParagraph.Hvo, analWsIds);
			segFFs = Cache.GetVectorProperty(infoCba0_0.SegmentHvo, tagSegFF, true);
			Assert.AreEqual(0, segFFs.Length, "Segment 0 should not have any freeform annotations.");
			segFFs = Cache.GetVectorProperty(infoCba1_0.SegmentHvo, tagSegFF, true);
			Assert.AreEqual(0, segFFs.Length, "Segment 1 should not have any freeform annotations.");
			segFFs = Cache.GetVectorProperty(infoCba2_1.SegmentHvo, tagSegFF, true);
			Assert.AreEqual(0, segFFs.Length, "Segment 2 should not have any freeform annotations.");

			// Try adding some freeform translations
			int segDefn_literalTranslation = Cache.GetIdFromGuid(LangProject.kguidAnnLiteralTranslation);
			int segDefn_freeTranslation = Cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation);
			BaseFreeformAdder ffAdder = new BaseFreeformAdder(Cache);
			ICmIndirectAnnotation freeTrans0 = ffAdder.AddFreeformAnnotation(infoCba0_0.SegmentHvo, segDefn_freeTranslation);
			freeTrans0.Comment.SetAlternative("Segment0: Freeform translation.", Cache.DefaultAnalWs);
			ICmIndirectAnnotation literalTrans0 = ffAdder.AddFreeformAnnotation(infoCba0_0.SegmentHvo, segDefn_literalTranslation);
			literalTrans0.Comment.SetAlternative("Segment0: Literal translation.", Cache.DefaultAnalWs);

			// see if we can load this into the cache.
			StTxtPara.LoadSegmentFreeformAnnotationData(Cache, new Set<int>(segments_Sense2), analWsIds);
			segFFs = Cache.GetVectorProperty(infoCba0_0.SegmentHvo, tagSegFF, true);
			Assert.AreEqual(2, segFFs.Length, "Segment 0 should have freeform annotations.");
			Assert.AreEqual(segFFs[0], freeTrans0.Hvo, "Segment 0 Freeform translation id.");
			Assert.AreEqual(segFFs[1], literalTrans0.Hvo, "Segment 0 Literal translation id.");

			StTxtPara.LoadSegmentFreeformAnnotationData(Cache, pb.ActualParagraph.Hvo, analWsIds);
			segFFs = Cache.GetVectorProperty(infoCba0_0.SegmentHvo, tagSegFF, true);
			Assert.AreEqual(2, segFFs.Length, "Segment 0 should have freeform annotations.");
			Assert.AreEqual(segFFs[0], freeTrans0.Hvo, "Segment 0 Freeform translation id.");
			Assert.AreEqual(segFFs[1], literalTrans0.Hvo, "Segment 0 Literal translation id.");
			segFFs = Cache.GetVectorProperty(infoCba1_0.SegmentHvo, tagSegFF, true);
			Assert.AreEqual(0, segFFs.Length, "Segment 1 should not have any freeform annotations.");
			segFFs = Cache.GetVectorProperty(infoCba2_1.SegmentHvo, tagSegFF, true);
			Assert.AreEqual(0, segFFs.Length, "Segment 2 should not have any freeform annotations.");
		}
Ejemplo n.º 9
0
		private void ValidateGuesses(List<int> expectedGuesses, StTxtPara paraWithGuesses)
		{
			List<int> segsParaGuesses = paraWithGuesses.Segments;
			int iExpectedGuess = 0;
			foreach (int hvoSegParaGuesses in segsParaGuesses)
			{
				List<int> segFormsParaGuesses = paraWithGuesses.SegmentForms(hvoSegParaGuesses);
				Assert.AreEqual(expectedGuesses.Count, segFormsParaGuesses.Count);
				foreach (int hvoSegFormParaGuesses in segFormsParaGuesses)
				{
					int hvoGuessActual = 0;
					CmBaseAnnotation cba = new CmBaseAnnotation(Cache, hvoSegFormParaGuesses);
					if (cba.InstanceOfRAHvo != 0)
					{
						// should be a twfic so get it's guess.
						StTxtPara.TwficInfo cbaInfo = new StTxtPara.TwficInfo(Cache, cba.Hvo);
						hvoGuessActual = cbaInfo.GetGuess();
					}
					Assert.AreEqual(expectedGuesses[iExpectedGuess], hvoGuessActual, "Guess mismatch");
					iExpectedGuess++;
				}
			}
		}
Ejemplo n.º 10
0
		/// <summary>
		/// Breaks the given (phrase-wordform) annotation to its basic wordforms.
		/// </summary>
		/// <param name="hvoCbaPhrase"></param>
		/// <param name="hvoParasInView">the paragraphs in the view doing the break phrase operation</param>
		/// <returns>ids of the new wordforms</returns>
		public List<int> BreakPhraseAnnotation(int hvoCbaPhrase, int[] hvoParasInView)
		{
			List<int> segForms;
			ICmBaseAnnotation phraseAnnotation = CmBaseAnnotation.CreateFromDBObject(Cache, hvoCbaPhrase);
			int phraseBeginOffset = phraseAnnotation.BeginOffset;
			int phraseEndOffset = phraseAnnotation.EndOffset;
			segForms = CollectSegmentForms(phraseBeginOffset, phraseEndOffset, false);
			StTxtPara.TwficInfo phraseInfo = new StTxtPara.TwficInfo(Cache, hvoCbaPhrase);
			int iSegForm = phraseInfo.SegmentFormIndex;
			int hvoParaSeg = phraseInfo.SegmentHvo;
			IVwCacheDa cda = Cache.VwCacheDaAccessor;
			ISilDataAccess sda = Cache.MainCacheAccessor;
			// convert dummy segForms to real ones.
			// This conversion is currently important to do before we exit BreakPhraseAnnotation because if we try to
			// convert a dummy annotation that references a dummy wordform, that dummy wordform
			// may be removed from the WordformInventory by DeleteUnderlyingObject()->OnChangedWordformsOC below.
			List<int> realSegForms = new List<int>(segForms.Count);
			foreach (int hvoSegForm in segForms)
			{
				int hvoNewWordform;
				WfiWordform.TryGetWfiWordformFromInstanceOf(Cache, hvoSegForm, out hvoNewWordform);
				if (hvoNewWordform != 0)
				{
					// This allows it to be converted to real, by specifying its owner and owning flid.
					WfiWordform.AddDummyAnnotation(Cache, hvoNewWordform, hvoSegForm);
					ICmBaseAnnotation realSegForm = CmObject.ConvertDummyToReal(Cache, hvoSegForm) as ICmBaseAnnotation;
					realSegForms.Add(realSegForm.Hvo);
					WfiWordform newWordform = WfiWordform.CreateFromDBObject(Cache, hvoNewWordform) as WfiWordform;
					// now add this occurrence to the wordform.
					newWordform.TryAddOccurrence(realSegForm.Hvo);
				}
				else
				{
					realSegForms.Add(hvoSegForm); // punctuation does not need to be real.
				}
			}
			// insert new forms.
			CacheReplaceOneUndoAction cacheReplaceSegmentsFormsAction = new CacheReplaceOneUndoAction(Cache, hvoParaSeg,
				kflidSegmentForms, iSegForm, iSegForm, realSegForms.ToArray());
			cacheReplaceSegmentsFormsAction.DoIt();
			if (Cache.ActionHandlerAccessor != null)
			{
				Cache.ActionHandlerAccessor.AddAction(cacheReplaceSegmentsFormsAction);
			}
			// Get the phrase wordform form the phraseAnnotation.
			int hvoOldWordform = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCbaPhrase);
			// delete old annotation. (In the future, this may be orphaned so that it may be reused.)
			WfiWordform wffOld = WfiWordform.CreateFromDBObject(Cache, hvoOldWordform, false) as WfiWordform;
			phraseAnnotation.DeleteUnderlyingObject();
			// see if we can delete the phrase wordform from our wordinventory.
			Set<int> delObjIds;
			StTxtPara.TryDeleteWordforms(Cache, new int[] { wffOld.Hvo }, hvoParasInView, out delObjIds);
			return realSegForms;
		}
Ejemplo n.º 11
0
		public void NoAnalyses_SimpleEdits_MultipleWritingSystemsParagraph()
		{
			CheckDisposed();
			ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.MultipleWritingSystems);
			pb.ParseParagraph(true, true);
			// xxxpus xxes xxxnihimbilira. xxfr xxen xxxnihimbilira xxxpus xxde. xxkal xxkal xxxxhesyla xxxxhesyla.
			//	xxkal: German (de)		-- occurrence 0
			//	xxkal: Kalaba (xkal)	-- occurrence 1
			Dictionary<string, int> expectedOccurrences = pb.ExpectedWordformsAndOccurrences;
			WordformInventory wfi = Cache.LangProject.WordformInventoryOA as WordformInventory;
			CheckExpectedWordformsAndOccurrences(wfi, expectedOccurrences);
			// replace the german occurrence of "xxkal" with a xkal version.
			int hvoSeg2 = pb.ActualParagraph.Segments[2];
			int hvoSegForm2_0 = pb.ActualParagraph.SegmentForms(hvoSeg2)[0];
			StTxtPara.TwficInfo ti2_0 = new StTxtPara.TwficInfo(Cache, hvoSegForm2_0);
			int wsDe = StringUtils.GetWsAtOffset(pb.ActualParagraph.Contents.UnderlyingTsString, ti2_0.Object.BeginOffset);
			int wsVernDef = Cache.DefaultVernWs;
			Assert.AreNotEqual(wsVernDef, wsDe, "did not expect to have a default vern ws.");
			pb.ReplaceSegmentForm(2, 0, "xxkal", wsVernDef);
			expectedOccurrences.Remove("xxkal" + wsDe.ToString());
			expectedOccurrences["xxkal" + wsVernDef.ToString()] += 1;
			pb.RebuildParagraphContentFromAnnotations(true, true);
			CheckExpectedWordformsAndOccurrences(wfi, expectedOccurrences);
		}
Ejemplo n.º 12
0
		/// <summary>
		/// Set up the sandbox to display the specified analysis, hvoAnalysis, which might be a WfiWordform,
		/// WfiAnalysis, or WfiGloss.
		/// </summary>
		/// <param name="hvoAnnotation"></param>
		/// <param name="fValidateRealObject">validate whether annotation exists in the database</param>
		public void SwitchWord(int hvoAnnotation, bool fValidateRealObject)
		{
			CheckDisposed();
			if (fValidateRealObject && !Cache.IsRealObject(hvoAnnotation, CmBaseAnnotation.kClassId))
				throw new ArgumentException(String.Format("invalid hvoAnnotation {0}", hvoAnnotation));
			HvoAnnotation = hvoAnnotation;
			RawWordformWs = 0;
			StTxtPara.TwficInfo twficInfo = new StTxtPara.TwficInfo(Cache, hvoAnnotation);
			this.TreatAsSentenceInitial = twficInfo.IsFirstTwficInSegment;
			ReconstructForWordBundleAnalysis(twficInfo.Object.InstanceOfRAHvo);
		}
Ejemplo n.º 13
0
		public void MakeAndBreakPhraseAndKeepFocusBoxInPlace()
		{
			JumpToWord("wonderfulXXXzzzcounselor");
			int indexWordBeforeEdit = m_wordList.CurrentIndex;
			int hvoWordBeforeEdit = m_wordList.CurrentObject.Hvo;
			using (InterlinMasterHelper imh = new InterlinMasterHelper(this))
			{
				imh.SwitchTab(InterlinMaster.TabPageSelection.Interlinearizer);
				InterlinDocChild idc = imh.CurrentInterlinDoc;
				// paragraph1: XXXlocoZZZ, XXXsegmentZZZ?? ZZZamazingXXX wonderfulXXXzzzcounselor!!
				StTxtPara para1 = m_text1.ContentsOA.ParagraphsOS[1] as StTxtPara;
				int hvoAnnBeforeEdit = para1.SegmentForm(1, 0);
				StTxtPara.TwficInfo twficBeforeEdit1_0 = new StTxtPara.TwficInfo(Cache, hvoAnnBeforeEdit);
				twficBeforeEdit1_0.CaptureObjectInfo();
				// select a "ZZZamazingXXX" so we can make a phrase with "wonderfulXXXzzzcounselor"
				IStText stTextBeforeEdit = idc.RawStText;
				idc.SelectAnnotation(hvoAnnBeforeEdit);
				// XXXlocoZZZ, XXXsegmentZZZ?? [ZZZamazingXXX wonderfulXXXzzzcounselor]
				m_window.InvokeCommand("CmdMakePhrase");
				ValidateFocusBoxState(indexWordBeforeEdit, idc, twficBeforeEdit1_0, stTextBeforeEdit);
				StTxtPara.TwficInfo twficAfterMakePhrase1_0 = new StTxtPara.TwficInfo(Cache, idc.HvoAnnotation);
				twficAfterMakePhrase1_0.CaptureObjectInfo();
				m_window.InvokeCommand("CmdBreakPhrase");
				// worderfulXXXzzzcounselor will have been inserted back before the current index, so advance one
				ValidateFocusBoxState(indexWordBeforeEdit + 1, idc, twficAfterMakePhrase1_0, stTextBeforeEdit);
				StTxtPara.TwficInfo twficAfterBreakPhrase1_0 = new StTxtPara.TwficInfo(Cache, idc.HvoAnnotation);
				twficAfterBreakPhrase1_0.CaptureObjectInfo();
				idc.OnUndo(null);
				ValidateFocusBoxState(indexWordBeforeEdit, idc, twficAfterBreakPhrase1_0, stTextBeforeEdit);
			}
		}
Ejemplo n.º 14
0
		void SetupTexts()
		{
			// First make a regular text.
			using (new UndoRedoTaskHelper(Cache, "ConcordanceControlTests - SetupTexts()", "ConcordanceControlTests - SetupTexts()"))
			{
				m_text1 = Cache.LangProject.TextsOC.Add(new Text());
				m_text1.ContentsOA = new StText();
				StTxtPara para0 = new StTxtPara();
				StTxtPara para1 = new StTxtPara();
				m_text1.ContentsOA.ParagraphsOS.Append(para0);
				m_text1.ContentsOA.ParagraphsOS.Append(para1);
				ITsStrFactory tsf = TsStrFactoryClass.Create();
				//           1         2         3         4         5         6
				// 0123456789012345678901234567890123456789012345678901234567890123456789
				// XXXXsecrecyZZZ; XXXsentenceZZZ!!
				// XXXlocoZZZ, XXXsegmentZZZ?? ZZZamazingXXX wonderfulXXXzzzcounselor!!
				para0.Contents.UnderlyingTsString = tsf.MakeString("XXXXsecrecyZZZ; XXXsentenceZZZ!!", Cache.DefaultVernWs);
				para1.Contents.UnderlyingTsString = tsf.MakeString("XXXlocoZZZ, XXXsegmentZZZ?? ZZZamazingXXX wonderfulXXXzzzcounselor!!", Cache.DefaultVernWs);

				// add scripture
				m_newBook1 = new ScrBook();
				Cache.LangProject.TranslatedScriptureOA.ScriptureBooksOS.Append(m_newBook1);
				m_newBook1.TitleOA = new StText();
				m_newBook1.TitleOA.ParagraphsOS.Append(new StTxtPara());
				(m_newBook1.TitleOA.ParagraphsOS[0] as StTxtPara).Contents.UnderlyingTsString = tsf.MakeString("XXXnewBook1zzz.Title", Cache.DefaultVernWs);
				IScrSection newSection1_0 = m_newBook1.SectionsOS.Append(new ScrSection());
				newSection1_0.ContentOA = new StText();
				StTxtPara paraSection1_0 = new StTxtPara();
				(newSection1_0.ContentOA as StText).ParagraphsOS.Append(paraSection1_0);
				paraSection1_0.Contents.UnderlyingTsString = tsf.MakeString("ZZZnewBook1.Section0.Introduction1XXX", Cache.DefaultVernWs);
				IScrSection newSection1_1 = m_newBook1.SectionsOS.Append(new ScrSection());
				newSection1_1.ContentOA = new StText();
				StTxtPara paraSection1_1 = new StTxtPara();
				(newSection1_1.ContentOA as StText).ParagraphsOS.Append(paraSection1_1);
				paraSection1_1.Contents.UnderlyingTsString = tsf.MakeString("XXXnewBook1.Section1.1:1-1:20ZZZ", Cache.DefaultVernWs);
				// section.VerseRefEnd = book.CanonicalNum * 1000000 + 1 * 1000 + (introSection ? 0 : 1);
				newSection1_1.VerseRefEnd = 70 * 1000000 + 1 * 1000 + 1;


				// setup some basic analyses for the texts.
				string formLexEntry = "XXXlexEntry1";
				ITsString tssLexEntryForm = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs);
				int clsidForm;
				StringUtils.ReassignTss(ref tssLexEntryForm, StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs));
				ILexEntry lexEntry1_Entry = LexEntry.CreateEntry(Cache,
					MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm,
					"XXXlexEntry1.sense1", null);
				ILexSense lexEntry1_Sense1 = lexEntry1_Entry.SensesOS[0];
				ILexSense lexEntry1_Sense2 = LexSense.CreateSense(lexEntry1_Entry, null, "XXXlexEntry1.sense2");
				ParagraphAnnotator tapara0 = new ParagraphAnnotator(para0);
				ParagraphAnnotator tapara1 = new ParagraphAnnotator(para1);
				ParagraphAnnotator taSection1_0 = new ParagraphAnnotator(paraSection1_0);
				ParagraphAnnotator taSection1_1 = new ParagraphAnnotator(paraSection1_1);

				// currently setup mono-morphemic search
				ArrayList morphForms = new ArrayList();
				formLexEntry = "XXXXsecrecyZZZ";
				StringUtils.ReassignTss(ref tssLexEntryForm, StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs));
				ILexEntry lexEntry2_Entry = LexEntry.CreateEntry(Cache,
					MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm,
					"XXXlexEntry2.sense1", null);
				morphForms.Add(lexEntry2_Entry.LexemeFormOA);
				IWfiAnalysis wfiAnalysis = tapara0.BreakIntoMorphs(0, 0, morphForms);
				m_wfXXXXsecrecyZZZ = (wfiAnalysis as WfiAnalysis).Owner as IWfiWordform;
				ILexSense lexEntry2_Sense1 = lexEntry2_Entry.SensesOS[0];
				tapara0.SetMorphSense(0, 0, 0, lexEntry2_Sense1);

				formLexEntry = "XXXsegmentZZZ";
				StringUtils.ReassignTss(ref tssLexEntryForm, StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs));
				ILexEntry lexEntry3_Entry = LexEntry.CreateEntry(Cache,
					MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm,
					"XXXlexEntry3.sense1", null);
				morphForms[0] = lexEntry3_Entry.LexemeFormOA;
				tapara1.BreakIntoMorphs(0, 2, morphForms);
				ILexSense lexEntry3_Sense1 = lexEntry3_Entry.SensesOS[0];
				tapara1.SetMorphSense(0, 2, 0, lexEntry3_Sense1);

				formLexEntry = "ZZZamazingXXX";
				StringUtils.ReassignTss(ref tssLexEntryForm, StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs));
				ILexEntry lexEntry4_Entry = LexEntry.CreateEntry(Cache,
					MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm,
					"XXXlexEntry4.sense1", null);
				morphForms[0] = lexEntry4_Entry.LexemeFormOA;
				tapara1.BreakIntoMorphs(1, 0, morphForms);
				ILexSense lexEntry4_Sense1 = lexEntry4_Entry.SensesOS[0];
				tapara1.SetMorphSense(1, 0, 0, lexEntry4_Sense1);

				//XXXlocoZZZ
				morphForms[0] = "XXXlocoZZZ";
				tapara1.BreakIntoMorphs(0, 0, morphForms);
				tapara1.SetMorphSense(0, 0, 0, lexEntry1_Sense2);

				formLexEntry = paraSection1_0.Contents.Text;
				StringUtils.ReassignTss(ref tssLexEntryForm, StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs));
				ILexEntry lexEntry5_Entry = LexEntry.CreateEntry(Cache,
					MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm,
					"XXXlexEntry5.sense1", null);
				morphForms[0] = lexEntry5_Entry.LexemeFormOA;
				taSection1_0.BreakIntoMorphs(0, 0, morphForms);
				ILexSense lexEntry5_Sense1 = lexEntry5_Entry.SensesOS[0];
				taSection1_0.SetMorphSense(0, 0, 0, lexEntry5_Sense1);

				morphForms[0] = paraSection1_1.Contents.Text;
				taSection1_1.BreakIntoMorphs(0, 0, morphForms);		// won't match on LexEntry
				taSection1_1.SetMorphSense(0, 0, 0, lexEntry1_Sense2);	// will match on LexGloss

				string gloss;
				tapara0.SetDefaultWordGloss(0, 0, out gloss);
				tapara1.SetDefaultWordGloss(0, 2, out gloss);
				tapara1.SetDefaultWordGloss(1, 0, out gloss);
				taSection1_1.SetDefaultWordGloss(0, 0, out gloss);

				StTxtPara.TwficInfo infoCba0_0_0 = new StTxtPara.TwficInfo(Cache, tapara0.GetSegmentForm(0, 0));
				StTxtPara.TwficInfo infoCba1_0_2 = new StTxtPara.TwficInfo(Cache, tapara1.GetSegmentForm(0, 2));
				StTxtPara.TwficInfo infoCbaScr_0_0 = new StTxtPara.TwficInfo(Cache, taSection1_1.GetSegmentForm(0, 0));

				int segDefn_literalTranslation = Cache.GetIdFromGuid(LangProject.kguidAnnLiteralTranslation);
				int segDefn_freeTranslation = Cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation);
				int segDefn_note = Cache.GetIdFromGuid(LangProject.kguidAnnNote);
				BaseFreeformAdder ffAdder = new BaseFreeformAdder(Cache);
				ICmIndirectAnnotation freeTrans0 = ffAdder.AddFreeformAnnotation(infoCba0_0_0.SegmentHvo, segDefn_freeTranslation);
				freeTrans0.Comment.SetAlternative("Para0.Segment0: XXXFreeform translation.", Cache.DefaultAnalWs);
				ICmIndirectAnnotation literalTrans0 = ffAdder.AddFreeformAnnotation(infoCba0_0_0.SegmentHvo, segDefn_literalTranslation);
				literalTrans0.Comment.SetAlternative("Para0.Segment0: XXXLiteral translation.", Cache.DefaultAnalWs);
				ICmIndirectAnnotation note0 = ffAdder.AddFreeformAnnotation(infoCba0_0_0.SegmentHvo, segDefn_note);
				note0.Comment.SetAlternative("Para0.Segment0: XXXNote.", Cache.DefaultAnalWs);

				ICmIndirectAnnotation freeTrans1 = ffAdder.AddFreeformAnnotation(infoCba1_0_2.SegmentHvo, segDefn_freeTranslation);
				freeTrans1.Comment.SetAlternative("Para1.Segment0: XXXFreeform translation.", Cache.DefaultAnalWs);
				ICmIndirectAnnotation literalTrans1 = ffAdder.AddFreeformAnnotation(infoCba1_0_2.SegmentHvo, segDefn_literalTranslation);
				literalTrans1.Comment.SetAlternative("Para1.Segment0: XXXLiteral translation.", Cache.DefaultAnalWs);
				ICmIndirectAnnotation note1 = ffAdder.AddFreeformAnnotation(infoCba1_0_2.SegmentHvo, segDefn_note);
				note1.Comment.SetAlternative("Para1.Segment0: XXXNote.", Cache.DefaultAnalWs);

				// Scripture
				ICmIndirectAnnotation freeTransScr1 = ffAdder.AddFreeformAnnotation(infoCbaScr_0_0.SegmentHvo, segDefn_freeTranslation);
				freeTransScr1.Comment.SetAlternative("Scr1.Para0.Segment0: XXXFreeform translation.", Cache.DefaultAnalWs);
				ICmIndirectAnnotation literalTransScr1 = ffAdder.AddFreeformAnnotation(infoCbaScr_0_0.SegmentHvo, segDefn_literalTranslation);
				literalTransScr1.Comment.SetAlternative("Scr1.Para0.Segment0: XXXLiteral translation.", Cache.DefaultAnalWs);
				ICmIndirectAnnotation noteScr1 = ffAdder.AddFreeformAnnotation(infoCbaScr_0_0.SegmentHvo, segDefn_note);
				noteScr1.Comment.SetAlternative("Scr1.Para0.Segment0: XXXNote.", Cache.DefaultAnalWs);
			}
		}
Ejemplo n.º 15
0
			/// <summary>
			/// looks in the paragraph to find an annotation that matches the information
			/// captured in CaptureObjectInfo().
			/// </summary>
			/// <returns>0 if none found</returns>
			public int FindIdenticalTwfic()
			{
				if (IsCapturedObjectInfoValid())
					return Object.Hvo;
				// otherwise look through our paragraph annotations and see
				// if we can find one corresponding to the one we've saved.
				// Enhance: we could start with the offsets in the paragraph
				// and look for an equivalent segform independent of segment
				// boundaries.
				StTxtPara para = new StTxtPara(m_fdoCache, m_hvoPara);
				List<int> segments = para.Segments;
				if (m_iSegment < 0 || m_iSegment >= segments.Count)
					return 0;
				int hvoSegment = segments[m_iSegment];
				List<int> segforms = para.SegmentForms(hvoSegment);
				if (m_iSegmentForm < 0 || m_iSegmentForm >= segforms.Count)
					return 0;
				int hvoSegform = segforms[m_iSegmentForm];
				StTxtPara.TwficInfo twficInfo = new StTxtPara.TwficInfo(m_fdoCache, hvoSegform);
				if (this.IsIdenticalObjectInfo(twficInfo))
					return hvoSegform;
				else
					return 0;
			}
Ejemplo n.º 16
0
		private bool TryGetTwficLowercaseSentenceInitialForm(int hvoAnnotation, out int hvoWfiLower)
		{
			hvoWfiLower = 0;
			int ktagMatchingLowercaseForm = InterlinVc.MatchingLowercaseWordForm(Cache);
			if (Cache.MainCacheAccessor.get_IsPropInCache(hvoAnnotation, ktagMatchingLowercaseForm, (int)CellarModuleDefns.kcptReferenceAtom, 0))
				hvoWfiLower = Cache.GetObjProperty(hvoAnnotation, ktagMatchingLowercaseForm);
			else
			{
				StTxtPara.TwficInfo twficInfo = new StTxtPara.TwficInfo(m_fdoCache, hvoAnnotation);
				if (twficInfo.IsFirstTwficInSegment)
				{
					ITsString tssWfBaseline = StTxtPara.TssSubstring(twficInfo.Object);
					CpeTracker tracker = new CpeTracker(Cache.LanguageWritingSystemFactoryAccessor, tssWfBaseline);
					ILgCharacterPropertyEngine cpe = tracker.CharPropEngine(0);
					string sLower = cpe.ToLower(tssWfBaseline.Text);
					hvoWfiLower = Cache.LangProject.WordformInventoryOA.GetWordformId(sLower,
						StringUtils.GetWsAtOffset(tssWfBaseline, 0));
				}
			}
			return hvoWfiLower != 0;
		}
Ejemplo n.º 17
0
			protected override void ValidateSegForms(object expectedSegForm, object actualSegForm, string segFormContext)
			{
				string msg = "Mismatched {0} in {1}.";
				// Get the paragraph string corresponding to the annotation.
				ICmBaseAnnotation cbaExpected = CmBaseAnnotation.CreateFromDBObject(m_cache, (int)expectedSegForm);
				// first make sure we have a txt item.
				if (IsLineEnabled(InterlinLineChoices.kflidWord))
				{
					ITsString tssExpectedForm = m_para.Contents.UnderlyingTsString.GetSubstring(cbaExpected.BeginOffset, cbaExpected.EndOffset);
					string lang = "xkal";
					// Review: get WsLabel from tssExpectedForm.
					string actualForm = "";
					if (cbaExpected.AnnotationTypeRAHvo == TwficAnnotationType)
						actualForm = m_reader.GetItemInnerText(actualSegForm as XmlNode, "txt", lang);
					else if (cbaExpected.AnnotationTypeRAHvo == PunctuationAnnotationType)
						actualForm = m_reader.GetItemInnerText(actualSegForm as XmlNode, "punct", lang);
					Assert.AreEqual(tssExpectedForm.Text, actualForm,
							String.Format(msg, "word", segFormContext));
				}
				// if WordGloss is enabled, verify it.
				if (IsLineEnabled(InterlinLineChoices.kflidWordGloss))
				{
					string lang = "en";
					string actualWordGloss = m_reader.GetItemInnerText(actualSegForm as XmlNode, "gls", lang);
					if (cbaExpected.AnnotationTypeRAHvo == PunctuationAnnotationType)
					{
						// must be a punctuation (non-wfic)
						Assert.AreEqual("", actualWordGloss);
					}
					else
					{
						WfiGloss expectedGloss = null;
						int clsId = m_cache.GetClassOfObject(cbaExpected.InstanceOfRAHvo);
						if (clsId == WfiGloss.kclsidWfiGloss)
						{
							expectedGloss = new WfiGloss(m_cache, cbaExpected.InstanceOfRAHvo);
						}
						else if (clsId == WfiWordform.kclsidWfiWordform)
						{
							// should be a twfic so get its guess.
							StTxtPara.TwficInfo cbaInfo = new StTxtPara.TwficInfo(m_cache, cbaExpected.Hvo);
							int hvoExpectedGloss = cbaInfo.GetGuess();
							if (hvoExpectedGloss != 0)
								expectedGloss = new WfiGloss(m_cache, hvoExpectedGloss);
						}
						// TODO: There are cases for other classes (e.g. WfiAnalysis) but
						// the tests do not generate those right now, so we won't worry about them right now.
						if (expectedGloss != null)
							Assert.AreEqual(expectedGloss.Form.AnalysisDefaultWritingSystem, actualWordGloss);
						else
							Assert.AreEqual("", actualWordGloss);
					}
				}
				// validate morph bundle lines.
				if (IsLineEnabled(InterlinLineChoices.kflidMorphemes) ||
					IsLineEnabled(InterlinLineChoices.kflidLexEntries) ||
					IsLineEnabled(InterlinLineChoices.kflidLexGloss) ||
					IsLineEnabled(InterlinLineChoices.kflidLexPos))
				{
					// compare exported document to the LexEntries information in the WfiAnalysis
					int hvoWfiAnalysis = 0;
					if (cbaExpected.AnnotationTypeRAHvo != PunctuationAnnotationType)
						hvoWfiAnalysis = WfiAnalysis.GetWfiAnalysisFromInstanceOf(m_cache, cbaExpected.Hvo);
					List<XmlNode> morphNodes = m_reader.GetMorphNodes(actualSegForm as XmlNode);
					if (hvoWfiAnalysis == 0)
					{
						// make sure we don't have any morphs.
						Assert.IsEmpty(morphNodes);
					}
					else
					{
						IWfiAnalysis wfiAnalysis = WfiAnalysis.CreateFromDBObject(m_cache, hvoWfiAnalysis);
						foreach (WfiMorphBundle morphBundle in wfiAnalysis.MorphBundlesOS)
						{
							int iMorph = morphBundle.OwnOrd - 1;
							string morphContext = segFormContext + "/Morph(" + iMorph +")";
							XmlNode actualMorphNode = iMorph < morphNodes.Count ? morphNodes[iMorph] : null;
							if (actualMorphNode == null)
								Assert.Fail(String.Format(msg, "missing morph", morphContext));
							ITsString tssLexEntry = null;
							int hvoMorph = morphBundle.MorphRAHvo;
							if (hvoMorph != 0)
							{
								// first test the morph form
								if (IsLineEnabled(InterlinLineChoices.kflidMorphemes))
								{
									string actualMorphForm = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "txt", "xkal");
									Assert.AreEqual(morphBundle.MorphRA.Form.VernacularDefaultWritingSystem,
													actualMorphForm,
													String.Format(msg, "morph/txt", morphContext));
								}

								// next test the lex entry
								if (IsLineEnabled(InterlinLineChoices.kflidLexEntries))
								{
									string actualLexEntry = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "cf", "xkal");
									string actualHomograph = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "hn", "en");
									string actualVariantTypes = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "variantTypes", "en");
									tssLexEntry = InterlinDocChild.GetLexEntryTss(m_cache, morphBundle, m_cache.DefaultVernWs);
									Assert.AreEqual(tssLexEntry.Text, actualLexEntry + actualHomograph + actualVariantTypes,
													String.Format(msg, "morph/cf[hn|variantTypes]", morphContext));
								}

								if (IsLineEnabled(InterlinLineChoices.kflidLexGloss))
								{
									string actualLexGloss = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "gls", "en");
									string expectedGloss = "";
									if (morphBundle.SenseRA != null && morphBundle.SenseRA.Gloss != null)
										expectedGloss = morphBundle.SenseRA.Gloss.AnalysisDefaultWritingSystem;
									Assert.AreEqual(expectedGloss, actualLexGloss,
													String.Format(msg, "morph/gls", morphContext));
								}
								if (IsLineEnabled(InterlinLineChoices.kflidLexPos))
								{
									string actualLexMsa = m_reader.GetItemInnerText(actualMorphNode as XmlNode, "msa", "en");
									string expectedMsa = "";
									if (morphBundle.SenseRA != null && morphBundle.SenseRA.MorphoSyntaxAnalysisRA != null)
										expectedMsa = morphBundle.SenseRA.MorphoSyntaxAnalysisRA.InterlinearAbbr;
									Assert.AreEqual(expectedMsa, actualLexMsa,
										String.Format(msg, "morph/msa", morphContext));
								}
							}
						}
						Assert.AreEqual(wfiAnalysis.MorphBundlesOS.Count, morphNodes.Count);
					}

				}
			}
Ejemplo n.º 18
0
		private StText GetStTextOfCurrentAnnotation()
		{
			StTxtPara.TwficInfo twficInfo = new StTxtPara.TwficInfo(Cache, HvoAnnotation);
			StTxtPara para = twficInfo.Object.BeginObjectRA as StTxtPara;
			StText text = para.Owner as StText;
			return text;
		}
Ejemplo n.º 19
0
		/// <summary>
		/// Given a set of wfics, return the set of xfics that may be affected
		/// by tagging or undoing the applied tag (which may overlap other xfics).
		/// </summary>
		/// <param name="hvoWfics"></param>
		/// <returns></returns>
		private Set<int> GetAllXficsPossiblyAffectedByTagging(List<int> hvoWfics)
		{
			// This is overkill, but there are too many cases to handle during undo/redo
			// to cover with just CheckForOverlappingTags().
			// For now get all the xfics for the segments owning the given wfics
			// so we can make sure the display will be properly updated.
			Set<int> segments = new Set<int>();
			foreach (int hvoWfic in hvoWfics)
			{
				// first collect a list of parent segments.
				StTxtPara.TwficInfo ti = new StTxtPara.TwficInfo(Cache, hvoWfic);
				if (ti.SegmentHvo == 0)
					continue;
				segments.Add(ti.SegmentHvo);
			}
			// now get all the xfics for those segments
			Set<int> allPossiblyAffectedXfics = new Set<int>();
			allPossiblyAffectedXfics.AddRange((m_vc as InterlinTaggingVc).CollectXficsFromSegments(segments.ToArray()));
			return allPossiblyAffectedXfics;
		}
Ejemplo n.º 20
0
		//[Ignore("FWC-16 - this test causes NUnit to hang. Need to investigate further.")]
		public void MakeAndBreakPhrases()
		{
			using (InterlinMasterHelper imh = new InterlinMasterHelper(this))
			{
				// 1. Start with a search in the basic text.
				m_concordanceControl.SelectLineOption(ConcordanceControl.ConcordanceLines.kWord);
				m_concordanceControl.MatchCase = true;
				m_concordanceControl.SearchOption = MockConcordanceControl.ConcordanceSearchOption.Anywhere;
				m_concordanceControl.SearchText = "XXX";	// should get all our twfics.
				List<int> results = m_concordanceControl.Search(); // this should parse the paragraphs creating dummy twfics.
				m_window.ProcessPendingItems();
				Assert.AreEqual(6, results.Count);
				Assert.AreEqual(results.Count, m_concordanceControl.Clerk.ListSize);

				// jump to ZZZamazingXXX
				m_concordanceControl.Clerk.JumpToIndex(4);
				m_window.ProcessPendingItems();
				StTxtPara.TwficInfo currentTwficInfo = new StTxtPara.TwficInfo(Cache, m_concordanceControl.Clerk.CurrentObject.Hvo);
				WfiWordform wf = WfiWordform.CreateFromDBObject(Cache, currentTwficInfo.HvoWfiWordform) as WfiWordform;
				Assert.AreEqual("ZZZamazingXXX", wf.Form.VernacularDefaultWritingSystem);

				// switch to interlinear tab, and make sure we're selecting "ZZZamazingXXX"
				imh.SwitchTab(InterlinMaster.TabPageSelection.Interlinearizer);
				m_window.ProcessPendingItems();
				// nothing should have changed
				results = m_concordanceControl.Results(); // the merge should not have refreshed our list (yet)
				Assert.AreEqual(6, results.Count);
				Assert.AreEqual(results.Count, m_concordanceControl.Clerk.ListSize);

				currentTwficInfo = new StTxtPara.TwficInfo(Cache, imh.CurrentInterlinDoc.HvoAnnotation);
				wf = WfiWordform.CreateFromDBObject(Cache, currentTwficInfo.HvoWfiWordform) as WfiWordform;
				Assert.AreEqual("ZZZamazingXXX", wf.Form.VernacularDefaultWritingSystem);

				// 2. Make a basic phrase
				// XXXlocoZZZ, XXXsegmentZZZ?? [ZZZamazingXXX wonderfulXXXzzzcounselor]
				m_window.InvokeCommand("CmdMakePhrase");
				currentTwficInfo = new StTxtPara.TwficInfo(Cache, imh.CurrentInterlinDoc.HvoAnnotation);
				wf = WfiWordform.CreateFromDBObject(Cache, currentTwficInfo.HvoWfiWordform) as WfiWordform;
				Assert.AreEqual("ZZZamazingXXX wonderfulXXXzzzcounselor", wf.Form.VernacularDefaultWritingSystem);

				results = m_concordanceControl.Results(); // CmBaseAnnotation.DeleteUnderlyingObject() removed itself from our cache.
				Assert.AreEqual(6, m_concordanceControl.Clerk.ListSize); // but we haven't refreshed our list yet.
				results = m_concordanceControl.Search(); // manually get the new results
				m_window.ProcessPendingItems();
				Assert.AreEqual(5, results.Count);
				// now compare this result set against the number of items in our browse view.
				Assert.AreEqual(results.Count, m_concordanceControl.Clerk.ListSize, "Our browse view results should match our propery list size");

				// 3. Break the phrase
				// XXXlocoZZZ, XXXsegmentZZZ?? \ZZZamazingXXX\ \wonderfulXXXzzzcounselor\
				m_window.InvokeCommand("CmdBreakPhrase");
				currentTwficInfo = new StTxtPara.TwficInfo(Cache, imh.CurrentInterlinDoc.HvoAnnotation);
				wf = WfiWordform.CreateFromDBObject(Cache, currentTwficInfo.HvoWfiWordform) as WfiWordform;
				Assert.AreEqual("ZZZamazingXXX", wf.Form.VernacularDefaultWritingSystem);
				results = m_concordanceControl.Results(); // CmBaseAnnotation.DeleteUnderlyingObject() removed phrase from our cache.
				Assert.AreEqual(4, results.Count);
				results = m_concordanceControl.Search(); // the break should result in new search results.
				m_window.ProcessPendingItems();
				Assert.AreEqual(6, results.Count);
				// now compare this result set against the number of items in our browse view.
				Assert.AreEqual(results.Count, m_concordanceControl.Clerk.ListSize, "Our browse view results should match our propery list size");
			}
		}