Пример #1
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);
					}

				}
			}
Пример #2
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++;
				}
			}
		}