Ejemplo n.º 1
0
			virtual internal int SetDefaultWordGloss(int iSegment, int iSegForm, IWfiAnalysis actualWfiAnalysis, out string gloss)
			{
				gloss = "";
				// Get actual segment form.
				int hvoCbaActual = GetSegmentForm(iSegment, iSegForm);

				// Get the wordform for this segmentForm
				ITsString tssWordformBaseline = GetBaselineText(hvoCbaActual);

				// Find or create the current analysis of the actual annotation.
				if (actualWfiAnalysis == null)
				{
					actualWfiAnalysis = FindOrCreateWfiAnalysis(hvoCbaActual);
				}

				// Make a new gloss based upon the wordform and segmentForm path.
				IWfiGloss newGloss = new WfiGloss();
				// Add the gloss to the WfiAnalysis.
				actualWfiAnalysis.MeaningsOC.Add(newGloss);
				gloss = String.Format("{0}.{1}.{2}", iSegment, iSegForm, tssWordformBaseline.Text);
				newGloss.Form.SetAlternative(gloss, m_cache.DefaultAnalWs);
				int hvoGloss = newGloss.Hvo;

				// Set the new expected and actual analysis.
				SetInstanceOf(hvoCbaActual, hvoGloss, true);
				return hvoGloss;
			}
Ejemplo n.º 2
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.º 3
0
		public void PickLexGlossUsingExistingAnalysis()
		{
			int hvoCba0_0 = GetCbaHvo(0, 0, 0);
			m_sandbox.SwitchWord(hvoCba0_0, false);
			ILexEntry lexEntry1_Entry;
			ILexSense lexEntry1_Sense1;
			SetupLexEntryAndSense("xxxa", "0.0.xxxa", out lexEntry1_Entry, out lexEntry1_Sense1);
			ILexEntry lexEntry2_Entry;
			ILexSense lexEntry2_Sense1;
			SetupLexEntryAndSense("xxxa", "xxxa.AlternativeGloss", out lexEntry2_Entry, out lexEntry2_Sense1);
			// setup an existing analysis and gloss to match existing entry
			WfiWordform wf;
			IWfiMorphBundle morphBundle1 = SetupMorphBundleForEntry(hvoCba0_0, "0.0.xxxa", lexEntry1_Entry, lexEntry1_Sense1, out wf);
			IWfiMorphBundle morphBundle2 = SetupMorphBundleForEntry(hvoCba0_0, "xxxa.AlternativeGloss", lexEntry2_Entry, lexEntry2_Sense1, out wf);
			// load sandbox with a guess.
			m_sandbox.SwitchWord(hvoCba0_0, false);
			Assert.IsTrue(m_sandbox.UsingGuess);

			// mark the count of LexEntries
			int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count;

			// first select 'unknown' to clear the guess for the word gloss/pos
			m_sandbox.SelectItemInCombo(InterlinLineChoices.kflidWordGloss, 0, "Unknown");
			// confirm Sandbox is in the expected state.
			ITsString tssWordGlossInSandbox = m_sandbox.GetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs);
			Assert.AreEqual(null, tssWordGlossInSandbox.Text);
			int hvoPos = m_sandbox.GetRealHvoInSandbox(InterlinLineChoices.kflidWordPos, 0);
			Assert.AreEqual(0, hvoPos);

			// simulate selecting a lex gloss '0.0.xxxa'
			m_sandbox.SelectItemInCombo(InterlinLineChoices.kflidWordGloss, 0, lexEntry1_Sense1.Hvo);
			// confirm Sandbox is in the expected state.
			tssWordGlossInSandbox = m_sandbox.GetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs);
			Assert.AreEqual("0.0.xxxa", tssWordGlossInSandbox.Text);
			int hvoPos2 = m_sandbox.GetRealHvoInSandbox(InterlinLineChoices.kflidWordPos, 0);
			Assert.AreNotEqual(0, hvoPos2);

			// simulate selecting the other lex gloss 'xxxa.AlternativeGloss'
			m_sandbox.SelectItemInCombo(InterlinLineChoices.kflidWordGloss, 0, lexEntry2_Sense1.Hvo);
			// confirm Sandbox is in the expected state.
			tssWordGlossInSandbox = m_sandbox.GetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs);
			Assert.AreEqual("xxxa.AlternativeGloss", tssWordGlossInSandbox.Text);
			int hvoPos3 = m_sandbox.GetRealHvoInSandbox(InterlinLineChoices.kflidWordPos, 0);
			Assert.AreNotEqual(0, hvoPos3);

			// Next simulate picking an existing word gloss/pos by typing/selecting
			tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa");
			// set word pos, to first possibility (e.g. 'adjunct')
			int hvoSbWordPos = m_sandbox.SelectIndexInCombo(InterlinLineChoices.kflidWordPos, 0, 0);

			// confirm the analysis (using existing analysis and a LexSense)
			int hvoGloss = m_sandbox.ConfirmAnalysis();
			WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss);

			// make sure we didn't add entries or senses to the Lexicon.
			int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.Count;
			Assert.AreEqual(cEntriesOrig, cEntriesAfter);
			Assert.AreEqual(1, lexEntry1_Entry.SensesOS.Count);

			// make sure the sense matches the existing one.
			ILexSense sense = m_sandbox.GetLexSenseForWord();
			Assert.AreEqual(lexEntry1_Sense1.Hvo, sense.Hvo);
			// make sure the strings of the wfi gloss matches the strings of the lex gloss.
			ValidateSenseWithAnalysis(sense, wfiGloss, hvoSbWordPos);

			// confirm we have not created a new analysis and that it is monomorphemic
			IWfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;
			Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform.");
			Assert.AreEqual(hvoSbWordPos, wfiAnalysis.CategoryRAHvo);
			Assert.AreEqual(2, wf.AnalysesOC.Count);
			Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
			Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);
			IWfiAnalysis wfiAnalysis2 = (morphBundle2 as WfiMorphBundle).Owner as WfiAnalysis;
			Assert.AreEqual(1, wfiAnalysis2.MorphBundlesOS.Count);
			Assert.AreEqual(1, wfiAnalysis2.MeaningsOC.Count);

			// make sure the morph is linked to our lexicon sense, msa, and part of speech.
			IWfiMorphBundle wfiMorphBundle = wfiAnalysis.MorphBundlesOS[0];
			Assert.AreEqual(morphBundle1.Hvo, wfiMorphBundle.Hvo);
		}
