public void SparseAnalyses_NoEdits_SimpleSegmentParagraph() { // First set sparse analyses on wordforms that have multiple occurrences. ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); string gloss; IWfiGloss gloss_xxxyalola1_2 = tapb.SetDefaultWordGloss(1, 2, out gloss); IWfiGloss gloss_xxxnihimbilira2_1 = tapb.SetDefaultWordGloss(2, 1, out gloss); // now parse through the text and make sure our two glosses are maintained. pb.ParseParagraph(); Assert.AreEqual(gloss_xxxyalola1_2, tapb.GetAnalysis(1, 2)); Assert.AreEqual(gloss_xxxnihimbilira2_1, tapb.GetAnalysis(2, 1)); // validate the rest of the stuff. tapb.ValidateAnnotations(); }
public void SegmentInitialUppercaseWordMatchesLowercaseWordform() { // prepopulate lowercase Wordforms new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara).ParseParagraph(); // Build and parse paragraph var pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.MixedCases); var tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); // Verify WF's are reused across case iff appropriate: Assert.AreEqual( tapb.GetAnalysis(0, 0), tapb.GetAnalysis(1, 1), "Initial Xxxpus should have been interpreted as sentence case"); Assert.AreNotEqual(tapb.GetAnalysis(0, 1), tapb.GetAnalysis(1, 2), "Mid-sentence Xxxyalola should not match lowercase WF"); Assert.AreNotEqual(tapb.GetAnalysis(0, 2), tapb.GetAnalysis(1, 0), "Congratulations! You fixed it! Please Assert.AreEqual with this message: xxxnihimbilira should have been reused for segment initial."); Assert.AreNotEqual(tapb.GetAnalysis(0, 2), tapb.GetAnalysis(2, 1), "XXXNIHIMBILIRA should have been given its own all-caps WF"); }
public void SparseAnalyses_NoEdits_MixedCaseWordformsParagraph() { // First set sparse analyses on wordforms that have multiple occurrences. ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.MixedCases); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); // set the corresponding annotations to lowercase wordforms. IWfiWordform wf_xxxpus0_0 = tapb.SetAlternateCase("Xxxpus", 0, StringCaseStatus.allLower); IWfiWordform wf_xxxnihimbilira1_0 = tapb.SetAlternateCase("Xxxnihimbilira", 0, StringCaseStatus.allLower); IWfiWordform wf_xxxhesyla2_0 = tapb.SetAlternateCase("Xxxhesyla", 0, StringCaseStatus.allLower); IWfiWordform wf_xxxnihimbilira2_1 = tapb.SetAlternateCase("XXXNIHIMBILIRA", 0, StringCaseStatus.allLower); pb.ParseParagraph(); Assert.AreEqual(wf_xxxpus0_0, tapb.GetAnalysis(0, 0)); Assert.AreEqual(wf_xxxnihimbilira1_0, tapb.GetAnalysis(1, 0)); Assert.AreEqual(wf_xxxhesyla2_0, tapb.GetAnalysis(2, 0)); Assert.AreEqual(wf_xxxnihimbilira2_1, tapb.GetAnalysis(2, 1)); tapb.ValidateAnnotations(); }
public void SparseAnalyses_SimpleEdits_SimpleSegmentParagraph_DuplicateWordforms_AddWhitespace_LT5313() { // First set sparse analyses on wordforms that have multiple occurrences. ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara); pb.ParseParagraph(); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); string gloss; var gloss0_1 = tapb.SetDefaultWordGloss(0, 1, out gloss); // xxxyalola 1 var gloss1_1 = tapb.SetDefaultWordGloss(1, 1, out gloss); // xxxpus 2 var gloss2_1 = tapb.SetDefaultWordGloss(2, 1, out gloss); // xxxnihimbilira 3 tapb.ValidateAnnotations(); // precondition testing. // Append whitespace in the text, and see if the analyses still show up in the right place // (cf. LT-5313). pb.ReplaceTrailingWhitepace(0, 0, 1); pb.RebuildParagraphContentFromAnnotations(); pb.ParseParagraph(); Assert.AreEqual(gloss0_1, tapb.GetAnalysis(0, 1)); Assert.AreEqual(gloss1_1, tapb.GetAnalysis(1, 1)); Assert.AreEqual(gloss2_1, tapb.GetAnalysis(2, 1)); tapb.ValidateAnnotations(); }
public void SparseAnalyses_SimpleEdits_SimpleSegmentParagraph_DuplicateWordforms() { // First set sparse analyses on wordforms that have multiple occurrences. ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); IWfiGloss gloss_xxxyalola0_1 = tapb.SetDefaultWordGloss("xxxyalola", 0); // gloss first occurrence. IWfiGloss gloss_xxxpus1_1 = tapb.SetDefaultWordGloss("xxxpus", 1); // gloss second occurrence. IWfiGloss gloss_xxxnihimbilira2_1 = tapb.SetDefaultWordGloss("xxxnihimbilira", 2); // gloss third occurrence. pb.ParseParagraph(); var actualAnalysis_xxxyalola0_1 = tapb.GetAnalysis(0, 1); var actualAnalysis_xxxpus1_1 = tapb.GetAnalysis(1, 1); var actualAnalysis_xxxnihimbilira2_1 = tapb.GetAnalysis(2, 1); Assert.AreEqual(gloss_xxxyalola0_1, actualAnalysis_xxxyalola0_1); Assert.AreEqual(gloss_xxxpus1_1, actualAnalysis_xxxpus1_1); Assert.AreEqual(gloss_xxxnihimbilira2_1, actualAnalysis_xxxnihimbilira2_1); // verify the rest tapb.ValidateAnnotations(); // Replace some occurrences of these wordforms from the text to validate the analysis does not show up on the wrong occurrence. // Remove the first occurrence of 'xxxnihimbilira'; the (newly) second occurrence should still have the gloss. pb.ReplaceSegmentForm("xxxnihimbilira", 0, ""); pb.RebuildParagraphContentFromAnnotations(); pb.ParseParagraph(); actualAnalysis_xxxnihimbilira2_1 = tapb.GetAnalysis(2, 1); Assert.AreEqual(gloss_xxxnihimbilira2_1, actualAnalysis_xxxnihimbilira2_1); tapb.ValidateAnnotations(); // Remove first occurrence of 'xxxpus'; the next one should still have the gloss. pb.ReplaceSegmentForm("xxxpus", 0, ""); pb.RebuildParagraphContentFromAnnotations(); pb.ParseParagraph(); actualAnalysis_xxxpus1_1 = tapb.GetAnalysis(1, 1); Assert.AreEqual(gloss_xxxpus1_1, actualAnalysis_xxxpus1_1); tapb.ValidateAnnotations(); }
/// <summary> /// Verify that the text actually in the paragraph for the indicated segment and form /// is what is expected. /// </summary> /// <param name="tapb"></param> /// <param name="iSegment"></param> /// <param name="iSegForm"></param> internal static void ValidateCbaWordToBaselineWord(ParagraphAnnotatorForParagraphBuilder tapb, int iSegment, int iSegForm) { int ws; ITsString tssStringValue = GetTssStringValue(tapb, iSegment, iSegForm, out ws); IAnalysis analysis = tapb.GetAnalysis(iSegment, iSegForm); IWfiWordform wfInstanceOf = analysis.Wordform; ITsString tssWf = wfInstanceOf.Form.get_String(ws); string locale = wfInstanceOf.Services.WritingSystemManager.Get(ws).IcuLocale; var cf = new CaseFunctions(locale); string context = String.Format("[{0}]", tssStringValue); const string msg = "{0} cba mismatch in {1}."; Assert.AreEqual(cf.ToLower(tssStringValue.Text), cf.ToLower(tssWf.Text), String.Format(msg, "underlying wordform for InstanceOf", context)); }
public void NoAnalyses_NoEdits_PhraseWordforms() { // 1. Setup Tests with a basic phrase ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int) Text1ParaIndex.PhraseWordforms); // first do a basic phrase (without secondary phrases (guesses)) // xxxpus xxxyalola xxxnihimbilira. [xxxpus xxxyalola] xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira pb.MergeAdjacentAnnotations(1, 0); // generate mock ids pb.RebuildParagraphContentFromAnnotations(); // now produce a guess to establish the phrase annotation. var tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); pb.ActualParagraph.SegmentsOS[1].AnalysesRS.RemoveAt(0); // delete "xxxpus" // now replace "xxxyalola" with the new phrase form "xxxpus xxxyalola" IAnalysis beforeParse_phrase1_0 = pb.ExportCbaNodeToReal(1, 0); //string gloss; //IWfiGloss wg_phrase1_0 = tapb.SetDefaultWordGloss(1, 0, out gloss); // NOTE: Precondition checks to make sure we set up the annotation properly // The real test: now parse and verify that we maintained the expected result for the phrase annotation. pb.ParseParagraph(); var afterParse_actualWordform = tapb.GetAnalysis(1, 0); Assert.AreEqual(beforeParse_phrase1_0, afterParse_actualWordform, "word mismatch"); // verify the rest. tapb.ValidateAnnotations(); }