public void LT7974_Phrase_MakeAndBreak() { CheckDisposed(); // 1. Make Phrases IList<int[]> secondaryPathsToJoinWords = new List<int[]>(); IList<int[]> secondaryPathsToBreakPhrases = new List<int[]>(); ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.PhraseWordforms); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); // go ahead and parse the text generating real wordforms to be more like a real user situation (LT-7974) // and reset the concordance to simulate the situation where the user hasn't loaded ConcordanceWords yet. (Cache.LangProject.WordformInventoryOA as WordformInventory).ResetConcordanceWordformsAndOccurrences(); bool fDidParse; (m_text1.ContentsOA as StText).LastParsedTimestamp = 0; ParagraphParser.ParseText(m_text1.ContentsOA, new NullProgressState(), out fDidParse); pb.ResyncExpectedAnnotationIds(); // first do a basic phrase (without secondary phrases (guesses)), which should not delete "xxxpus" or "xxxyalola" // since they occur later in the text. // [xxxpus xxxyalola] xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira int hvoCba1_0 = tapb.GetSegmentForm(1, 0); // second xxxpus int hvoCba1_1 = tapb.GetSegmentForm(1, 1); // second xxxyalola ICmBaseAnnotation cba1_0 = new CmBaseAnnotation(Cache, hvoCba1_0); ICmBaseAnnotation cba1_1 = new CmBaseAnnotation(Cache, hvoCba1_1); IWfiWordform wf1 = cba1_0.InstanceOfRA as WfiWordform; IWfiWordform wf2 = cba1_0.InstanceOfRA as WfiWordform; tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); // after the merge, make sure the wordforms for xxxpus and xxxyalola are still valid Assert.IsTrue(wf1.IsValidObject(), "expected xxxpus to still be valid"); Assert.IsTrue(wf2.IsValidObject(), "expected xxxyalola to still be valid"); tapb.ValidateAnnotations(true); // now break the phrase and make sure we delete this wordform, b/c it is not occurring elsewhere (Cache.LangProject.WordformInventoryOA as WordformInventory).ResetConcordanceWordformsAndOccurrences(); pb.ResyncExpectedAnnotationIds(); // \xxxpus\ \xxxyalola\ xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira int hvoCba0_0 = tapb.GetSegmentForm(0, 0); // xxxpus xxxyalola ICmBaseAnnotation cba0_0 = new CmBaseAnnotation(Cache, hvoCba0_0); IWfiWordform wf3 = cba0_0.InstanceOfRA as WfiWordform; secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsFalse(wf3.IsValidObject(), "expected 'xxxpus xxxyalola' to be deleted."); tapb.ValidateAnnotations(true); // rejoin the first phrase, parse the text, and break the first phrase // [xxxpus xxxyalola] xxxnihimbilira. {xxxpus xxxyalola} xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira secondaryPathsToJoinWords.Add(new int[2] { 1, 0 }); // {xxxpus xxxyalola} xxxhesyla secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); hvoCba0_0 = tapb.GetSegmentForm(0, 0); // xxxpus xxxyalola cba0_0 = new CmBaseAnnotation(Cache, hvoCba0_0); wf1 = cba0_0.InstanceOfRA as WfiWordform; tapb.ReparseParagraph(); // just break the new phrase (and the leave existing guesses) // \xxxpus\ \xxxyalola\ xxxnihimbilira. {xxxpus xxxyalola} xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira (Cache.LangProject.WordformInventoryOA as WordformInventory).ResetConcordanceWordformsAndOccurrences(); secondaryPathsToJoinWords.Clear(); tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsTrue(wf1.IsValidObject(), "expected 'xxxpus xxxyalola' to still be valid"); tapb.ValidateAnnotations(true); // xxxpus xxxyalola xxxnihimbilira. \xxxpus\ \xxxyalola\ xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira tapb.BreakPhrase(1, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsTrue(wf1.IsValidObject(), "expected 'xxxpus xxxyalola' to still be valid"); tapb.ValidateAnnotations(true); // xxxpus xxxyalola xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. \xxxpus\ \xxxyalola\ xxxnihimbilira tapb.BreakPhrase(2, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsFalse(wf1.IsValidObject(), "expected 'xxxpus xxxyalola' to be deleted"); tapb.ValidateAnnotations(true); // now do two joins, the second resulting in deletion of a wordform. // xxxpus xxxyalola xxxnihimbilira. xxxpus [xxxyalola xxxhesyla] xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira // xxxpus xxxyalola xxxnihimbilira. xxxpus [xxxyalola xxxhesyla xxxnihimbilira]. xxxpus xxxyalola xxxnihimbilira (Cache.LangProject.WordformInventoryOA as WordformInventory).ResetConcordanceWordformsAndOccurrences(); (m_text1.ContentsOA as StText).LastParsedTimestamp = 0; ParagraphParser.ParseText(m_text1.ContentsOA, new NullProgressState(), out fDidParse); pb.ResyncExpectedAnnotationIds(); tapb.MergeAdjacentAnnotations(1, 1, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); hvoCba1_1 = tapb.GetSegmentForm(1, 1); // xxxyalola xxxhesyla cba1_1 = new CmBaseAnnotation(Cache, hvoCba1_1); IWfiWordform wf4 = cba1_1.InstanceOfRA as WfiWordform; tapb.MergeAdjacentAnnotations(1, 1, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); // this merge should have deleted 'xxxyalola xxxhesyla' Assert.IsFalse(wf4.IsValidObject(), "expected 'xxxyalola xxxhesyla' to be deleted."); tapb.ValidateAnnotations(true); }
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_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 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); ParagraphParser.ParseParagraph(pb.ActualParagraph); // Create a new lexical entry and sense. int clsidForm; string formLexEntry = "xnihimbilira"; var morphTypeRepository = Cache.ServiceLocator.GetInstance<IMoMorphTypeRepository>(); var rootMorphType = morphTypeRepository. GetObject(MoMorphTypeTags.kguidMorphRoot); ITsString tssLexEntryForm = TsStringUtils.MakeTss(formLexEntry, Cache.DefaultVernWs); var entryFactory = Cache.ServiceLocator.GetInstance<ILexEntryFactory>(); ILexEntry xnihimbilira_Entry = entryFactory.Create(rootMorphType, tssLexEntryForm, "xnihimbilira.sense1", null); ILexSense xnihimbilira_Sense1 = xnihimbilira_Entry.SensesOS[0]; var senseFactory = Cache.ServiceLocator.GetInstance<ILexSenseFactory>(); ILexSense xnihimbilira_Sense2 = senseFactory.Create(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); Assert.That(xnihimbilira_Sense1.ReferringObjects, Has.Count.EqualTo(1)); Assert.That(xnihimbilira_Sense2.ReferringObjects, Has.Count.EqualTo(0)); IWfiAnalysis waCba1_0 = pb.ActualParagraph.SegmentsOS[1].AnalysesRS[0] as IWfiAnalysis; Assert.IsNotNull(waCba1_0, String.Format("Unexpected class({0}) of Analysis({1}) for cba0.", pb.ActualParagraph.SegmentsOS[0].AnalysesRS[2].GetType(), pb.ActualParagraph.SegmentsOS[0].AnalysesRS[2].Hvo)); Assert.AreEqual(xnihimbilira_Sense1, waCba1_0.MorphBundlesOS[1].SenseRA); Assert.That(waCba1_0.ReferringObjects, Has.Count.EqualTo(1)); // one ref to the analysis (from segment 0) var wordform = (IWfiWordform)waCba1_0.Owner; Assert.That(wordform.FullConcordanceCount, Is.EqualTo(3)); // unchanged even though one is now an analysis // 2. Establish word gloss on the existing analysis. string wordGloss1; tapb.SetDefaultWordGloss(2, 1, wfiAnalysis1, out wordGloss1); Assert.That(wordform.FullConcordanceCount, Is.EqualTo(3)); // analysis and gloss and unchanged wordform all count var wgCba2_1 = pb.ActualParagraph.SegmentsOS[2].AnalysesRS[1] as IWfiGloss; Assert.IsNotNull(wgCba2_1, String.Format("Unexpected class({0}) of InstanceOf({1}) for cba1.", pb.ActualParagraph.SegmentsOS[2].AnalysesRS[1].GetType(), pb.ActualParagraph.SegmentsOS[2].AnalysesRS[1].Hvo)); var waCba2_1 = wgCba2_1.Owner as IWfiAnalysis; Assert.AreEqual(xnihimbilira_Sense1.Hvo, waCba2_1.MorphBundlesOS[1].SenseRA.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); Assert.That(wordform.FullConcordanceCount, Is.EqualTo(3)); var waCba0_2 = pb.ActualParagraph.SegmentsOS[0].AnalysesRS[2] as IWfiAnalysis; Assert.IsNotNull(waCba0_2, String.Format("Unexpected class({0}) of InstanceOf({1}) for cba0.", pb.ActualParagraph.SegmentsOS[2].AnalysesRS[1].GetType(), pb.ActualParagraph.SegmentsOS[2].AnalysesRS[1].Hvo)); Assert.AreEqual(xnihimbilira_Sense1.Hvo, waCba0_2.MorphBundlesOS[1].SenseRA.Hvo); Assert.That(xnihimbilira_Sense1.ReferringObjects, Has.Count.EqualTo(2)); Assert.That(xnihimbilira_Sense2.ReferringObjects, Has.Count.EqualTo(0)); // 4. change an existing sense to sense2. tapb.SetMorphSense(0, 2, 1, xnihimbilira_Sense2); Assert.That(xnihimbilira_Sense1.ReferringObjects, Has.Count.EqualTo(1)); Assert.That(xnihimbilira_Sense2.ReferringObjects, Has.Count.EqualTo(1)); waCba0_2 = pb.ActualParagraph.SegmentsOS[0].AnalysesRS[2] as IWfiAnalysis; Assert.IsNotNull(waCba0_2, String.Format("Unexpected class({0}) of InstanceOf({1}) for cba0.", pb.ActualParagraph.SegmentsOS[2].AnalysesRS[1].GetType(), pb.ActualParagraph.SegmentsOS[2].AnalysesRS[1].Hvo)); Assert.AreEqual(xnihimbilira_Sense2, waCba0_2.MorphBundlesOS[1].SenseRA); // 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); Assert.That(xnihimbilira_Sense2.ReferringObjects, Has.Count.EqualTo(2)); // reparse paragraph and make sure important stuff doesn't change tapb.ReparseParagraph(); Assert.That(xnihimbilira_Sense1.ReferringObjects, Has.Count.EqualTo(1)); Assert.That(xnihimbilira_Sense2.ReferringObjects, Has.Count.EqualTo(2)); }
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(); }
//[Ignore("FWC-16: this test causes NUnit to hang in fixture teardown - need more investigation")] public void Phrase_MakeAndBreak() { // 1. Make Phrases IList<int[]> secondaryPathsToJoinWords = new List<int[]>(); IList<int[]> secondaryPathsToBreakPhrases = new List<int[]>(); ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.PhraseWordforms); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); // first do a basic phrase (without secondary phrases (guesses)) and break it // [xxxpus xxxyalola] xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(true); // \xxxpus\ \xxxyalola\ xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(true); // make phrases with secondary phrases (guesses). // [xxxpus xxxyalola] xxxnihimbilira. {xxxpus xxxyalola} xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); secondaryPathsToJoinWords.Add(new int[2] { 1, 0 }); // {xxxpus xxxyalola} xxxhesyla secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); // then check that the last phrase has been properly annotated. tapb.ValidateAnnotations(); // JohnT: in 6.0, making the larger phrase would apparently get rid of the guessed phrase. // in 7.0+ there's no distinction between a guess and user-made phrase, so once it exists it doesn't go away. // [xxxpus xxxyalola xxxnihimbilira]. [xxxpus xxxyalola] xxxhesyla xxxnihimbilira. {xxxpus xxxyalola xxxnihimbilira}. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); // 7.0+ secondaryPathsToBreakPhrases.Add(new int[2] { 1, 0 }); // \xxxpus\ \xxxyalola\ xxxhesyla secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {{xxxpus xxxyalola} xxxnihimbilira} tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); // [xxxpus xxxyalola xxxnihimbilira]. [xxxpus xxxyalola] xxxhesyla xxxnihimbilira. {xxxpus xxxyalola xxxnihimbilira} // 7.0+ nothing to do here; it's in this state after the previous change. //secondaryPathsToJoinWords.Clear(); //secondaryPathsToBreakPhrases.Clear(); //tapb.MergeAdjacentAnnotations(1, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); //tapb.ValidateAnnotations(); // 2. Break Phrases. // [xxxpus xxxyalola xxxnihimbilira]. \xxxpus\ \xxxyalola\ xxxhesyla xxxnihimbilira. {xxxpus xxxyalola xxxnihimbilira} secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.BreakPhrase(1, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(); // [\xxxpus\ \xxxyalola\ \xxxnihimbilira\]. xxxpus xxxyalola xxxhesyla xxxnihimbilira. {\xxxpus\ \xxxyalola\ \xxxnihimbilira\} secondaryPathsToBreakPhrases.Clear(); // 7.0+ secondaryPathsToBreakPhrases.Add(new int[2] { 2, 0 }); // {\xxxpus\ \xxxyalola\ \xxxnihimbilira\} tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(); // 7.0+ breaking the guessed phrase has to be an extra step. tapb.BreakPhrase(2, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(); // gloss the second occurrence of xxxyalola and check that we don't overwrite it with a secondary guess. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); // [xxxpus xxxyalola] xxxnihimbilira. xxxpus [xxxyalola] xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira tapb.SetDefaultWordGloss("xxxyalola", 1); secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); // reparse so that we can 'confirm' "xxxpus xxxyalola" phrase. tapb.SetDefaultWordGloss("xxxpus xxxyalola", 0); // 'confirm' this merge. tapb.ValidateAnnotations(); // join the last occurrence of 'xxxpus xxxyalola xxxnihimbilira' // and check that we don't overwrite the first join of 'xxxpus xxxyalola' with a secondary guess. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); // [xxxpus xxxyalola] xxxnihimbilira. xxxpus [xxxyalola] xxxhesyla xxxnihimbilira. [xxxpus xxxyalola xxxnihimbilira] tapb.MergeAdjacentAnnotations(2, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); // reparse so that we can 'confirm' "xxxpus xxxyalola xxxnihimbilira" phrase. tapb.SetDefaultWordGloss("xxxpus xxxyalola xxxnihimbilira", 0); // 'confirm' this merge. tapb.ValidateAnnotations(); // make sure we can break our analysis. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); // [xxxpus xxxyalola] xxxnihimbilira. xxxpus [xxxyalola] xxxhesyla xxxnihimbilira. {\xxxpus\ \xxxyalola\} \xxxnihimbilira\ // In 6.0, apparently we would re-guess the shorter pus yalola phrase. In 7.0+, breaking a phrase does not // produce a new parse and new phrase guesses. Otherwise, if the longer phrase still existed somewhere else, // it would be guessed again! Don't see how this ever worked right, except that after breaking the phrase the // user would usually annotate the parts before there was occasion to re-parse. // 7.0+ secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.BreakPhrase(2, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, "xxxpus xxxyalola"); tapb.ValidateAnnotations(); }
public void Phrase_SimpleEdits_LT6244() { // 1. Make Phrases IList<int[]> secondaryPathsToJoinWords = new List<int[]>(); IList<int[]> secondaryPathsToBreakPhrases = new List<int[]>(); ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.PhraseWordforms); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); // first do a basic phrase (without secondary phrases (guesses)) // xxxpus xxxyalola xxxnihimbilira. xxxpus xxxyalola [xxxhesyla xxxnihimbilira]. xxxpus xxxyalola xxxnihimbilira tapb.MergeAdjacentAnnotations(1, 2, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(true); // edit the second word in the phrase. pb.ReplaceSegmentForm("xxxhesyla xxxnihimbilira", 0, "xxxhesyla xxxra"); pb.BreakPhraseAnnotation(1, 2); // this edit should break the phrase back into words. tapb.ValidateAnnotations(); }
public void SparseTwficAnalyses_NoEdits_MixedCaseWordformsParagraph() { CheckDisposed(); // 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); tapb.ValidateAnnotations(); // set the corresponding annotations to lowercase wordforms. tapb.SetAlternateCase("Xxxpus", 0, StringCaseStatus.allLower); tapb.SetAlternateCase("Xxxnihimbilira", 0, StringCaseStatus.allLower); tapb.SetAlternateCase("Xxxhesyla", 0, StringCaseStatus.allLower); tapb.SetAlternateCase("XXXNIHIMBILIRA", 0, StringCaseStatus.allLower); tapb.ValidateAnnotations(); }
public override void ReplaceTwficWithSameTwfic() { StTxtPara para0 = m_text1.ContentsOA.ParagraphsOS[0] as StTxtPara; m_rtp.TextBuilder.SelectedNode = m_rtp.GetParagraphBuilder(para0.Hvo).SegmentNodes()[0]; TextBuilder tb = new TextBuilder(m_rtp.TextBuilder); ParagraphBuilder pb = tb.GetParagraphBuilder(para0.Hvo); ParagraphAnnotatorForParagraphBuilder papb = new ParagraphAnnotatorForParagraphBuilder(pb); string wgloss; papb.SetDefaultWordGloss(0, 0, out wgloss); pb.ReplaceSegmentForm(0, 0, "xxxpus", 0); XmlNode paraNodeAfterEdit = tb.SelectedNode; m_rtp.AddResultingAnnotationState(paraNodeAfterEdit); base.ReplaceTwficWithSameTwfic(); }
public void SparseTwficAnalyses_SimpleEdits_SimpleSegmentParagraph_DuplicateWordforms() { CheckDisposed(); // 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); tapb.SetDefaultWordGloss("xxxyalola", 0); // gloss first occurrence. tapb.SetDefaultWordGloss("xxxpus", 1); // gloss second occurrence. tapb.SetDefaultWordGloss("xxxnihimbilira", 2); // gloss third occurrence. 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 second occurrence should have the gloss. pb.ReplaceSegmentForm("xxxnihimbilira", 0, ""); pb.RebuildParagraphContentFromAnnotations(); tapb.ValidateAnnotations(); // Remove first occurrence of 'xxxpus'; the next one should still have the gloss. pb.ReplaceSegmentForm("xxxpus", 0, ""); pb.RebuildParagraphContentFromAnnotations(); tapb.ValidateAnnotations(); //SparseTwficAnalyses_SimpleEdits_SimpleSegmentParagraph_DuplicateWordforms_RemoveSegment_LT5376() //SparseTwficAnalyses_SimpleEdits_SimpleSegmentParagraph_DuplicateWordforms_AddWhitespace_LT5313() }
public void SparseTwficAnalyses_SimpleEdits_SimpleSegmentParagraph_DuplicateWordforms_AddWhitespace_LT5313() { CheckDisposed(); // 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); tapb.SetDefaultWordGloss("xxxyalola", 0); // gloss first occurrence. tapb.SetDefaultWordGloss("xxxpus", 1); // gloss second occurrence. tapb.SetDefaultWordGloss("xxxnihimbilira", 2); // gloss third occurrence. tapb.ValidateAnnotations(); // 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(); tapb.ValidateAnnotations(); }
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."); }
public void SparseSegmentAnalyses_FreeformAnnotations_LT7318() { // Make some analyses linked to the same LexSense. //<!--xxxpus xxxyalola xxxnihimbilira. xxxnihimbilira xxxpus xxxyalola. xxxhesyla xxxnihimbilira.--> ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara); List<int> segments = (pb.ActualParagraph as StTxtPara).Segments; Assert.AreEqual(3, segments.Count, "Unexpected number of senses."); // Verify that each of these segments are dummy Assert.IsTrue(Cache.IsDummyObject(segments[0]), "Expected dummy segment."); Assert.IsTrue(Cache.IsDummyObject(segments[1]), "Expected dummy segment."); Assert.IsTrue(Cache.IsDummyObject(segments[2]), "Expected dummy segment."); // Load free form annotations for segments. shouldn't have any. Set<int> analWsIds = new Set<int>(Cache.LangProject.AnalysisWssRC.HvoArray); StTxtPara.LoadSegmentFreeformAnnotationData(Cache, new Set<int>(segments), analWsIds); int tagSegFF = StTxtPara.SegmentFreeformAnnotationsFlid(Cache); int[] segFFs = Cache.GetVectorProperty(segments[0], 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(segments[1], tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 1 should not have any freeform annotations."); segFFs = Cache.GetVectorProperty(segments[2], tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 2 should not have any freeform annotations."); // convert the third segment to a real, in preparation for adding the annotation. ICmBaseAnnotation cbaReal = CmBaseAnnotation.ConvertBaseAnnotationToReal(m_fdoCache, segments[2]); segments = (pb.ActualParagraph as StTxtPara).Segments; Assert.IsTrue(!Cache.IsDummyObject(segments[2]), "Expected real segment."); // Try adding some freeform translations to third segment. int segDefn_literalTranslation = Cache.GetIdFromGuid(LangProject.kguidAnnLiteralTranslation); int segDefn_freeTranslation = Cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation); BaseFreeformAdder ffAdder = new BaseFreeformAdder(Cache); ICmIndirectAnnotation freeTrans0 = ffAdder.AddFreeformAnnotation(segments[2], segDefn_freeTranslation); freeTrans0.Comment.SetAlternative("Segment2: Freeform translation.", Cache.DefaultAnalWs); ICmIndirectAnnotation literalTrans0 = ffAdder.AddFreeformAnnotation(segments[2], segDefn_literalTranslation); literalTrans0.Comment.SetAlternative("Segment2: Literal translation.", Cache.DefaultAnalWs); // see if we can load this into the cache. StTxtPara.LoadSegmentFreeformAnnotationData(Cache, new Set<int>(segments), analWsIds); segFFs = Cache.GetVectorProperty(segments[2], tagSegFF, true); Assert.AreEqual(2, segFFs.Length, "Segment 2 should have freeform annotations."); Assert.AreEqual(segFFs[0], freeTrans0.Hvo, "Segment 2 Freeform translation id."); Assert.AreEqual(segFFs[1], literalTrans0.Hvo, "Segment 2 Literal translation id."); // make sure the other segments don't have freeform annotations. segFFs = Cache.GetVectorProperty(segments[0], 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(segments[1], tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 1 should not have any freeform annotations."); // reparse the paragraph and make sure nothing changed. ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); tapb.ReparseParagraph(); segments = (pb.ActualParagraph as StTxtPara).Segments; StTxtPara.LoadSegmentFreeformAnnotationData(Cache, new Set<int>(segments), analWsIds); segFFs = Cache.GetVectorProperty(segments[2], tagSegFF, true); Assert.AreEqual(2, segFFs.Length, "Segment 2 should have freeform annotations."); Assert.AreEqual(segFFs[0], freeTrans0.Hvo, "Segment 2 Freeform translation id."); Assert.AreEqual(segFFs[1], literalTrans0.Hvo, "Segment 2 Literal translation id."); // make sure the other segments don't have freeform annotations. segFFs = Cache.GetVectorProperty(segments[0], 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(segments[1], tagSegFF, true); Assert.AreEqual(0, segFFs.Length, "Segment 1 should not have any freeform annotations."); }
//[Ignore("FWC-16: this test causes NUnit to hang in fixture teardown - need more investigation")] public void Phrase_MakeAndBreak() { CheckDisposed(); // 1. Make Phrases IList<int[]> secondaryPathsToJoinWords = new List<int[]>(); IList<int[]> secondaryPathsToBreakPhrases = new List<int[]>(); ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.PhraseWordforms); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); // first do a basic phrase (without secondary phrases (guesses)) and break it // [xxxpus xxxyalola] xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(true); // \xxxpus\ \xxxyalola\ xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(true); // make phrases with secondary phrases (guesses). // [xxxpus xxxyalola] xxxnihimbilira. {xxxpus xxxyalola} xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); secondaryPathsToJoinWords.Add(new int[2] { 1, 0 }); // {xxxpus xxxyalola} xxxhesyla secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); // then check that the last phrase has been properly annotated. tapb.ValidateAnnotations(); // [xxxpus xxxyalola xxxnihimbilira]. xxxpus xxxyalola xxxhesyla xxxnihimbilira. {xxxpus xxxyalola xxxnihimbilira}. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); secondaryPathsToBreakPhrases.Add(new int[2] { 1, 0 }); // \xxxpus\ \xxxyalola\ xxxhesyla secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {{xxxpus xxxyalola} xxxnihimbilira} tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); // [xxxpus xxxyalola xxxnihimbilira]. [xxxpus xxxyalola] xxxhesyla xxxnihimbilira. {xxxpus xxxyalola xxxnihimbilira} secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.MergeAdjacentAnnotations(1, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); // 2. Break Phrases. // [xxxpus xxxyalola xxxnihimbilira]. \xxxpus\ \xxxyalola\ xxxhesyla xxxnihimbilira. {xxxpus xxxyalola xxxnihimbilira} secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.BreakPhrase(1, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(); // [\xxxpus\ \xxxyalola\ \xxxnihimbilira\]. xxxpus xxxyalola xxxhesyla xxxnihimbilira. {\xxxpus\ \xxxyalola\ \xxxnihimbilira\} secondaryPathsToBreakPhrases.Clear(); secondaryPathsToBreakPhrases.Add(new int[2] { 2, 0 }); // {\xxxpus\ \xxxyalola\ \xxxnihimbilira\} tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(); // gloss the second occurrence of xxxyalola and check that we don't overwrite it with a secondary guess. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); // [xxxpus xxxyalola] xxxnihimbilira. xxxpus [xxxyalola] xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira tapb.SetDefaultWordGloss("xxxyalola", 1); secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); // reparse so that we can 'confirm' "xxxpus xxxyalola" phrase. tapb.SetDefaultWordGloss("xxxpus xxxyalola", 0); // 'confirm' this merge. tapb.ValidateAnnotations(); // join the last occurrence of 'xxxpus xxxyalola xxxnihimbilira' // and check that we don't overwrite the first join of 'xxxpus xxxyalola' with a secondary guess. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); // [xxxpus xxxyalola] xxxnihimbilira. xxxpus [xxxyalola] xxxhesyla xxxnihimbilira. [xxxpus xxxyalola xxxnihimbilira] tapb.MergeAdjacentAnnotations(2, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); // reparse so that we can 'confirm' "xxxpus xxxyalola xxxnihimbilira" phrase. tapb.SetDefaultWordGloss("xxxpus xxxyalola xxxnihimbilira", 0); // 'confirm' this merge. tapb.ValidateAnnotations(); // make sure we can break our analysis. secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); // [xxxpus xxxyalola] xxxnihimbilira. xxxpus [xxxyalola] xxxhesyla xxxnihimbilira. {\xxxpus\ \xxxyalola\} \xxxnihimbilira\ secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.BreakPhrase(2, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, "xxxpus xxxyalola"); tapb.ValidateAnnotations(); }
public void Phrase_Make() { // 1. Make Phrases IList<int[]> secondaryPathsToJoinWords = new List<int[]>(); IList<int[]> secondaryPathsToBreakPhrases = new List<int[]>(); ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int) Text1ParaIndex.PhraseWordforms); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); XmlNode paraDef0 = pb.ParagraphDefinition.CloneNode(true); XmlNode paraDef_afterJoin1_2; pb.ParseParagraph(); // xxxpus xxxyalola xxxnihimbilira. xxxpus xxxyalola [xxxhesyla xxxnihimbilira]. xxxpus xxxyalola xxxnihimbilira tapb.MergeAdjacentAnnotations(1, 2, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); }
public override void ReplaceTwficsWithStringContainingSameTwfics() { StTxtPara para0 = m_text1.ContentsOA.ParagraphsOS[0] as StTxtPara; m_rtp.TextBuilder.SelectNode(para0, 0); ParagraphAnnotatorForParagraphBuilder papb = new ParagraphAnnotatorForParagraphBuilder( m_rtp.TextBuilder.GetParagraphBuilder(para0.Hvo)); string wgloss; papb.SetDefaultWordGloss(0, 0, out wgloss); // clone text builder to modify a different version of the document. // this will help Validation maintain the initial word gloss state. TextBuilder tb = new TextBuilder(m_rtp.TextBuilder); ParagraphBuilder pb = tb.GetParagraphBuilder(para0.Hvo); // basically replace all the existing twfics in the selection with new ones. pb.ReplaceSegmentForm(0, 0, "xxxNewTwfic", 0); pb.ReplaceSegmentForm(0, 1, "xxxpus", 0); pb.ReplaceSegmentForm(0, 2, "xxxyalola", 0); pb.InsertSegmentForm(0, 3, LangProject.kguidAnnWordformInContext, "xxxnihimbilira"); XmlNode paraNodeAfterEdit = tb.SelectedNode; m_rtp.AddResultingAnnotationState(paraNodeAfterEdit); base.ReplaceTwficsWithStringContainingSameTwfics(); }
public void LT7974_Phrase_MakeAndBreak() { // 1. Make Phrases IList<int[]> secondaryPathsToJoinWords = new List<int[]>(); IList<int[]> secondaryPathsToBreakPhrases = new List<int[]>(); //Thist test proved to be incapable of being Undone, since further tests relied on state this test affected //the following two variables duplicate member variables to isolate changes to this test. XmlDocument donTouchIt = new XmlDocument(); IText noLoToque = LoadTestText( Path.Combine("FDO", Path.Combine("FDOTests", Path.Combine("TestData", "ParagraphParserTestTexts.xml"))), 1, donTouchIt); ParagraphBuilder pb = new ParagraphBuilder(donTouchIt, noLoToque, (int)Text1ParaIndex.PhraseWordforms); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); // go ahead and parse the text generating real wordforms to be more like a real user situation (LT-7974) // and reset the concordance to simulate the situation where the user hasn't loaded ConcordanceWords yet. ParagraphParser.ParseText(noLoToque.ContentsOA); pb.ResyncExpectedAnnotationIds(); // first do a basic phrase (without secondary phrases (guesses)), which should not delete "xxxpus" or "xxxyalola" // since they occur later in the text. // [xxxpus xxxyalola] xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira IWfiWordform wf1 = pb.ActualParagraph.SegmentsOS[0].AnalysesRS[0].Wordform; IWfiWordform wf2 = pb.ActualParagraph.SegmentsOS[0].AnalysesRS[1].Wordform; tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); // after the merge, make sure the wordforms for xxxpus and xxxyalola are still valid Assert.IsTrue(wf1.IsValidObject, "expected xxxpus to still be valid"); Assert.IsTrue(wf2.IsValidObject, "expected xxxyalola to still be valid"); tapb.ValidateAnnotations(true); // now break the phrase and make sure we delete this wordform, b/c it is not occurring elsewhere pb.ResyncExpectedAnnotationIds(); // \xxxpus\ \xxxyalola\ xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira IWfiWordform wf3 = pb.ActualParagraph.SegmentsOS[0].AnalysesRS[0].Wordform; secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsFalse(wf3.IsValidObject, "expected 'xxxpus xxxyalola' to be deleted."); tapb.ValidateAnnotations(true); // rejoin the first phrase, parse the text, and break the first phrase // [xxxpus xxxyalola] xxxnihimbilira. {xxxpus xxxyalola} xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira secondaryPathsToJoinWords.Add(new int[2] { 1, 0 }); // {xxxpus xxxyalola} xxxhesyla secondaryPathsToJoinWords.Add(new int[2] { 2, 0 }); // {xxxpus xxxyalola} xxxnihimbilira tapb.MergeAdjacentAnnotations(0, 0, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); wf1 = pb.ActualParagraph.SegmentsOS[0].AnalysesRS[0].Wordform; tapb.ReparseParagraph(); // just break the new phrase (and the leave existing guesses) // \xxxpus\ \xxxyalola\ xxxnihimbilira. {xxxpus xxxyalola} xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira secondaryPathsToJoinWords.Clear(); tapb.BreakPhrase(0, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsTrue(wf1.IsValidObject, "expected 'xxxpus xxxyalola' to still be valid"); tapb.ValidateAnnotations(true); // xxxpus xxxyalola xxxnihimbilira. \xxxpus\ \xxxyalola\ xxxhesyla xxxnihimbilira. {xxxpus xxxyalola} xxxnihimbilira tapb.BreakPhrase(1, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsTrue(wf1.IsValidObject, "expected 'xxxpus xxxyalola' to still be valid"); tapb.ValidateAnnotations(true); // xxxpus xxxyalola xxxnihimbilira. xxxpus xxxyalola xxxhesyla xxxnihimbilira. \xxxpus\ \xxxyalola\ xxxnihimbilira tapb.BreakPhrase(2, 0, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); Assert.IsFalse(wf1.IsValidObject, "expected 'xxxpus xxxyalola' to be deleted"); tapb.ValidateAnnotations(true); // now do two joins, the second resulting in deletion of a wordform. // xxxpus xxxyalola xxxnihimbilira. xxxpus [xxxyalola xxxhesyla] xxxnihimbilira. xxxpus xxxyalola xxxnihimbilira // xxxpus xxxyalola xxxnihimbilira. xxxpus [xxxyalola xxxhesyla xxxnihimbilira]. xxxpus xxxyalola xxxnihimbilira ParagraphParser.ParseText(noLoToque.ContentsOA); pb.ResyncExpectedAnnotationIds(); tapb.MergeAdjacentAnnotations(1, 1, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); IWfiWordform wf4 = pb.ActualParagraph.SegmentsOS[1].AnalysesRS[1].Wordform; tapb.MergeAdjacentAnnotations(1, 1, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); // this merge should have deleted 'xxxyalola xxxhesyla' Assert.IsFalse(wf4.IsValidObject, "expected 'xxxyalola xxxhesyla' to be deleted."); tapb.ValidateAnnotations(true); }
public override void Initialize() { CheckDisposed(); base.Initialize(); // annotate all the twfics in the text. foreach (IStPara para in m_rtp.TextBuilder.ActualStText.ParagraphsOS) { ParagraphBuilder pb = m_rtp.TextBuilder.GetParagraphBuilder(para.Hvo); ParagraphAnnotatorForParagraphBuilder papb = new ParagraphAnnotatorForParagraphBuilder(pb); papb.SetupDefaultWordGlosses(); } }
/// <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)); }
/// <summary> /// TODO: Finish implementing this. /// </summary> /// <returns></returns> public List<int> ExportRealSegmentAnnotationsFromDefn() { List<int> realSegments = new List<int>(); foreach (IStTxtPara para in m_text.ContentsOA.ParagraphsOS) { ParagraphBuilder pb = GetParagraphBuilder(para); ParagraphAnnotatorForParagraphBuilder papb = new ParagraphAnnotatorForParagraphBuilder(pb); int iseg = 0; foreach (XmlNode segNode in pb.SegmentNodes()) { int hvoSeg = papb.GetSegmentHvo(iseg); // export this into a real annotation by converting it to a real annotation. } } return realSegments; }
public void SparseSegmentAnalyses_FreeformAnnotations_LT7318() { // Make some analyses linked to the same LexSense. //<!--xxxpus xxxyalola xxxnihimbilira. xxxnihimbilira xxxpus xxxyalola. xxxhesyla xxxnihimbilira.--> ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.SimpleSegmentPara); var segments = pb.ActualParagraph.SegmentsOS; Assert.AreEqual(3, segments.Count, "Unexpected number of senses."); // Load free form annotations for segments. shouldn't have any. Assert.That(segments[0].FreeTranslation.AvailableWritingSystemIds.Length, Is.EqualTo(0)); Assert.That(segments[1].FreeTranslation.AvailableWritingSystemIds.Length, Is.EqualTo(0)); Assert.That(segments[2].FreeTranslation.AvailableWritingSystemIds.Length, Is.EqualTo(0)); // Try adding some freeform translations to third segment. segments[2].FreeTranslation.AnalysisDefaultWritingSystem = Cache.TsStrFactory.MakeString("Segment2: Freeform translation.", Cache.DefaultAnalWs); segments[2].LiteralTranslation.AnalysisDefaultWritingSystem = Cache.TsStrFactory.MakeString("Segment2: Literal translation.", Cache.DefaultAnalWs); // make sure the other segments don't have freeform annotations. Assert.That(segments[0].FreeTranslation.AvailableWritingSystemIds.Length, Is.EqualTo(0)); Assert.That(segments[1].FreeTranslation.AvailableWritingSystemIds.Length, Is.EqualTo(0)); // reparse the paragraph and make sure nothing changed. ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); tapb.ReparseParagraph(); segments = (pb.ActualParagraph as IStTxtPara).SegmentsOS; Assert.That(segments[0].FreeTranslation.AvailableWritingSystemIds.Length, Is.EqualTo(0)); Assert.That(segments[1].FreeTranslation.AvailableWritingSystemIds.Length, Is.EqualTo(0)); Assert.That(segments[2].FreeTranslation.AnalysisDefaultWritingSystem.Text, Is.EqualTo("Segment2: Freeform translation.")); Assert.That(segments[2].LiteralTranslation.AnalysisDefaultWritingSystem.Text, Is.EqualTo("Segment2: Literal translation.")); }
public void NoAnalyses_NoEdits( [Values(Text1ParaIndex.EmptyParagraph, Text1ParaIndex.SimpleSegmentPara, Text1ParaIndex.ComplexPunctuations, Text1ParaIndex.MixedCases, Text1ParaIndex.MultipleWritingSystems)] Text1ParaIndex paraIdx) { var pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)paraIdx); var tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); tapb.ValidateAnnotations(); }
internal static ITsString GetTssStringValue(ParagraphAnnotatorForParagraphBuilder tapb, int iSegment, int iSegForm, out int ws) { ITsString tssStringValue = tapb.GetSegment(iSegment).GetBaselineText(iSegForm); ws = TsStringUtils.GetWsAtOffset(tssStringValue, 0); return tssStringValue; }
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(); }
public void SparseAnalyses_SimpleEdits_SimpleSegmentParagraph_DuplicateWordforms_RemoveSegment_LT5376() { // 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); tapb.SetDefaultWordGloss("xxxyalola", 0); // gloss first occurrence. tapb.ValidateAnnotations(); // Remove first sentence containing 'xxxyalola'; its annotation should be removed. pb.RemoveSegment(0); pb.RebuildParagraphContentFromAnnotations(); pb.ParseParagraph(); tapb.ValidateAnnotations(); }
public void NoAnalyses_NoEdits_MultipleWritingSystemsParagraph_LT5379() { var pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.MultipleWritingSystems); var tapb = new ParagraphAnnotatorForParagraphBuilder(pb); pb.ParseParagraph(); tapb.ValidateAnnotations(); }
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 NoAnalyses_SimpleEdits_MultipleWritingSystemsParagraph() { ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.MultipleWritingSystems); // verify that our wfics point to wordforms in the expected wss. pb.ParseParagraph(); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); FdoValidator.ValidateCbaWordToBaselineWord(tapb, 0, 0); //FdoValidator.ValidateCbaWordToBaselineWord(tapb, 0, 1); // currently considered punctuation. //FdoValidator.ValidateCbaWordToBaselineWord(tapb, 1, 0); // french word considered punctuation. //FdoValidator.ValidateCbaWordToBaselineWord(tapb, 1, 1); // eng word considered punctuation // FdoValidator.ValidateCbaWordToBaselineWord(tapb, 1, 4); // german word considered punctuation. // validate the rest tapb.ValidateAnnotations(); // 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; CheckExpectedWordformsAndOccurrences(pb.ActualParagraph, expectedOccurrences); // replace the german occurrence of "xxkal" with a xkal version. int wsDe; FdoValidator.GetTssStringValue(tapb, 2, 0, out wsDe); int wsVernDef = Cache.DefaultVernWs; Assert.AreNotEqual(wsVernDef, wsDe, "Precondition: did not expect to have a default vern ws."); pb.ReplaceSegmentForm(2, 0, "xxkal", wsVernDef); var segformNode = pb.SegmentFormNode(2, 0); // Now it should parse as a wfic. var linkNode = segformNode.SelectSingleNode("AnnotationType34/Link"); linkNode.Attributes["guid"].Value = ParagraphBuilder.WficGuid; linkNode.Attributes["name"].Value = "Wordform In Context"; expectedOccurrences.Remove("xxkal" + wsDe.ToString()); expectedOccurrences["xxkal" + wsVernDef.ToString()] += 1; pb.RebuildParagraphContentFromAnnotations(true); pb.ParseParagraph(); int wsAnalysis2_0; FdoValidator.GetTssStringValue(tapb, 2, 0, out wsAnalysis2_0); Assert.AreEqual(Cache.DefaultVernWs, wsAnalysis2_0, "Precondition: expected to have default vern ws."); FdoValidator.ValidateCbaWordToBaselineWord(tapb, 2, 0); // validate the rest. tapb.ValidateAnnotations(); CheckExpectedWordformsAndOccurrences(pb.ActualParagraph, expectedOccurrences); }
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 Phrase_MakeAndBreak_UndoRedo() { CheckDisposed(); // 1. Make Phrases IList<int[]> secondaryPathsToJoinWords = new List<int[]>(); IList<int[]> secondaryPathsToBreakPhrases = new List<int[]>(); WordformInventory wfi = m_fdoCache.LangProject.WordformInventoryOA as WordformInventory; ParagraphBuilder pb = new ParagraphBuilder(m_textsDefn, m_text1, (int)Text1ParaIndex.PhraseWordforms); ParagraphAnnotatorForParagraphBuilder tapb = new ParagraphAnnotatorForParagraphBuilder(pb); XmlNode paraDef0 = pb.ParagraphDefinition.CloneNode(true); XmlNode paraDef_afterJoin1_2; using (new UndoRedoTaskHelper(Cache, "Phrase_MakeAndBreak_UndoRedo_Join", "Phrase_MakeAndBreak_UndoRedo_Join")) { // xxxpus xxxyalola xxxnihimbilira. xxxpus xxxyalola [xxxhesyla xxxnihimbilira]. xxxpus xxxyalola xxxnihimbilira tapb.MergeAdjacentAnnotations(1, 2, secondaryPathsToJoinWords, secondaryPathsToBreakPhrases); tapb.ValidateAnnotations(); paraDef_afterJoin1_2 = pb.ParagraphDefinition.CloneNode(true) ; } UndoResult ures; Cache.Undo(out ures); WordformInventory.OnChangedWordformsOC(); pb.ParagraphDefinition = paraDef0; pb.ParseParagraph(false, false, false); tapb.ValidateAnnotations(); Cache.Redo(out ures); WordformInventory.OnChangedWordformsOC(); pb.ParagraphDefinition = paraDef_afterJoin1_2; pb.ParseParagraph(false, false, false); tapb.ValidateAnnotations(); paraDef_afterJoin1_2 = pb.ParagraphDefinition.CloneNode(true); XmlNode paraDef_afterBreak1_2; using (new UndoRedoTaskHelper(Cache, "Phrase_MakeAndBreak_UndoRedo_Break", "Phrase_MakeAndBreak_UndoRedo_Break")) { // xxxpus xxxyalola xxxnihimbilira. xxxpus xxxyalola /xxxhesyla/ /xxxnihimbilira/. xxxpus xxxyalola xxxnihimbilira secondaryPathsToJoinWords.Clear(); secondaryPathsToBreakPhrases.Clear(); tapb.BreakPhrase(1, 2, secondaryPathsToBreakPhrases, secondaryPathsToJoinWords, null); tapb.ValidateAnnotations(); paraDef_afterBreak1_2 = pb.ParagraphDefinition.CloneNode(true); } Cache.Undo(out ures); WordformInventory.OnChangedWordformsOC(); pb.ParagraphDefinition = paraDef_afterJoin1_2; pb.ParseParagraph(false, false, false); tapb.ValidateAnnotations(); Cache.Redo(out ures); WordformInventory.OnChangedWordformsOC(); pb.ParagraphDefinition = paraDef_afterBreak1_2; pb.ParseParagraph(false, false, false); tapb.ValidateAnnotations(); }