Ejemplo n.º 4
0
		/// <summary>
		/// This goes through the collected list of WfiWordforms that do not have any analyses, and generates
		/// a guess for any whose forms exactly match a LexemeForm (or AlternateForm) of a stem/root entry.
		/// </summary>
		/// <param name="progress"></param>
		private void AddEntryGuesses(ProgressState progress)
		{
			if (m_rgEmptyWfis.Count == 0)
				return;
			MapEmptyWfToInfo();
			progress.Breath();
			if (m_mapEmptyWfInfo.Count == 0)
				return;
			foreach (EmptyWwfAnno ewa in m_rgEmptyWfis)
			{
				IWfiWordform ww = WfiWordform.CreateFromDBObject(m_cache, ewa.m_hvoWwf);
				EmptyWwfKey key = new EmptyWwfKey(ww.Hvo, ewa.m_ws);
				EmptyWwfInfo info;
				if (!m_mapEmptyWfInfo.TryGetValue(key, out info))
					continue;
				IWfiAnalysis wa;
				if (ww.AnalysesOC.Count == 0)
				{
					ITsString tssName = null;
					int wsVern = 0;
					ILexEntryRef ler = SandboxBase.GetVariantRef(m_cache, info.m_hvoEntry, true);
					int hvoEntryToDisplay = info.m_hvoEntry;
					if (ler != null)
					{
						ICmObject coRef = ler.ComponentLexemesRS[0];
						if (coRef is ILexSense)
							hvoEntryToDisplay = (coRef as ILexSense).EntryID;
						else
							hvoEntryToDisplay = coRef.Hvo;
						wsVern = StringUtils.GetWsAtOffset(m_tssPara, 0);
						tssName = InterlinDocChild.GetLexEntryTss(Cache, hvoEntryToDisplay, wsVern, ler);
						info.m_hvoSense = m_cache.MainCacheAccessor.get_VecItem(hvoEntryToDisplay,
							(int)LexEntry.LexEntryTags.kflidSenses, 0);
						info.m_hvoMsa = m_cache.MainCacheAccessor.get_ObjectProp(info.m_hvoSense,
							(int)LexSense.LexSenseTags.kflidMorphoSyntaxAnalysis);
						int clidMsa = m_cache.GetClassOfObject(info.m_hvoMsa);
						if (info.m_hvoPOS == 0)
						{
							info.m_hvoPOS = m_cache.MainCacheAccessor.get_ObjectProp(info.m_hvoMsa,
								(int)MoStemMsa.MoStemMsaTags.kflidPartOfSpeech);
						}
					}
					wa = new WfiAnalysis();
					ww.AnalysesOC.Add(wa);
					wa.CategoryRAHvo = info.m_hvoPOS;
					WfiGloss wg = new WfiGloss();
					wa.MeaningsOC.Add(wg);
					// Not all entries have senses.
					if (info.m_hvoSense != 0)
					{
						MultiUnicodeAccessor muaGloss = new MultiUnicodeAccessor(m_cache, info.m_hvoSense,	/* ls.Id */
							(int)LexSense.LexSenseTags.kflidGloss, "LexSense_Gloss");
						wg.Form.MergeAlternatives(muaGloss);
					}
					WfiMorphBundle wmb = new WfiMorphBundle();
					wa.MorphBundlesOS.Append(wmb);
					wmb.MorphRAHvo = info.m_hvoForm;
					if (tssName != null && wsVern != 0)
						wmb.Form.SetAlternative(tssName, wsVern);
					wmb.MsaRAHvo = info.m_hvoMsa;
					wmb.SenseRAHvo = info.m_hvoSense;

					// Now, set up an approved "Computer" evaluation of this generated analysis
					wa.SetAgentOpinion(m_cache.LangProject.DefaultComputerAgent, Opinions.approves);
				}
				else
				{
					// The same unanalyzed word may occur twice in a paragraph...
					wa = ww.AnalysesOC.ToArray()[0];
					Debug.Assert(ww.AnalysesOC.Count == 1);
					Debug.Assert(wa.CategoryRAHvo == info.m_hvoPOS);
					Debug.Assert(wa.MorphBundlesOS.Count == 1);
					Debug.Assert(wa.MorphBundlesOS[0].MorphRAHvo == info.m_hvoForm);
					Debug.Assert(wa.MorphBundlesOS[0].MsaRAHvo == info.m_hvoMsa);
					Debug.Assert(wa.MorphBundlesOS[0].SenseRAHvo == info.m_hvoSense);
				}
			}
			progress.Breath();
		}
