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 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 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 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(); }
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(); }
//[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 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_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 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 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."); }
//[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(); }