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 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."); }