Ejemplo n.º 5
0
		public void NewGlossExistingLexEntryAllomorphNewLexSense()
		{
			int hvoCba0_0 = GetCbaHvo(0, 0, 0);
			m_sandbox.SwitchWord(hvoCba0_0, false);
			string formLexEntry = "xxxab";
			ITsString tssLexEntryForm = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs);
			string formAllomorph = "xxxa";
			ITsString tssAllomorphForm = StringUtils.MakeTss(formAllomorph, Cache.DefaultVernWs);

			// first create an entry with a matching allomorph that doesn't match 'verb' POS we will be selecting in the sandbox
			ILexEntry lexEntry_NounPos;
			ILexSense lexSense_NounPos;
			SetupLexEntryAndSense("xxxab", "0.0.xxxab_NounPos", "noun", out lexEntry_NounPos, out lexSense_NounPos);
			IMoStemAllomorph allomorph0 = lexEntry_NounPos.AlternateFormsOS.Append(new MoStemAllomorph()) as IMoStemAllomorph;
			allomorph0.Form.SetAlternativeTss(tssAllomorphForm);

			// now create the entry we want to match, that has a 'verb' POS.
			ILexEntry lexEntry1_Entry;
			ILexSense lexEntry1_Sense1;
			SetupLexEntryAndSense("xxxab", "0.0.xxxab_VerbPos", "verb", out lexEntry1_Entry, out lexEntry1_Sense1);
			IMoStemAllomorph allomorph = lexEntry1_Entry.AlternateFormsOS.Append(new MoStemAllomorph()) as IMoStemAllomorph;
			allomorph.Form.SetAlternativeTss(tssAllomorphForm);

			// mark the count of LexEntries
			int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count;

			// add a new word gloss
			ITsString tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa");
			int hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0);
			WfiWordform wf = new WfiWordform(Cache, hvoWf);
			// set word pos to verb
			int hvoSbWordPos = m_sandbox.GetComboItemHvo(InterlinLineChoices.kflidWordPos, 0, "transitive verb");
			m_sandbox.SelectItemInCombo(InterlinLineChoices.kflidWordPos, 0, hvoSbWordPos);

			// confirm the analysis (making a real analysis and a LexSense)
			int hvoGloss = m_sandbox.ConfirmAnalysis();
			WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss);

			// make sure we didn't add entries to the Lexicon.
			int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.Count;
			Assert.AreEqual(cEntriesOrig, cEntriesAfter);

			// confirm we have only one analysis and that it is monomorphemic
			WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;
			Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform.");
			Assert.AreEqual(1, wf.AnalysesOC.Count);
			Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
			Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);

			// make sure the strings of the wfi gloss matches the strings of the lex gloss.
			ValidateSenseWithAnalysis(m_sandbox.GetLexSenseForWord(), wfiGloss, hvoSbWordPos, true, allomorph);
		}
