public void TwoWordforms() { int hvoBearTEST = CheckAnalysisSize("bearTEST", 0, true); int hvoBullTEST = CheckAnalysisSize("bullTEST", 0, true); string xmlFragment = ""; using (FdoCache cache = FdoCache.Create("TestLangProj")) { ILexDb ldb = cache.LangProject.LexDbOA; // Bear ILexEntry bearN = (ILexEntry)ldb.EntriesOC.Add(new LexEntry()); AddIdToList(bearN.Hvo); IMoStemAllomorph bearNForm = (IMoStemAllomorph)bearN.AlternateFormsOS.Append(new MoStemAllomorph()); bearNForm.Form.VernacularDefaultWritingSystem = "bearNTEST"; IMoStemMsa bearNMSA = (IMoStemMsa)bearN.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); // Bull ILexEntry bullN = (ILexEntry)ldb.EntriesOC.Add(new LexEntry()); AddIdToList(bullN.Hvo); IMoStemAllomorph bullNForm = (IMoStemAllomorph)bullN.AlternateFormsOS.Append(new MoStemAllomorph()); bullNForm.Form.VernacularDefaultWritingSystem = "bullNTEST"; IMoStemMsa bullNMSA = (IMoStemMsa)bullN.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); xmlFragment = "<Wordform DbRef='" + hvoBearTEST.ToString() + "' Form='bearTEST'>\n" + "<WfiAnalysis>\n" + "<Morphs>\n" + "<Morph>\n" + "<MoForm DbRef='" + bearNForm.Hvo.ToString() + "' Label='bearNTEST'/>\n" + "<MSI DbRef='" + bearNMSA.Hvo.ToString() + "'/>\n" + "</Morph>\n" + "</Morphs>\n" + "</WfiAnalysis>\n" + "</Wordform>\n" + "<Wordform DbRef='" + hvoBullTEST.ToString() + "' Form='bullTEST'>\n" + "<WfiAnalysis>\n" + "<Morphs>\n" + "<Morph>\n" + "<MoForm DbRef='" + bullNForm.Hvo.ToString() + "' Label='bullNTEST'/>\n" + "<MSI DbRef='" + bullNMSA.Hvo.ToString() + "'/>\n" + "</Morph>\n" + "</Morphs>\n" + "</WfiAnalysis>\n" + "</Wordform>\n"; } m_filer.ProcessParse(MakeXML(xmlFragment, true)); CheckAnalysisSize("bearTEST", 1, false); CheckAnalysisSize("bullTEST", 1, false); }
public void HumanHasNoopinionParserHadApprovedButNoLongerApprovesRemovesAnalysis() { IWfiWordform threeLittlePigs = CheckAnalysisSize("threeLittlePigsTEST", 0, true); ParseResult result = null; IWfiAnalysis anal = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Pig entry ILexEntry pigN = m_entryFactory.Create(); IMoStemAllomorph pigNForm = m_stemAlloFactory.Create(); pigN.AlternateFormsOS.Add(pigNForm); pigNForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("pigNTEST", m_vernacularWS.Handle); IMoStemMsa pigNMsa = m_stemMsaFactory.Create(); pigN.MorphoSyntaxAnalysesOC.Add(pigNMsa); ILexSense pigNSense = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create(); pigN.SensesOS.Add(pigNSense); // Human no-opinion anal. Parser had approved, but then it failed to produce it. var analFactory = Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>(); var mbFactory = Cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>(); // Human no-opinion anal. Parser had approved, but then it failed to produce it. anal = analFactory.Create(); threeLittlePigs.AnalysesOC.Add(anal); IWfiMorphBundle mb = mbFactory.Create(); anal.MorphBundlesOS.Add(mb); mb.MorphRA = pigNForm; mb.MsaRA = pigNMsa; HumanAgent.SetEvaluation(anal, Opinions.noopinion); ParserAgent.SetEvaluation(anal, Opinions.approves); CheckEvaluationSize(anal, 1, true, "anal"); CheckAnalysisSize("threeLittlePigsTEST", 1, true); result = new ParseResult(Enumerable.Empty <ParseAnalysis>()); }); m_filer.ProcessParse(threeLittlePigs, ParserPriority.Low, result); ExecuteIdleQueue(); Assert.IsFalse(anal.IsValidObject, "analysis should end up with no evaluations and be deleted."); }
private bool CheckForStemDataLoss(IMoStemAllomorph stem, List<IMoMorphSynAnalysis> rgmsaStem) { bool fLoseStemName = stem.StemNameRA != null; bool fLoseGramInfo = false; for (int i = 0; i < rgmsaStem.Count; ++i) { var msa = rgmsaStem[i] as IMoStemMsa; if (msa != null && (msa.FromPartsOfSpeechRC.Count > 0 || msa.InflectionClassRA != null || msa.ProdRestrictRC.Count > 0 || msa.StratumRA != null || msa.MsFeaturesOA != null)) { fLoseGramInfo = true; break; } } if (fLoseStemName || fLoseGramInfo) { string sMsg; if (fLoseStemName && fLoseGramInfo) sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseStemNameGramInfo", m_ksPath); else if (fLoseStemName) sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseStemName", m_ksPath); else sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseGramInfo", m_ksPath); string sCaption = m_mediator.StringTbl.GetStringWithXPath("ChangeLexemeMorphTypeCaption", m_ksPath); DialogResult result = MessageBox.Show(sMsg, sCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.No) { return true; } } return false; }
private void SetMorphType(IMoStemAllomorph allomorph, Guid guidType) { allomorph.MorphTypeRA = Cache.ServiceLocator.GetInstance<IMoMorphTypeRepository>().GetObject(guidType); }
private void ValidateSenseWithAnalysis(ILexSense sense, WfiGloss wfiGloss, int hvoSbWordPos, bool fMatchMainPossibility, IMoStemAllomorph allomorph) { WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis; CompareTss(sense.Gloss.GetAlternativeTss(Cache.DefaultAnalWs), wfiGloss.Form.GetAlternativeTss(Cache.DefaultAnalWs)); // make sure the morph is linked to the lexicon sense, msa, and part of speech. IWfiMorphBundle morphBundle = wfiAnalysis.MorphBundlesOS[0]; Assert.AreEqual(sense.Hvo, morphBundle.SenseRAHvo); Assert.AreEqual(sense.MorphoSyntaxAnalysisRAHvo, morphBundle.MsaRAHvo); if (!fMatchMainPossibility) { // expect exact possibility Assert.AreEqual(hvoSbWordPos, (sense.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRAHvo); } else { IPartOfSpeech posTarget = PartOfSpeech.CreateFromDBObject(Cache, hvoSbWordPos); Assert.AreEqual(posTarget.MainPossibility.Hvo, (sense.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRA.MainPossibility.Hvo); } Assert.AreEqual(allomorph.Hvo, morphBundle.MorphRAHvo); Assert.AreEqual(hvoSbWordPos, wfiAnalysis.CategoryRAHvo); }
private void ValidateSenseWithAnalysis(ILexSense sense, IWfiGloss wfiGloss, int hvoSbWordPos, bool fMatchMainPossibility, IMoStemAllomorph allomorph) { IWfiAnalysis wfiAnalysis = wfiGloss.Owner as IWfiAnalysis; CompareTss(sense.Gloss.get_String(Cache.DefaultAnalWs), wfiGloss.Form.get_String(Cache.DefaultAnalWs)); // make sure the morph is linked to the lexicon sense, msa, and part of speech. IWfiMorphBundle morphBundle = wfiAnalysis.MorphBundlesOS[0]; Assert.AreEqual(sense, morphBundle.SenseRA); Assert.AreEqual(sense.MorphoSyntaxAnalysisRA, morphBundle.MsaRA); if (!fMatchMainPossibility) { // expect exact possibility Assert.AreEqual(hvoSbWordPos, (sense.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA.Hvo); } else { IPartOfSpeech posTarget = Cache.ServiceLocator.GetInstance<IPartOfSpeechRepository>().GetObject(hvoSbWordPos); Assert.AreEqual(posTarget.MainPossibility, (sense.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA.MainPossibility); } Assert.AreEqual(allomorph, morphBundle.MorphRA); Assert.AreEqual(hvoSbWordPos, wfiAnalysis.CategoryRA.Hvo); }
public void DuplicateAnalysesApproval() { int hvoBearTEST = CheckAnalysisSize("bearTEST", 0, true); string xmlFragment = ""; int anal1Hvo; int anal2Hvo; int anal3Hvo; using (FdoCache cache = FdoCache.Create("TestLangProj")) { IWfiAnalysis anal = null; ILexDb ldb = cache.LangProject.LexDbOA; // Bear entry ILexEntry bearN = (ILexEntry)ldb.EntriesOC.Add(new LexEntry()); AddIdToList(bearN.Hvo); IMoStemAllomorph bearNForm = (IMoStemAllomorph)bearN.AlternateFormsOS.Append(new MoStemAllomorph()); bearNForm.Form.VernacularDefaultWritingSystem = "bearNTEST"; IMoStemMsa bearNMSA = (IMoStemMsa)bearN.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); ILexSense bearNLS = (ILexSense)bearN.SensesOS.Append(new LexSense());; IWfiWordform wf = WfiWordform.CreateFromDBObject(cache, hvoBearTEST); // First of two duplicate analyses anal = (IWfiAnalysis)wf.AnalysesOC.Add(new WfiAnalysis()); anal1Hvo = anal.Hvo; IWfiMorphBundle mb = (IWfiMorphBundle)anal.MorphBundlesOS.Append(new WfiMorphBundle()); mb.MorphRA = bearNForm; mb.MsaRA = bearNMSA; CheckEvaluationSize(anal1Hvo, 0, true, "anal1Hvo"); // Non-duplicate, to make sure it does not get approved. anal = (IWfiAnalysis)wf.AnalysesOC.Add(new WfiAnalysis()); anal2Hvo = anal.Hvo; mb = (IWfiMorphBundle)anal.MorphBundlesOS.Append(new WfiMorphBundle()); mb.SenseRA = bearNLS; CheckEvaluationSize(anal2Hvo, 0, true, "anal2Hvo"); // Second of two duplicate analyses anal = (IWfiAnalysis)wf.AnalysesOC.Add(new WfiAnalysis()); anal3Hvo = anal.Hvo; mb = (IWfiMorphBundle)anal.MorphBundlesOS.Append(new WfiMorphBundle()); mb.MorphRA = bearNForm; mb.MsaRA = bearNMSA; CheckEvaluationSize(anal3Hvo, 0, true, "anal3Hvo"); CheckAnalysisSize("bearTEST", 3, false); xmlFragment = "<Wordform DbRef='" + hvoBearTEST.ToString() + "' Form='bearTEST'>\n" + "<WfiAnalysis>\n" + "<Morphs>\n" + "<Morph>\n" + "<MoForm DbRef='" + bearNForm.Hvo.ToString() + "' Label='bearNTEST'/>\n" + "<MSI DbRef='" + bearNMSA.Hvo.ToString() + "'/>\n" + "</Morph>\n" + "</Morphs>\n" + "</WfiAnalysis>\n" + "</Wordform>\n"; } m_filer.ProcessParse(MakeXML(xmlFragment, true)); CheckEvaluationSize(anal1Hvo, 1, false, "anal1Hvo"); CheckEvaluationSize(anal2Hvo, 0, false, "anal2Hvo"); CheckEvaluationSize(anal3Hvo, 1, false, "anal3Hvo"); }
public void TwoAnalyses() { int hvoBearTEST = CheckAnalysisSize("bearsTEST", 0, true); string xmlFragment = ""; using (FdoCache cache = FdoCache.Create("TestLangProj")) { ILexDb ldb = cache.LangProject.LexDbOA; // Noun ILexEntry bearN = (ILexEntry)ldb.EntriesOC.Add(new LexEntry()); AddIdToList(bearN.Hvo); IMoStemAllomorph bearNForm = (IMoStemAllomorph)bearN.AlternateFormsOS.Append(new MoStemAllomorph()); bearNForm.Form.VernacularDefaultWritingSystem = "bearNTEST"; IMoStemMsa bearNMSA = (IMoStemMsa)bearN.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); ILexEntry sPL = (ILexEntry)ldb.EntriesOC.Add(new LexEntry()); AddIdToList(sPL.Hvo); IMoAffixAllomorph sPLForm = (IMoAffixAllomorph)sPL.AlternateFormsOS.Append(new MoAffixAllomorph()); sPLForm.Form.VernacularDefaultWritingSystem = "sPLTEST"; IMoInflAffMsa sPLMSA = (IMoInflAffMsa)sPL.MorphoSyntaxAnalysesOC.Add(new MoInflAffMsa()); // Verb ILexEntry bearV = (ILexEntry)ldb.EntriesOC.Add(new LexEntry()); AddIdToList(bearV.Hvo); IMoStemAllomorph bearVForm = (IMoStemAllomorph)bearV.AlternateFormsOS.Append(new MoStemAllomorph()); bearVForm.Form.VernacularDefaultWritingSystem = "bearVTEST"; IMoStemMsa bearVMSA = (IMoStemMsa)bearV.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); ILexEntry sAGR = (ILexEntry)ldb.EntriesOC.Add(new LexEntry()); AddIdToList(sAGR.Hvo); IMoAffixAllomorph sAGRForm = (IMoAffixAllomorph)sAGR.AlternateFormsOS.Append(new MoAffixAllomorph()); sAGRForm.Form.VernacularDefaultWritingSystem = "sAGRTEST"; IMoInflAffMsa sAGRMSA = (IMoInflAffMsa)sAGR.MorphoSyntaxAnalysesOC.Add(new MoInflAffMsa()); xmlFragment = "<Wordform DbRef='" + hvoBearTEST.ToString() + "' Form='bearsTEST'>\n" + "<WfiAnalysis>\n" + "<Morphs>\n" + "<Morph>\n" + "<MoForm DbRef='" + bearNForm.Hvo.ToString() + "' Label='bearNTEST'/>\n" + "<MSI DbRef='" + bearNMSA.Hvo.ToString() + "'/>\n" + "</Morph>\n" + "<Morph>\n" + "<MoForm DbRef='" + sPLForm.Hvo.ToString() + "' Label='sPLTEST'/>\n" + "<MSI DbRef='" + sPLMSA.Hvo.ToString() + "'/>\n" + "</Morph>\n" + "</Morphs>\n" + "</WfiAnalysis>\n" + "<WfiAnalysis>\n" + "<Morphs>\n" + "<Morph>\n" + "<MoForm DbRef='" + bearVForm.Hvo.ToString() + "' Label='bearVTEST'/>\n" + "<MSI DbRef='" + bearVMSA.Hvo.ToString() + "'/>\n" + "</Morph>\n" + "<Morph>\n" + "<MoForm DbRef='" + sAGRForm.Hvo.ToString() + "' Label='sAGRTEST'/>\n" + "<MSI DbRef='" + sAGRMSA.Hvo.ToString() + "'/>\n" + "</Morph>\n" + "</Morphs>\n" + "</WfiAnalysis>\n" + "</Wordform>\n"; } m_filer.ProcessParse(MakeXML(xmlFragment, true)); CheckAnalysisSize("bearsTEST", 2, false); }
public void LexEntryInflTypeTwoAnalyses() { IWfiWordform creb = CheckAnalysisSize("crebTEST", 0, true); ILexDb ldb = Cache.LanguageProject.LexDbOA; ParseResult result = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Verb creb which is a past tense, plural irregularly inflected form of 'believe' and also 'seek' // with automatically generated null Tense slot and an automatically generated null Number slot filler // (This is not supposed to be English, in case you're wondering....) ILexEntryInflType pastTenseLexEntryInflType = m_lexEntryInflTypeFactory.Create(); ILexEntryInflType pluralTenseLexEntryInflType = m_lexEntryInflTypeFactory.Create(); Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS.Add(pastTenseLexEntryInflType); Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS.Add(pluralTenseLexEntryInflType); ILexEntry believeV = m_entryFactory.Create(); IMoStemAllomorph believeVForm = m_stemAlloFactory.Create(); believeV.AlternateFormsOS.Add(believeVForm); believeVForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("believeVTEST", m_vernacularWS.Handle); IMoStemMsa believeVMsa = m_stemMsaFactory.Create(); believeV.MorphoSyntaxAnalysesOC.Add(believeVMsa); ILexSense believeVSense = m_senseFactory.Create(); believeV.SensesOS.Add(believeVSense); believeVSense.MorphoSyntaxAnalysisRA = believeVMsa; ILexEntry seekV = m_entryFactory.Create(); IMoStemAllomorph seekVForm = m_stemAlloFactory.Create(); believeV.AlternateFormsOS.Add(seekVForm); seekVForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("seekVTEST", m_vernacularWS.Handle); IMoStemMsa seekVMsa = m_stemMsaFactory.Create(); seekV.MorphoSyntaxAnalysesOC.Add(seekVMsa); ILexSense seekVSense = m_senseFactory.Create(); seekV.SensesOS.Add(seekVSense); seekVSense.MorphoSyntaxAnalysisRA = seekVMsa; ILexEntry crebV = m_entryFactory.Create(); IMoStemAllomorph crebVForm = m_stemAlloFactory.Create(); crebV.AlternateFormsOS.Add(crebVForm); crebVForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("crebVTEST", m_vernacularWS.Handle); ILexEntryRef lexEntryref = m_lexEntryRefFactory.Create(); crebV.EntryRefsOS.Add(lexEntryref); lexEntryref.ComponentLexemesRS.Add(believeV); lexEntryref.VariantEntryTypesRS.Add(pastTenseLexEntryInflType); lexEntryref.VariantEntryTypesRS.Add(pluralTenseLexEntryInflType); lexEntryref = m_lexEntryRefFactory.Create(); crebV.EntryRefsOS.Add(lexEntryref); lexEntryref.ComponentLexemesRS.Add(seekV); lexEntryref.VariantEntryTypesRS.Add(pastTenseLexEntryInflType); lexEntryref.VariantEntryTypesRS.Add(pluralTenseLexEntryInflType); ILexEntry nullPast = m_entryFactory.Create(); IMoAffixAllomorph nullPastForm = m_afxAlloFactory.Create(); nullPast.AlternateFormsOS.Add(nullPastForm); nullPastForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("nullPASTTEST", m_vernacularWS.Handle); IMoInflAffMsa nullPastMsa = m_inflAffMsaFactory.Create(); nullPast.MorphoSyntaxAnalysesOC.Add(nullPastMsa); ILexEntry nullPlural = m_entryFactory.Create(); IMoAffixAllomorph nullPluralForm = m_afxAlloFactory.Create(); nullPlural.AlternateFormsOS.Add(nullPluralForm); nullPluralForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("nullPLURALTEST", m_vernacularWS.Handle); IMoInflAffMsa nullPluralMsa = m_inflAffMsaFactory.Create(); nullPlural.MorphoSyntaxAnalysesOC.Add(nullPluralMsa); result = new ParseResult(new[] { new ParseAnalysis(new[] { new ParseMorph(crebVForm, MorphServices.GetMainOrFirstSenseOfVariant(crebV.EntryRefsOS[1]).MorphoSyntaxAnalysisRA, (ILexEntryInflType)crebV.EntryRefsOS[1].VariantEntryTypesRS[0]) }), new ParseAnalysis(new[] { new ParseMorph(crebVForm, MorphServices.GetMainOrFirstSenseOfVariant(crebV.EntryRefsOS[0]).MorphoSyntaxAnalysisRA, (ILexEntryInflType)crebV.EntryRefsOS[0].VariantEntryTypesRS[0]) }) }); }); m_filer.ProcessParse(creb, ParserPriority.Low, result); ExecuteIdleQueue(); CheckAnalysisSize("crebTEST", 2, false); foreach (var analysis in creb.AnalysesOC) { Assert.AreEqual(1, analysis.MorphBundlesOS.Count, "Expected only 1 morph in the analysis"); var morphBundle = analysis.MorphBundlesOS.ElementAt(0); Assert.IsNotNull(morphBundle.Form, "First bundle: form is not null"); Assert.IsNotNull(morphBundle.MsaRA, "First bundle: msa is not null"); Assert.IsNotNull(morphBundle.InflTypeRA, "First bundle: infl type is not null"); } }
private void CacheEnvironments(IMoStemAllomorph allomorph) { CacheEnvironments(allomorph.PhoneEnvRC.ToHvoArray()); AppendPhoneEnv(kDummyPhoneEnvID, null); }