Ejemplo n.º 6
0
		public void PickLexGlossCreatingNewAnalysis()
		{
			int hvoCba0_0 = GetCbaHvo(0, 0, 0);
			m_sandbox.SwitchWord(hvoCba0_0, false);
			ILexEntry lexEntry1_Entry;
			ILexSense lexEntry1_Sense1;
			SetupLexEntryAndSense("xxxa", "0.0.xxxa", out lexEntry1_Entry, out lexEntry1_Sense1);

			// mark the count of LexEntries
			int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count;

			// add a new word gloss
			ITsString tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa");
			int hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0);
			WfiWordform wf = new WfiWordform(Cache, hvoWf);
			// set word pos, to first possibility (e.g. 'adjunct')
			int hvoSbWordPos = m_sandbox.SelectIndexInCombo(InterlinLineChoices.kflidWordPos, 0, 0);

			// confirm the analysis (making a real analysis and a LexSense)
			int hvoGloss = m_sandbox.ConfirmAnalysis();
			WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss);

			// make sure we didn't add entries or senses to the Lexicon.
			int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.Count;
			Assert.AreEqual(cEntriesOrig, cEntriesAfter);
			Assert.AreEqual(1, lexEntry1_Entry.SensesOS.Count);

			// make sure the sense matches the existing one.
			ILexSense sense = m_sandbox.GetLexSenseForWord();
			Assert.AreEqual(lexEntry1_Sense1.Hvo, sense.Hvo);
			// make sure the morph is linked to our lexicon sense, msa, and part of speech.
			ValidateSenseWithAnalysis(sense, wfiGloss, hvoSbWordPos);

			// confirm we have created a new analysis and that it is monomorphemic
			WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;
			Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform.");
			Assert.AreEqual(1, wf.AnalysesOC.Count);
			Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
			Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);
		}
Ejemplo n.º 7
0
		private void ValidateSenseWithAnalysis(ILexSense sense, WfiGloss wfiGloss, int hvoSbWordPos, bool fMatchMainPossibility, IMoStemAllomorph allomorph)
		{
			WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;
			CompareTss(sense.Gloss.GetAlternativeTss(Cache.DefaultAnalWs),
				wfiGloss.Form.GetAlternativeTss(Cache.DefaultAnalWs));

			// make sure the morph is linked to the lexicon sense, msa, and part of speech.
			IWfiMorphBundle morphBundle = wfiAnalysis.MorphBundlesOS[0];
			Assert.AreEqual(sense.Hvo, morphBundle.SenseRAHvo);
			Assert.AreEqual(sense.MorphoSyntaxAnalysisRAHvo, morphBundle.MsaRAHvo);
			if (!fMatchMainPossibility)
			{
				// expect exact possibility
				Assert.AreEqual(hvoSbWordPos, (sense.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRAHvo);
			}
			else
			{
				IPartOfSpeech posTarget = PartOfSpeech.CreateFromDBObject(Cache, hvoSbWordPos);
				Assert.AreEqual(posTarget.MainPossibility.Hvo, (sense.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRA.MainPossibility.Hvo);
			}
			Assert.AreEqual(allomorph.Hvo, morphBundle.MorphRAHvo);
			Assert.AreEqual(hvoSbWordPos, wfiAnalysis.CategoryRAHvo);
		}
Ejemplo n.º 8
0
		public void NewGlossExistingLexEntryNewLexSense()
		{
			int hvoCba0_0 = GetCbaHvo(0, 0, 0);
			m_sandbox.SwitchWord(hvoCba0_0, false);
			string formLexEntry = "xxxa";
			ITsString tssLexEntryForm = StringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs);
			int clsidForm;
			ILexEntry lexEntry1_Entry = LexEntry.CreateEntry(Cache,
				MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm,
				"xxxa.existingsense1", null);
			ILexSense lexEntry1_Sense1 = lexEntry1_Entry.SensesOS[0];

			// mark the count of LexEntries
			int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count;

			// add a new word gloss
			ITsString tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa");
			int hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0);
			WfiWordform wf = new WfiWordform(Cache, hvoWf);
			// set word pos, to first possibility (e.g. 'adjunct')
			int hvoSbWordPos = m_sandbox.SelectIndexInCombo(InterlinLineChoices.kflidWordPos, 0, 0);

			// confirm the analysis (making a real analysis and a LexSense)
			int hvoGloss = m_sandbox.ConfirmAnalysis();
			WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss);

			// make sure we didn't add entries to the Lexicon.
			int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.Count;
			Assert.AreEqual(cEntriesOrig, cEntriesAfter);

			// confirm we have only one analysis and that it is monomorphemic
			WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;
			Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform.");
			Assert.AreEqual(1, wf.AnalysesOC.Count);
			Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
			Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);

			// make sure the strings of the wfi gloss matches the strings of the lex gloss.
			ValidateSenseWithAnalysis(m_sandbox.GetLexSenseForWord(), wfiGloss, hvoSbWordPos);
		}
Ejemplo n.º 9
0
		private void ValidateSenseWithAnalysis(ILexSense sense, WfiGloss wfiGloss, int hvoSbWordPos)
		{
			ValidateSenseWithAnalysis(sense, wfiGloss, hvoSbWordPos, false, sense.Entry.LexemeFormOA as IMoStemAllomorph);
		}
Ejemplo n.º 10
0
		public void NewGlossNewLexEntryNewLexSense()
		{
			// load sandbox for first 'xxxa'
			int hvoCba0_0 = GetCbaHvo(0, 0, 0);
			m_sandbox.SwitchWord(hvoCba0_0, false);

			// verify that the word gloss is empty
			ITsString tssEmpty = StringUtils.MakeTss("", Cache.DefaultAnalWs);
			ITsString tssWordGloss = m_sandbox.GetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs);
			CompareTss(tssEmpty, tssWordGloss);
			// add a new word gloss and confirm the analysis.
			ITsString tssWordGlossInSandbox = m_sandbox.SetTssInSandbox(InterlinLineChoices.kflidWordGloss, Cache.DefaultAnalWs, "0.0.xxxa");
			// mark the count of LexEntries
			int cEntriesOrig = Cache.LangProject.LexDbOA.EntriesOC.Count;
			// verify no analyses exist for this wordform;
			int hvoWf = WfiWordform.GetWfiWordformFromInstanceOf(Cache, hvoCba0_0);
			WfiWordform wf = new WfiWordform(Cache, hvoWf);
			Assert.AreEqual(0, wf.AnalysesOC.Count);

			// set word pos, to first possibility (e.g. 'adjunct')
			int hvoSbWordPos = m_sandbox.SelectIndexInCombo(InterlinLineChoices.kflidWordPos, 0, 0);
			Assert.IsFalse(hvoSbWordPos == 0);	 // select nonzero pos

			// confirm the analysis (making a real analysis and a LexSense)
			int hvoGloss = m_sandbox.ConfirmAnalysis();

			WfiGloss wfiGloss = new WfiGloss(Cache, hvoGloss);
			CompareTss(tssWordGlossInSandbox, wfiGloss.Form.GetAlternativeTss(Cache.DefaultAnalWs));
			// confirm we have only one analysis and that it is monomorphemic
			WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;
			Assert.AreEqual(wf.Hvo, wfiAnalysis.OwnerHVO, "Expected confirmed analysis to be owned by the original wordform.");
			Assert.AreEqual(1, wf.AnalysesOC.Count);
			Assert.AreEqual(1, wfiAnalysis.MorphBundlesOS.Count);
			Assert.AreEqual(1, wfiAnalysis.MeaningsOC.Count);

			// make sure the strings of the wfi gloss matches the strings of the lex gloss.
			ValidateSenseWithAnalysis(m_sandbox.GetLexSenseForWord(), wfiGloss, hvoSbWordPos);

			// make sure a new entry is in the Lexicon.
			int cEntriesAfter = Cache.LangProject.LexDbOA.EntriesOC.Count;
			Assert.AreEqual(cEntriesOrig + 1, cEntriesAfter);
		}
Ejemplo n.º 11
0
		private WfiAnalysis Make2BundleAnalysis(string form1, string form2, string gloss1, string gloss2)
		{
			WfiAnalysis result;
			ILexEntry entry1 = MakeEntry(form1, gloss1);
			ILexEntry entry2 = MakeEntry(form2, gloss2);

			result = new WfiAnalysis();
			m_wfAxx.AnalysesOC.Add(result);
			IWfiMorphBundle bundle = result.MorphBundlesOS.Append(new WfiMorphBundle());
			bundle.MorphRA = entry1.LexemeFormOA;
			bundle.SenseRA = entry1.SensesOS[0];
			bundle = result.MorphBundlesOS.Append(new WfiMorphBundle());
			bundle.MorphRA = entry2.LexemeFormOA;
			bundle.SenseRA = entry2.SensesOS[0];

			WfiGloss gloss = new WfiGloss();
			result.MeaningsOC.Add(gloss);
			gloss.Form.AnalysisDefaultWritingSystem = gloss1 + "." + gloss2;
			result.SetAgentOpinion(m_fdoCache.LangProject.DefaultUserAgent, Opinions.approves);

			m_cAnalyses++;

			return result;
		}
Ejemplo n.º 12
0
		/// <summary>
		/// Make (two) monomorphemic analyses on our favorite wordform, connected to two entries, one with two glosses.
		/// </summary>
		private void MakeMonoAnalyses()
		{
			string formLexEntry = "axx";
			ITsString tssLexEntryForm = Cache.MakeVernTss(formLexEntry);
			int clsidForm;
			ILexEntry entry = LexEntry.CreateEntry(Cache,
					MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm,
					"axe", null);
			ILexSense senseAxe = entry.SensesOS[0];
			IMoForm form = entry.LexemeFormOA;

			m_wfaAxe = new WfiAnalysis();
			m_wfAxx.AnalysesOC.Add(m_wfaAxe);
			IWfiMorphBundle bundle = m_wfaAxe.MorphBundlesOS.Append(new WfiMorphBundle());
			bundle.MorphRA = form;
			bundle.SenseRA = senseAxe;

			m_wgAxe = new WfiGloss();
			m_wfaAxe.MeaningsOC.Add(m_wgAxe);
			m_wgAxe.Form.AnalysisDefaultWritingSystem = "axe";

			m_wgChopper = new WfiGloss();
			m_wfaAxe.MeaningsOC.Add(m_wgChopper);
			m_wgChopper.Form.AnalysisDefaultWritingSystem = "chopper";
			m_wfaAxe.SetAgentOpinion(m_fdoCache.LangProject.DefaultUserAgent, Opinions.approves);

			ILexEntry entryCut = LexEntry.CreateEntry(Cache,
					MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm,
					"cut", null);
			m_wfaCut = new WfiAnalysis();
			m_wfAxx.AnalysesOC.Add(m_wfaCut);
			bundle = m_wfaCut.MorphBundlesOS.Append(new WfiMorphBundle());
			bundle.MorphRA = entryCut.LexemeFormOA;
			bundle.SenseRA = entryCut.SensesOS[0];

			m_wgCut = new WfiGloss();
			m_wfaCut.MeaningsOC.Add(m_wgCut);
			m_wgCut.Form.AnalysisDefaultWritingSystem = "cut";
			m_wfaCut.SetAgentOpinion(m_fdoCache.LangProject.DefaultUserAgent, Opinions.approves);

			m_cAnalyses += 2;
		}
Ejemplo n.º 13
0
		// Make some sort of wfics for the text of the specified paragraph. Assumes no double spaces!
		// Caches results and does not repeat on same para
		internal int[] MakeAnnotations(StTxtPara para)
		{
			int[] previous;
			if (m_annotations.TryGetValue(para.Hvo, out previous))
				return previous;
			string contents = para.Contents.Text;
			string[] words = contents.Split(new char[] { ' ', '.' });
			int ich = 0;
			List<int> results = new List<int>();
			ICmAnnotationDefn WficType = CmAnnotationDefn.Twfic(Cache);
			foreach (string word in words)
			{
				if (word == "")
				{
					ich++;
					continue;
				}
				WfiWordform wordform = new WfiWordform();
				Cache.LangProject.WordformInventoryOA.WordformsOC.Add(wordform);
				wordform.Form.SetAlternative(word, Cache.DefaultVernWs);
				// JohnT: This should ideally use CmBaseAnnotation.CreateUnownedCba. But most or all uses of this
				// method are memory-only tests, and that method requires a database.
				CmBaseAnnotation cba = new CmBaseAnnotation();
				Cache.LangProject.AnnotationsOC.Add(cba);
				cba.BeginOffset = ich;
				ich += word.Length;
				cba.EndOffset = ich;
				ich++; // past space or dot
				cba.BeginObjectRA = para;
				cba.AnnotationTypeRA = WficType;
				//cba.AnnotationTypeRA = ?? can we get CmAnnotationDefn.Twfic(Cache) with a non-database cache?
				WfiAnalysis analysis = new WfiAnalysis();
				wordform.AnalysesOC.Add(analysis);
				WfiGloss gloss = new WfiGloss();
				analysis.MeaningsOC.Add(gloss);
				gloss.Form.SetAlternative(word + "Gloss" + ich, Cache.DefaultAnalWs);
				cba.InstanceOfRA = gloss;
				results.Add(cba.Hvo);

			}
			int[] result = results.ToArray();
			m_annotations[para.Hvo] = result;
			return result;
		}