/// <summary> /// Given a (potentially) owning object, and the flid in which is does/will own /// the feature structure, find the relevant POS. /// </summary> /// <param name="cobj"></param> /// <param name="owningFlid"></param> /// <returns></returns> private IPartOfSpeech GetPosFromCmObjectAndFlid(ICmObject cobj, int owningFlid) { IPartOfSpeech pos = null; switch (cobj.ClassID) { case MoInflAffMsa.kclsidMoInflAffMsa: IMoInflAffMsa infl = cobj as IMoInflAffMsa; if (infl != null) { pos = infl.PartOfSpeechRA; } break; case MoDerivAffMsa.kclsidMoDerivAffMsa: IMoDerivAffMsa deriv = cobj as IMoDerivAffMsa; if (deriv != null) { if (owningFlid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromMsFeatures) { pos = deriv.FromPartOfSpeechRA; } else if (owningFlid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidToMsFeatures) { pos = deriv.ToPartOfSpeechRA; } } break; case MoStemMsa.kclsidMoStemMsa: IMoStemMsa stem = cobj as IMoStemMsa; if (stem != null) { pos = stem.PartOfSpeechRA; } break; case MoStemName.kclsidMoStemName: IMoStemName sn = cobj as IMoStemName; pos = PartOfSpeech.CreateFromDBObject(sn.Cache, sn.OwnerHVO); break; case MoAffixAllomorph.kclsidMoAffixAllomorph: // get entry of the allomorph and then get the msa of first sense and return its (from) POS ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, cobj.OwnerHVO); if (entry == null) { return(pos); } ILexSense sense = entry.SensesOS.FirstItem; if (sense == null) { return(pos); } IMoMorphSynAnalysis msa = sense.MorphoSyntaxAnalysisRA; pos = GetPosFromCmObjectAndFlid(msa, (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromMsFeatures); break; } return(pos); }
private void InitMsa(IMoStemMsa msmTarget, int hvoPos) { msmTarget.PartOfSpeechRA = m_cache.ServiceLocator.GetObject(hvoPos) as IPartOfSpeech; var newFeatures = (IFsFeatStruc)m_cache.ServiceLocator.GetObject(m_selectedHvo); msmTarget.CopyMsFeatures(newFeatures); }
public void MergeReferenceAtomic() { CheckDisposed(); // 24 LexSense.MorphoSyntaxAnalysis (refers to MSA) ILexEntry lme = m_entriesCol.Add(new LexEntry()); ILexSense lsKeeper = lme.SensesOS.Append(new LexSense()); ILexSense lsSrc = lme.SensesOS.Append(new LexSense()); IMoStemMsa msa1 = (IMoStemMsa)lme.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); IMoStemMsa msa2 = (IMoStemMsa)lme.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); // Merge content into null. lsSrc.MorphoSyntaxAnalysisRAHvo = msa1.Hvo; lsKeeper.MergeObject(lsSrc); Assert.AreEqual(msa1.Hvo, lsKeeper.MorphoSyntaxAnalysisRAHvo); // Merge content into content. lsKeeper.MorphoSyntaxAnalysisRAHvo = msa1.Hvo; lsSrc = lme.SensesOS.Append(new LexSense()); lsSrc.MorphoSyntaxAnalysisRAHvo = msa2.Hvo; lsKeeper.MergeObject(lsSrc); Assert.AreEqual(msa1.Hvo, lsKeeper.MorphoSyntaxAnalysisRAHvo); // Merge null into content. lsKeeper.MorphoSyntaxAnalysisRAHvo = msa1.Hvo; lsSrc = lme.SensesOS.Append(new LexSense()); lsSrc.MorphoSyntaxAnalysisRA = null; lsKeeper.MergeObject(lsSrc); Assert.AreEqual(msa1.Hvo, lsKeeper.MorphoSyntaxAnalysisRAHvo); }
private void RemoveFeatureStructureFromMSA() { if (m_obj != null) { switch (m_obj.ClassID) { case FDO.Ling.MoStemMsa.kclsidMoStemMsa: IMoStemMsa stem = m_obj as IMoStemMsa; stem.MsFeaturesOA = null; break; case FDO.Ling.MoInflAffMsa.kclsidMoInflAffMsa: IMoInflAffMsa infl = m_obj as IMoInflAffMsa; infl.InflFeatsOA = null; break; case FDO.Ling.MoDerivAffMsa.kclsidMoDerivAffMsa: IMoDerivAffMsa derv = m_obj as IMoDerivAffMsa; if (m_flid == (int)FDO.Ling.MoDerivAffMsa.MoDerivAffMsaTags.kflidFromMsFeatures) { derv.FromMsFeaturesOA = null; } else { // assume it's the to features derv.ToMsFeaturesOA = null; } break; } } }
public void MergeOwningCollection() { CheckDisposed(); // 25 LexEntry.MorphoSyntaxAnalyses ILexEntry lmeKeeper = m_entriesCol.Add(new LexEntry()); ILexEntry lmeSrc = m_entriesCol.Add(new LexEntry()); FdoOwningSequence<ICmPossibility> posSeq = Cache.LangProject.PartsOfSpeechOA.PossibilitiesOS; posSeq.Append(new PartOfSpeech()); posSeq.Append(new PartOfSpeech()); // Merge content into null. IMoStemMsa msaSrc = (IMoStemMsa)lmeSrc.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); msaSrc.PartOfSpeechRA = (IPartOfSpeech)posSeq[0]; lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(1, lmeKeeper.MorphoSyntaxAnalysesOC.Count); Assert.AreEqual(msaSrc.Hvo, lmeKeeper.MorphoSyntaxAnalysesOC.HvoArray[0]); // Merge content into content. lmeSrc = m_entriesCol.Add(new LexEntry()); IMoStemMsa msaSrc2 = (IMoStemMsa)lmeSrc.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); msaSrc2.PartOfSpeechRA = (IPartOfSpeech)posSeq[1]; lmeKeeper.MergeObject(lmeSrc); Assert.AreEqual(2, lmeKeeper.MorphoSyntaxAnalysesOC.Count); }
private void RemoveFeatureStructureFromMSA() { if (m_obj != null) { NonUndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(m_cache.ServiceLocator.GetInstance <IActionHandler>(), () => { switch (m_obj.ClassID) { case MoStemMsaTags.kClassId: IMoStemMsa stem = m_obj as IMoStemMsa; stem.MsFeaturesOA = null; break; case MoInflAffMsaTags.kClassId: IMoInflAffMsa infl = m_obj as IMoInflAffMsa; infl.InflFeatsOA = null; break; case MoDerivAffMsaTags.kClassId: IMoDerivAffMsa derv = m_obj as IMoDerivAffMsa; if (m_flid == MoDerivAffMsaTags.kflidFromMsFeatures) { derv.FromMsFeaturesOA = null; } else { // assume it's the to features derv.ToMsFeaturesOA = null; } break; } }); } }
public void TwoAnalyses() { IWfiWordform catsTest = CheckAnalysisSize("catsTEST", 0, true); ILexDb ldb = Cache.LanguageProject.LexDbOA; ParseResult result = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Noun ILexEntry catN = m_entryFactory.Create(); IMoStemAllomorph catNForm = m_stemAlloFactory.Create(); catN.AlternateFormsOS.Add(catNForm); catNForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("catNTEST", m_vernacularWS.Handle); IMoStemMsa catNMsa = m_stemMsaFactory.Create(); catN.MorphoSyntaxAnalysesOC.Add(catNMsa); ILexEntry sPl = m_entryFactory.Create(); IMoAffixAllomorph sPlForm = m_afxAlloFactory.Create(); sPl.AlternateFormsOS.Add(sPlForm); sPlForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("sPLTEST", m_vernacularWS.Handle); IMoInflAffMsa sPlMsa = m_inflAffMsaFactory.Create(); sPl.MorphoSyntaxAnalysesOC.Add(sPlMsa); // Verb ILexEntry catV = m_entryFactory.Create(); IMoStemAllomorph catVForm = m_stemAlloFactory.Create(); catV.AlternateFormsOS.Add(catVForm); catVForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("catVTEST", m_vernacularWS.Handle); IMoStemMsa catVMsa = m_stemMsaFactory.Create(); catV.MorphoSyntaxAnalysesOC.Add(catVMsa); ILexEntry sAgr = m_entryFactory.Create(); IMoAffixAllomorph sAgrForm = m_afxAlloFactory.Create(); sAgr.AlternateFormsOS.Add(sAgrForm); sAgrForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("sAGRTEST", m_vernacularWS.Handle); IMoInflAffMsa sAgrMsa = m_inflAffMsaFactory.Create(); sAgr.MorphoSyntaxAnalysesOC.Add(sAgrMsa); result = new ParseResult(new[] { new ParseAnalysis(new[] { new ParseMorph(catNForm, catNMsa), new ParseMorph(sPlForm, sPlMsa) }), new ParseAnalysis(new[] { new ParseMorph(catVForm, catVMsa), new ParseMorph(sAgrForm, sAgrMsa) }) }); }); m_filer.ProcessParse(catsTest, ParserPriority.Low, result); ExecuteIdleQueue(); CheckAnalysisSize("catsTEST", 2, false); }
/// <summary> /// Answer true if the selected MSA has an MsFeatures that is the same as the argument. /// </summary> /// <returns></returns> private bool MsaMatchesTarget(IMoStemMsa msm, IFsFeatStruc fsTarget) { if (m_selectedHvo == 0 && msm.MsFeaturesOA == null) { return(true); } if (msm.MsFeaturesOA == null) { return(false); } return(msm.MsFeaturesOA.IsEquivalent(fsTarget)); }
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 MergeAtomicPropertyBackReferences() { CheckDisposed(); ILexEntry lme = m_entriesCol.Add(new LexEntry()); IMoStemMsa msaKeeper = (IMoStemMsa)lme.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); IMoStemMsa msaSrc = (IMoStemMsa)lme.MorphoSyntaxAnalysesOC.Add(new MoStemMsa()); ILexSense ls1 = lme.SensesOS.Append(new LexSense()); ls1.MorphoSyntaxAnalysisRAHvo = msaKeeper.Hvo; ILexSense ls2 = lme.SensesOS.Append(new LexSense()); ls2.MorphoSyntaxAnalysisRAHvo = msaSrc.Hvo; // Shift atomic back reference. msaKeeper.MergeObject(msaSrc); Assert.AreEqual(ls2.MorphoSyntaxAnalysisRAHvo, msaKeeper.Hvo); }
private static void WriteStemMsaXmlElement(XmlWriter writer, IMoStemMsa stemMsa, IEnumerable <ILexEntryRef> variantEntryRefs) { writer.WriteStartElement("stemMsa"); WritePosXmlAttribute(writer, stemMsa.PartOfSpeechRA, "cat"); IMoInflClass inflClass = stemMsa.InflectionClassRA; if (inflClass == null) { // use default inflection class of the POS or // the first ancestor POS that has a non-zero default inflection class int inflClassHvo = 0; IPartOfSpeech pos = stemMsa.PartOfSpeechRA; while (pos != null && inflClassHvo == 0) { if (pos.DefaultInflectionClassRA != null) { inflClassHvo = pos.DefaultInflectionClassRA.Hvo; } else { int clsid = stemMsa.Services.GetInstance <ICmObjectRepository>().GetObject(pos.Owner.Hvo).ClassID; pos = clsid == PartOfSpeechTags.kClassId ? stemMsa.Services.GetInstance <IPartOfSpeechRepository>().GetObject(pos.Owner.Hvo) : null; } } if (inflClassHvo != 0) { inflClass = stemMsa.Services.GetInstance <IMoInflClassRepository>().GetObject(inflClassHvo); } } WriteInflectionClassXmlAttribute(writer, inflClass, "inflClass"); WriteRequiresInflectionXmlAttribute(writer, stemMsa.PartOfSpeechRA); WriteFeatureStructureNodes(writer, stemMsa.MsFeaturesOA, stemMsa.Hvo); WriteProductivityRestrictionNodes(writer, stemMsa.ProdRestrictRC, "productivityRestriction"); WriteFromPosNodes(writer, stemMsa.FromPartsOfSpeechRC, "fromPartsOfSpeech"); foreach (ILexEntryRef entryRef in variantEntryRefs) { foreach (ILexEntryType lexEntryType in entryRef.VariantEntryTypesRS) { var inflEntryType = lexEntryType as ILexEntryInflType; if (inflEntryType != null) { WriteFeatureStructureNodes(writer, inflEntryType.InflFeatsOA, stemMsa.Hvo); } } } writer.WriteEndElement(); //stemMsa }
private bool CheckForStemDataLoss(IMoStemAllomorph stem, List <IMoMorphSynAnalysis> rgmsaStem) { bool fLoseStemName = stem.StemNameRAHvo != 0; bool fLoseGramInfo = false; for (int i = 0; i < rgmsaStem.Count; ++i) { IMoStemMsa msa = rgmsaStem[i] as IMoStemMsa; if (msa != null && msa.FromPartsOfSpeechRC.Count > 0 || msa.InflectionClassRAHvo != 0 || msa.ProdRestrictRC.Count > 0 || msa.StratumRAHvo != 0 || msa.MsFeaturesOAHvo != 0) { 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); }
protected void CreateStemMsaXmlElement(XmlDocument doc, XmlNode morphNode, IMoStemMsa stemMsa) { XmlNode stemMsaNode = CreateXmlElement(doc, "stemMsa", morphNode); CreatePOSXmlAttribute(doc, stemMsaNode, stemMsa.PartOfSpeechRA, "cat"); IMoInflClass inflClass = stemMsa.InflectionClassRA; if (inflClass == null) { // use default inflection class of the POS or // the first ancestor POS that has a non-zero default inflection class int inflClassHvo = 0; IPartOfSpeech pos = stemMsa.PartOfSpeechRA; while (pos != null && inflClassHvo == 0) { if (pos.DefaultInflectionClassRA != null) { inflClassHvo = pos.DefaultInflectionClassRA.Hvo; } else { int clsid = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(pos.Owner.Hvo).ClassID; if (clsid == PartOfSpeechTags.kClassId) { pos = m_cache.ServiceLocator.GetInstance <IPartOfSpeechRepository>().GetObject(pos.Owner.Hvo); } else { pos = null; } } } if (inflClassHvo != 0) { inflClass = m_cache.ServiceLocator.GetInstance <IMoInflClassRepository>().GetObject(inflClassHvo); } } CreateInflectionClassXmlAttribute(doc, stemMsaNode, inflClass, "inflClass"); CreateRequiresInflectionXmlAttribute(doc, stemMsa.PartOfSpeechRA, stemMsaNode); CreateFeatureStructureNodes(doc, stemMsaNode, stemMsa.MsFeaturesOA, stemMsa.Hvo); CreateProductivityRestrictionNodes(doc, stemMsaNode, stemMsa.ProdRestrictRC, "productivityRestriction"); CreateFromPOSNodes(doc, stemMsaNode, stemMsa.FromPartsOfSpeechRC, "fromPartsOfSpeech"); }
public void TwoWordforms() { IWfiWordform snake = CheckAnalysisSize("snakeTEST", 0, true); IWfiWordform bull = CheckAnalysisSize("bullTEST", 0, true); ILexDb ldb = Cache.LanguageProject.LexDbOA; ParseResult result = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Snake ILexEntry snakeN = m_entryFactory.Create(); IMoStemAllomorph snakeNForm = m_stemAlloFactory.Create(); snakeN.AlternateFormsOS.Add(snakeNForm); snakeNForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("snakeNTEST", m_vernacularWS.Handle); IMoStemMsa snakeNMsa = m_stemMsaFactory.Create(); snakeN.MorphoSyntaxAnalysesOC.Add(snakeNMsa); // Bull ILexEntry bullN = m_entryFactory.Create(); IMoStemAllomorph bullNForm = m_stemAlloFactory.Create(); bullN.AlternateFormsOS.Add(bullNForm); bullNForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("bullNTEST", m_vernacularWS.Handle); IMoStemMsa bullNMsa = m_stemMsaFactory.Create(); bullN.MorphoSyntaxAnalysesOC.Add(bullNMsa); result = new ParseResult(new[] { new ParseAnalysis(new[] { new ParseMorph(snakeNForm, snakeNMsa) }), new ParseAnalysis(new[] { new ParseMorph(bullNForm, bullNMsa) }) }); }); m_filer.ProcessParse(snake, ParserPriority.Low, result); ExecuteIdleQueue(); CheckAnalysisSize("snakeTEST", 1, false); CheckAnalysisSize("bullTEST", 1, false); }
public void HumanApprovedParserPreviouslyApprovedButNowRejectedAnalysisSurvives() { IWfiWordform theThreeLittlePigs = CheckAnalysisSize("theThreeLittlePigsTEST", 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 = Cache.TsStrFactory.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 approved anal. Start with parser approved, but then it failed. var analFactory = Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>(); var mbFactory = Cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>(); // Only analysis: human approved, previously parser approved but no longer produced. anal = analFactory.Create(); theThreeLittlePigs.AnalysesOC.Add(anal); IWfiMorphBundle mb = mbFactory.Create(); anal.MorphBundlesOS.Add(mb); mb.MorphRA = pigNForm; mb.MsaRA = pigNMsa; HumanAgent.SetEvaluation(anal, Opinions.approves); ParserAgent.SetEvaluation(anal, Opinions.approves); CheckEvaluationSize(anal, 2, true, "anal"); CheckAnalysisSize("theThreeLittlePigsTEST", 1, true); result = new ParseResult(Enumerable.Empty <ParseAnalysis>()); }); m_filer.ProcessParse(theThreeLittlePigs, ParserPriority.Low, result); ExecuteIdleQueue(); CheckEvaluationSize(anal, 2, false, "analHvo"); Assert.IsTrue(anal.IsValidObject, "analysis should end up with one evaluation and not be deleted"); }
/// <summary> /// This overload finds guesses for wordforms specified in a dictionary that maps a wordform to the /// string that we want to match (might be a different case form). /// </summary> /// <param name="wordsToMatch"></param> /// <returns></returns> private Dictionary <IWfiWordform, EmptyWwfInfo> MapWordsForComputerGuessesToBestMatchingEntry(Dictionary <IWfiWordform, ITsString> wordsToMatch) { var matchingMorphs = new Dictionary <ITsString, IMoStemAllomorph>(new TsStringEquator()); foreach (var tssWord in wordsToMatch.Values) { matchingMorphs[tssWord] = null; } MorphServices.GetMatchingMonomorphemicMorphs(Cache, matchingMorphs); var mapEmptyWfInfo = new Dictionary <IWfiWordform, EmptyWwfInfo>(); foreach (var kvp in wordsToMatch) { var word = kvp.Key; var tssWord = kvp.Value; var bestMatchingMorph = matchingMorphs[tssWord]; if (bestMatchingMorph != null) { var entryOrVariant = bestMatchingMorph.OwnerOfClass <ILexEntry>(); ILexEntry mainEntry; ILexSense sense; GetMainEntryAndSense(entryOrVariant, out mainEntry, out sense); if (sense == null && mainEntry.SensesOS.Count > 0) { sense = mainEntry.SensesOS.Where(s => s.MorphoSyntaxAnalysisRA is IMoStemMsa) .FirstOrDefault(); } IMoStemMsa msa = null; IPartOfSpeech pos = null; if (sense != null) { msa = (IMoStemMsa)sense.MorphoSyntaxAnalysisRA; pos = msa.PartOfSpeechRA; } // map the word to its best entry. var entryInfo = new EmptyWwfInfo(bestMatchingMorph, msa, pos, sense); mapEmptyWfInfo.Add(word, entryInfo); } } return(mapEmptyWfInfo); }
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 static void WriteStemMsaXmlElement(XmlWriter writer, IMoStemMsa stemMsa, IEnumerable<ILexEntryRef> variantEntryRefs) { writer.WriteStartElement("stemMsa"); WritePosXmlAttribute(writer, stemMsa.PartOfSpeechRA, "cat"); IMoInflClass inflClass = stemMsa.InflectionClassRA; if (inflClass == null) { // use default inflection class of the POS or // the first ancestor POS that has a non-zero default inflection class int inflClassHvo = 0; IPartOfSpeech pos = stemMsa.PartOfSpeechRA; while (pos != null && inflClassHvo == 0) { if (pos.DefaultInflectionClassRA != null) inflClassHvo = pos.DefaultInflectionClassRA.Hvo; else { int clsid = stemMsa.Services.GetInstance<ICmObjectRepository>().GetObject(pos.Owner.Hvo).ClassID; pos = clsid == PartOfSpeechTags.kClassId ? stemMsa.Services.GetInstance<IPartOfSpeechRepository>().GetObject(pos.Owner.Hvo) : null; } } if (inflClassHvo != 0) inflClass = stemMsa.Services.GetInstance<IMoInflClassRepository>().GetObject(inflClassHvo); } WriteInflectionClassXmlAttribute(writer, inflClass, "inflClass"); WriteRequiresInflectionXmlAttribute(writer, stemMsa.PartOfSpeechRA); WriteFeatureStructureNodes(writer, stemMsa.MsFeaturesOA, stemMsa.Hvo); WriteProductivityRestrictionNodes(writer, stemMsa.ProdRestrictRC, "productivityRestriction"); WriteFromPosNodes(writer, stemMsa.FromPartsOfSpeechRC, "fromPartsOfSpeech"); foreach (ILexEntryRef entryRef in variantEntryRefs) { foreach (ILexEntryType lexEntryType in entryRef.VariantEntryTypesRS) { var inflEntryType = lexEntryType as ILexEntryInflType; if (inflEntryType != null) WriteFeatureStructureNodes(writer, inflEntryType.InflFeatsOA, stemMsa.Hvo); } } writer.WriteEndElement(); //stemMsa }
protected void CreateMsaXmlElement(XmlNode node, XmlDocument doc, XmlNode morphNode, string sHvo) { XmlNode attr; // morphname contains the hvo of the msa attr = node.SelectSingleNode(sHvo); if (attr != null) { ICmObject obj = CmObject.CreateFromDBObject(m_cache, Convert.ToInt32(attr.Value)); switch (obj.GetType().Name) { default: throw new ApplicationException(String.Format("Invalid MSA type: {0}.", obj.GetType().Name)); case "MoStemMsa": IMoStemMsa stemMsa = obj as IMoStemMsa; CreateStemMsaXmlElement(doc, morphNode, stemMsa); break; case "MoInflAffMsa": IMoInflAffMsa inflMsa = obj as IMoInflAffMsa; CreateInflectionClasses(doc, morphNode); CreateInflMsaXmlElement(doc, morphNode, inflMsa); break; case "MoDerivAffMsa": IMoDerivAffMsa derivMsa = obj as IMoDerivAffMsa; CreateDerivMsaXmlElement(doc, morphNode, derivMsa); break; case "MoUnclassifiedAffixMsa": IMoUnclassifiedAffixMsa unclassMsa = obj as IMoUnclassifiedAffixMsa; CreateUnclassifedMsaXmlElement(doc, morphNode, unclassMsa); break; } } }
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"); } }
/// <summary> /// Execute the change requested by the current selection in the combo. /// Basically we want the MoInflClass indicated by m_selectedHvo, (even if 0?? not yet possible), /// to become the InflectionClass of each record that is appropriate to change. /// We do nothing to records where the check box is turned off, /// and nothing to ones that currently have an MSA other than an MoStemMsa, /// and nothing to ones that currently have an MSA with the wrong POS. /// (a) If the owning entry has an MoStemMsa with the right inflection class (and presumably POS), /// set the sense to use it. /// (b) If all senses using the current MoStemMsa are to be changed, just update /// the inflection class of that MoStemMsa. /// We could add this...but very probably unused MSAs would have been taken over /// when setting the POS. /// --(c) If the entry has an MoStemMsa which is not being used at all, change it to /// --the required POS and inflection class and use it. /// (d) Make a new MoStemMsa in the LexEntry with the required POS and inflection class /// and point the sense at it. /// </summary> public void DoIt(Set <int> itemsToChange, ProgressState state) { CheckDisposed(); int hvoPos = GetPOS(); // A Set of eligible parts of speech to use in filtering. Set <int> possiblePOS = GetPossiblePartsOfSpeech(); // Make a Dictionary from HVO of entry to list of modified senses. Dictionary <int, List <ILexSense> > sensesByEntry = new Dictionary <int, List <ILexSense> >(); int tagOwningEntry = m_cache.VwCacheDaAccessor.GetVirtualHandlerName("LexSense", "OwningEntry").Tag; int i = 0; // Report progress 50 times or every 100 items, whichever is more (but no more than once per item!) int interval = Math.Min(100, Math.Max(itemsToChange.Count / 50, 1)); foreach (int hvoSense in itemsToChange) { i++; if (i % interval == 0) { state.PercentDone = i * 20 / itemsToChange.Count; state.Breath(); } if (!IsItemEligible(m_cache.MainCacheAccessor, hvoSense, possiblePOS)) { continue; } ILexSense ls = (ILexSense)CmObject.CreateFromDBObject(m_cache, hvoSense, false); IMoMorphSynAnalysis msa = ls.MorphoSyntaxAnalysisRA; int hvoEntry = m_cache.MainCacheAccessor.get_ObjectProp(ls.Hvo, tagOwningEntry); if (!sensesByEntry.ContainsKey(hvoEntry)) { sensesByEntry[hvoEntry] = new List <ILexSense>(); } sensesByEntry[hvoEntry].Add(ls); } m_cache.BeginUndoTask(FdoUiStrings.ksUndoBEInflClass, FdoUiStrings.ksRedoBEInflClass); BulkEditBar.ForceRefreshOnUndoRedo(m_cache.MainCacheAccessor); i = 0; interval = Math.Min(100, Math.Max(sensesByEntry.Count / 50, 1)); foreach (KeyValuePair <int, List <ILexSense> > kvp in sensesByEntry) { i++; if (i % interval == 0) { state.PercentDone = i * 80 / sensesByEntry.Count + 20; state.Breath(); } ILexEntry entry = (ILexEntry)CmObject.CreateFromDBObject(m_cache, kvp.Key, false); List <ILexSense> sensesToChange = kvp.Value; IMoStemMsa msmTarget = null; foreach (IMoMorphSynAnalysis msa in entry.MorphoSyntaxAnalysesOC) { IMoStemMsa msm = msa as IMoStemMsa; if (msm != null && msm.InflectionClassRAHvo == m_selectedHvo) { // Can reuse this one! msmTarget = msm; break; } } if (msmTarget == null) { // See if we can reuse an existing MoStemMsa by changing it. // This is possible if it is used only by senses in the list, or not used at all. List <ILexSense> otherSenses = new List <ILexSense>(); if (entry.SensesOS.Count != sensesToChange.Count) { foreach (ILexSense ls in entry.SensesOS) { if (!sensesToChange.Contains(ls)) { otherSenses.Add(ls); } } } foreach (IMoMorphSynAnalysis msa in entry.MorphoSyntaxAnalysesOC) { IMoStemMsa msm = msa as IMoStemMsa; if (msm == null) { continue; } bool fOk = true; foreach (ILexSense ls in otherSenses) { if (ls.MorphoSyntaxAnalysisRA == msm) { fOk = false; break; } } if (fOk) { // Can reuse this one! Nothing we don't want to change uses it. // Adjust its POS as well as its inflection class, just to be sure. msmTarget = msm; msmTarget.PartOfSpeechRAHvo = hvoPos; msmTarget.InflectionClassRAHvo = m_selectedHvo; break; } } } if (msmTarget == null) { // Nothing we can reuse...make a new one. msmTarget = new MoStemMsa(); entry.MorphoSyntaxAnalysesOC.Add(msmTarget); msmTarget.PartOfSpeechRAHvo = hvoPos; msmTarget.InflectionClassRAHvo = m_selectedHvo; } // Finally! Make the senses we want to change use it. foreach (ILexSense ls in sensesToChange) { ls.MorphoSyntaxAnalysisRA = msmTarget; } } m_cache.EndUndoTask(); }
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); }
/// <summary> /// Execute the change requested by the current selection in the combo. /// Basically we want the MoInflClass indicated by m_selectedHvo, (even if 0?? not yet possible), /// to become the InflectionClass of each record that is appropriate to change. /// We do nothing to records where the check box is turned off, /// and nothing to ones that currently have an MSA other than an MoStemMsa, /// and nothing to ones that currently have an MSA with the wrong POS. /// (a) If the owning entry has an MoStemMsa with the right inflection class (and presumably POS), /// set the sense to use it. /// (b) If all senses using the current MoStemMsa are to be changed, just update /// the inflection class of that MoStemMsa. /// We could add this...but very probably unused MSAs would have been taken over /// when setting the POS. /// --(c) If the entry has an MoStemMsa which is not being used at all, change it to /// --the required POS and inflection class and use it. /// (d) Make a new MoStemMsa in the LexEntry with the required POS and inflection class /// and point the sense at it. /// </summary> public void DoIt(IEnumerable <int> itemsToChange, ProgressState state) { CheckDisposed(); var pos = GetPOS(); // A Set of eligible parts of speech to use in filtering. Set <int> possiblePOS = GetPossiblePartsOfSpeech(); // Make a Dictionary from HVO of entry to list of modified senses. var sensesByEntryAndPos = new Dictionary <Tuple <ILexEntry, IPartOfSpeech>, List <ILexSense> >(); int i = 0; // Report progress 50 times or every 100 items, whichever is more (but no more than once per item!) int interval = Math.Min(100, Math.Max(itemsToChange.Count() / 50, 1)); foreach (int hvoSense in itemsToChange) { i++; if (i % interval == 0) { state.PercentDone = i * 20 / itemsToChange.Count(); state.Breath(); } if (!IsItemEligible(m_cache.DomainDataByFlid, hvoSense, possiblePOS)) { continue; } var ls = m_cache.ServiceLocator.GetInstance <ILexSenseRepository>().GetObject(hvoSense); var msa = (IMoStemMsa)ls.MorphoSyntaxAnalysisRA; var entry1 = ls.Entry; var key = new Tuple <ILexEntry, IPartOfSpeech>(entry1, msa.PartOfSpeechRA); if (!sensesByEntryAndPos.ContainsKey(key)) { sensesByEntryAndPos[key] = new List <ILexSense>(); } sensesByEntryAndPos[key].Add(ls); } m_cache.DomainDataByFlid.BeginUndoTask(FdoUiStrings.ksUndoBEInflClass, FdoUiStrings.ksRedoBEInflClass); i = 0; interval = Math.Min(100, Math.Max(sensesByEntryAndPos.Count / 50, 1)); foreach (var kvp in sensesByEntryAndPos) { i++; if (i % interval == 0) { state.PercentDone = i * 80 / sensesByEntryAndPos.Count + 20; state.Breath(); } var entry = kvp.Key.Item1; var sensesToChange = kvp.Value; IMoStemMsa msmTarget = null; foreach (var msa in entry.MorphoSyntaxAnalysesOC) { var msm = msa as IMoStemMsa; if (msm != null && msm.InflectionClassRA != null && msm.InflectionClassRA.Hvo == m_selectedHvo) { // Can reuse this one! msmTarget = msm; break; } } if (msmTarget == null) { // See if we can reuse an existing MoStemMsa by changing it. // This is possible if it is used only by senses in the list, or not used at all. var otherSenses = new List <ILexSense>(); if (entry.SensesOS.Count != sensesToChange.Count) { foreach (var ls in entry.SensesOS) { if (!sensesToChange.Contains(ls)) { otherSenses.Add(ls); } } } foreach (var msa in entry.MorphoSyntaxAnalysesOC) { var msm = msa as IMoStemMsa; if (msm == null) { continue; } bool fOk = true; foreach (var ls in otherSenses) { if (ls.MorphoSyntaxAnalysisRA == msm) { fOk = false; break; } } if (fOk) { // Can reuse this one! Nothing we don't want to change uses it. // Adjust its POS as well as its inflection class, just to be sure. msmTarget = msm; msmTarget.PartOfSpeechRA = kvp.Key.Item2; msmTarget.InflectionClassRA = m_cache.ServiceLocator.GetInstance <IMoInflClassRepository>().GetObject(m_selectedHvo); break; } } } if (msmTarget == null) { // Nothing we can reuse...make a new one. msmTarget = m_cache.ServiceLocator.GetInstance <IMoStemMsaFactory>().Create(); entry.MorphoSyntaxAnalysesOC.Add(msmTarget); msmTarget.PartOfSpeechRA = kvp.Key.Item2; msmTarget.InflectionClassRA = m_cache.ServiceLocator.GetInstance <IMoInflClassRepository>().GetObject(m_selectedHvo); } // Finally! Make the senses we want to change use it. foreach (var ls in sensesToChange) { ls.MorphoSyntaxAnalysisRA = msmTarget; } } m_cache.DomainDataByFlid.EndUndoTask(); }
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"); }
private void InitMsa(IMoStemMsa msmTarget, int hvoPos) { msmTarget.PartOfSpeechRAHvo = hvoPos; msmTarget.MsFeaturesOA = null; // Delete the old one. Cache.CopyObject(m_selectedHvo, msmTarget.Hvo, (int)MoStemMsa.MoStemMsaTags.kflidMsFeatures); }
private void WriteMoStemMsa(TextWriter w, IMoStemMsa msa) { if (m_flidMoStemMsaIsEmpty == 0) m_flidMoStemMsaIsEmpty = m_cache.MetaDataCacheAccessor.GetFieldId("MoStemMsa", "IsEmpty", false); if (m_cache.DomainDataByFlid.get_BooleanProp(msa.Hvo, m_flidMoStemMsaIsEmpty)) return; if (String.IsNullOrEmpty(msa.PosFieldName)) w.WriteLine("<grammatical-info value=\"\">"); else w.WriteLine("<grammatical-info value=\"{0}\">", MakeSafeAndNormalizedAttribute(msa.PosFieldName)); if (msa.InflectionClassRA != null) { w.Write("<trait name=\"{0}-infl-class\" value=\"{1}\"/>", MakeSafeAndNormalizedAttribute(msa.InflectionClassRA.Owner.ShortName), BestAlternative(msa.InflectionClassRA.Name, m_wsEn)); } foreach (var pos in msa.FromPartsOfSpeechRC) WriteTrait(w, RangeNames.sPartsOfSpeechOAold1, pos.Name, m_wsBestAnalVern); if (msa.MsFeaturesOA != null && !msa.MsFeaturesOA.IsEmpty) w.WriteLine("<trait name=\"{0}\" value=\"{1}\"/>", RangeNames.sMSAinflectionFeature, MakeSafeAndNormalizedAttribute(msa.MsFeaturesOA.LiftName)); foreach (var restrict in msa.ProdRestrictRC) WriteTrait(w, RangeNames.sProdRestrictOA, restrict.Name, m_wsBestAnalVern); WriteLiftResidue(w, msa); w.WriteLine("</grammatical-info>"); }
/// <summary> /// Constructor. /// </summary> private DummyGenericMSA(IMoStemMsa stemMsa) { m_type = MsaType.kStem; m_mainPOS = stemMsa.PartOfSpeechRAHvo; m_fromPOSes = stemMsa.FromPartsOfSpeechRC; }
///<summary> /// Copies attributes associated with the current POS, such as inflection features and classes, that /// are valid from the specified MSA to this MSA. If the attribute is not valid, it is removed from /// this MSA. ///</summary> ///<param name="srcMsa">the source MSA</param> public void CopyAttributesIfValid(IMoStemMsa srcMsa) { // inflection classes if (IsReferenceAttributeValid(srcMsa.InflectionClassRA, MoStemMsaTags.kflidInflectionClass)) { if (srcMsa.InflectionClassRA != InflectionClassRA) InflectionClassRA = srcMsa.InflectionClassRA; } else if (InflectionClassRA != null) { InflectionClassRA = null; } // inflection features if (srcMsa.MsFeaturesOA == null) { MsFeaturesOA = null; } else { if (MsFeaturesOA != srcMsa.MsFeaturesOA) CopyObject<IFsFeatStruc>.CloneFdoObject(srcMsa.MsFeaturesOA, newMsa => MsFeaturesOA = newMsa); RemoveInvalidFeatureSpecs(PartOfSpeechRA, MsFeaturesOA); if (MsFeaturesOA != null) { if (MsFeaturesOA.IsEmpty) MsFeaturesOA = null; } } }
/// <summary> /// Execute the change requested by the current selection in the combo. /// Basically we want a copy of the FsFeatStruc indicated by m_selectedHvo, (even if 0?? not yet possible), /// to become the MsFeatures of each record that is appropriate to change. /// We do nothing to records where the check box is turned off, /// and nothing to ones that currently have an MSA other than an MoStemMsa, /// and nothing to ones that currently have an MSA with the wrong POS. /// (a) If the owning entry has an MoStemMsa with a matching MsFeatures (and presumably POS), /// set the sense to use it. /// (b) If all senses using the current MoStemMsa are to be changed, just update /// the MsFeatures of that MoStemMsa. /// We could add this...but very probably unused MSAs would have been taken over /// when setting the POS. /// --(c) If the entry has an MoStemMsa which is not being used at all, change it to /// --the required POS and inflection class and use it. /// (d) Make a new MoStemMsa in the LexEntry with the required POS and features /// and point the sense at it. /// </summary> public void DoIt(IEnumerable <int> itemsToChange, ProgressState state) { CheckDisposed(); var pos = GetPOS(); // Make a Set of eligible parts of speech to use in filtering. HashSet <int> possiblePOS = GetPossiblePartsOfSpeech(); // Make a Dictionary from HVO of entry to list of modified senses. var sensesByEntry = new Dictionary <int, HashSet <ILexSense> >(); int i = 0; // Report progress 50 times or every 100 items, whichever is more (but no more than once per item!) int interval = Math.Min(100, Math.Max(itemsToChange.Count() / 50, 1)); foreach (int hvoSense in itemsToChange) { i++; if (i % interval == 0) { state.PercentDone = i * 20 / itemsToChange.Count(); state.Breath(); } if (!IsItemEligible(m_cache.DomainDataByFlid, hvoSense, possiblePOS)) { continue; } var ls = m_cache.ServiceLocator.GetInstance <ILexSenseRepository>().GetObject(hvoSense); var msa = ls.MorphoSyntaxAnalysisRA; int hvoEntry = ls.EntryID; if (!sensesByEntry.ContainsKey(hvoEntry)) { sensesByEntry[hvoEntry] = new HashSet <ILexSense>(); } sensesByEntry[hvoEntry].Add(ls); } //REVIEW: Should these really be the same Undo/Redo strings as for InflectionClassEditor.cs? m_cache.DomainDataByFlid.BeginUndoTask(FdoUiStrings.ksUndoBEInflClass, FdoUiStrings.ksRedoBEInflClass); i = 0; interval = Math.Min(100, Math.Max(sensesByEntry.Count / 50, 1)); IFsFeatStruc fsTarget = null; if (m_selectedHvo != 0) { fsTarget = Cache.ServiceLocator.GetInstance <IFsFeatStrucRepository>().GetObject(m_selectedHvo); } foreach (var kvp in sensesByEntry) { i++; if (i % interval == 0) { state.PercentDone = i * 80 / sensesByEntry.Count + 20; state.Breath(); } var entry = m_cache.ServiceLocator.GetInstance <ILexEntryRepository>().GetObject(kvp.Key); var sensesToChange = kvp.Value; IMoStemMsa msmTarget = null; foreach (var msa in entry.MorphoSyntaxAnalysesOC) { var msm = msa as IMoStemMsa; if (msm != null && MsaMatchesTarget(msm, fsTarget)) { // Can reuse this one! msmTarget = msm; break; } } if (msmTarget == null) { // See if we can reuse an existing MoStemMsa by changing it. // This is possible if it is used only by senses in the list, or not used at all. var otherSenses = new HashSet <ILexSense>(); var senses = new HashSet <ILexSense>(entry.AllSenses.ToArray()); if (senses.Count != sensesToChange.Count) { foreach (var ls in senses) { if (!sensesToChange.Contains(ls)) { otherSenses.Add(ls); } } } foreach (var msa in entry.MorphoSyntaxAnalysesOC) { var msm = msa as IMoStemMsa; if (msm == null) { continue; } bool fOk = true; foreach (var ls in otherSenses) { if (ls.MorphoSyntaxAnalysisRA == msm) { fOk = false; break; } } if (fOk) { // Can reuse this one! Nothing we don't want to change uses it. // Adjust its POS as well as its inflection feature, just to be sure. // Ensure that we don't change the POS! See LT-6835. msmTarget = msm; InitMsa(msmTarget, msm.PartOfSpeechRA.Hvo); break; } } } if (msmTarget == null) { // Nothing we can reuse...make a new one. msmTarget = m_cache.ServiceLocator.GetInstance <IMoStemMsaFactory>().Create(); entry.MorphoSyntaxAnalysesOC.Add(msmTarget); InitMsa(msmTarget, pos.Hvo); } // Finally! Make the senses we want to change use it. foreach (var ls in sensesToChange) { ls.MorphoSyntaxAnalysisRA = msmTarget; } } m_cache.DomainDataByFlid.EndUndoTask(); }
private int FindOrCreateMatchingAffixMsa(IMoStemMsa msa) { int hvoPOS = msa.PartOfSpeechRAHvo; foreach (IMoMorphSynAnalysis msaT in this.MorphoSyntaxAnalysesOC) { IMoUnclassifiedAffixMsa msaAffix = msaT as IMoUnclassifiedAffixMsa; if (msaAffix != null && msaAffix.PartOfSpeechRAHvo == hvoPOS) return msaAffix.Hvo; } IMoUnclassifiedAffixMsa msaNew = new MoUnclassifiedAffixMsa(); this.MorphoSyntaxAnalysesOC.Add(msaNew); msaNew.PartOfSpeechRAHvo = hvoPOS; return msaNew.Hvo; }
/// <summary> /// Answer true if the selected MSA has an MsFeatures that is the same as the argument. /// </summary> /// <returns></returns> private bool MsaMatchesTarget(IMoStemMsa msm, IFsFeatStruc fsTarget) { if (m_selectedHvo == 0 && msm.MsFeaturesOAHvo == 0) return true; if (msm.MsFeaturesOAHvo == 0) return false; return msm.MsFeaturesOA.IsEquivalent(fsTarget); }
public void LexEntryInflTypeAnalysisWithNullForSlotFiller() { IWfiWordform brubs = CheckAnalysisSize("brubsTEST", 0, true); ILexDb ldb = Cache.LanguageProject.LexDbOA; ParseResult result = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Verb brub which is a present tense irregularly inflected form of 'believe' // with automatically generated null Tense slot and an -s Plural Number slot filler // (This is not supposed to be English, in case you're wondering....) ILexEntryInflType presentTenseLexEntryInflType = m_lexEntryInflTypeFactory.Create(); Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS.Add(presentTenseLexEntryInflType); ILexEntry believeV = m_entryFactory.Create(); IMoStemAllomorph believeVForm = m_stemAlloFactory.Create(); believeV.AlternateFormsOS.Add(believeVForm); believeVForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.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 brubV = m_entryFactory.Create(); IMoStemAllomorph brubVForm = m_stemAlloFactory.Create(); brubV.AlternateFormsOS.Add(brubVForm); brubVForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("brubVTEST", m_vernacularWS.Handle); ILexEntryRef lexEntryref = m_lexEntryRefFactory.Create(); brubV.EntryRefsOS.Add(lexEntryref); lexEntryref.ComponentLexemesRS.Add(believeV); lexEntryref.VariantEntryTypesRS.Add(presentTenseLexEntryInflType); ILexEntry nullPresent = m_entryFactory.Create(); IMoAffixAllomorph nullPresentForm = m_afxAlloFactory.Create(); nullPresent.AlternateFormsOS.Add(nullPresentForm); nullPresentForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("nullPRESENTTEST", m_vernacularWS.Handle); IMoInflAffMsa nullPresentMsa = m_inflAffMsaFactory.Create(); nullPresent.MorphoSyntaxAnalysesOC.Add(nullPresentMsa); ILexEntry sPlural = m_entryFactory.Create(); IMoAffixAllomorph sPluralForm = m_afxAlloFactory.Create(); sPlural.AlternateFormsOS.Add(sPluralForm); sPluralForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("sPLURALTEST", m_vernacularWS.Handle); IMoInflAffMsa sPluralMsa = m_inflAffMsaFactory.Create(); sPlural.MorphoSyntaxAnalysesOC.Add(sPluralMsa); result = new ParseResult(new[] { new ParseAnalysis(new[] { new ParseMorph(brubVForm, MorphServices.GetMainOrFirstSenseOfVariant(brubV.EntryRefsOS[0]).MorphoSyntaxAnalysisRA, (ILexEntryInflType)brubV.EntryRefsOS[0].VariantEntryTypesRS[0]), new ParseMorph(sPluralForm, sPluralMsa) }) }); }); m_filer.ProcessParse(brubs, ParserPriority.Low, result); ExecuteIdleQueue(); CheckAnalysisSize("brubsTEST", 1, false); var analysis = brubs.AnalysesOC.ElementAt(0); Assert.AreEqual(2, analysis.MorphBundlesOS.Count, "Expected only 2 morphs 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"); }
public void DuplicateAnalysesApproval() { IWfiWordform pigs = CheckAnalysisSize("pigsTEST", 0, true); ParseResult result = null; IWfiAnalysis anal1 = null, anal2 = null, anal3 = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Bear entry ILexEntry pigN = m_entryFactory.Create(); IMoStemAllomorph pigNForm = m_stemAlloFactory.Create(); pigN.AlternateFormsOS.Add(pigNForm); pigNForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.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); var analFactory = Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>(); var mbFactory = Cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>(); // First of two duplicate analyses IWfiAnalysis anal = analFactory.Create(); pigs.AnalysesOC.Add(anal); anal1 = anal; IWfiMorphBundle mb = mbFactory.Create(); anal.MorphBundlesOS.Add(mb); mb.MorphRA = pigNForm; mb.MsaRA = pigNMsa; CheckEvaluationSize(anal1, 0, true, "anal1"); // Non-duplicate, to make sure it does not get approved. anal = analFactory.Create(); pigs.AnalysesOC.Add(anal); anal2 = anal; mb = mbFactory.Create(); anal.MorphBundlesOS.Add(mb); mb.SenseRA = pigNSense; CheckEvaluationSize(anal2, 0, true, "anal2"); // Second of two duplicate analyses anal = analFactory.Create(); pigs.AnalysesOC.Add(anal); anal3 = anal; mb = mbFactory.Create(); anal.MorphBundlesOS.Add(mb); mb.MorphRA = pigNForm; mb.MsaRA = pigNMsa; CheckEvaluationSize(anal3, 0, true, "anal3"); CheckAnalysisSize("pigsTEST", 3, false); result = new ParseResult(new[] { new ParseAnalysis(new[] { new ParseMorph(pigNForm, pigNMsa) }) }); }); m_filer.ProcessParse(pigs, ParserPriority.Low, result); ExecuteIdleQueue(); CheckEvaluationSize(anal1, 1, false, "anal1Hvo"); Assert.IsFalse(anal2.IsValidObject, "analysis 2 should end up with no evaluations and so be deleted"); CheckEvaluationSize(anal3, 1, false, "anal3Hvo"); }
protected void CreateStemMsaXmlElement(XmlDocument doc, XmlNode morphNode, IMoStemMsa stemMsa) { XmlNode stemMsaNode = CreateXmlElement(doc, "stemMsa", morphNode); CreatePOSXmlAttribute(doc, stemMsaNode, stemMsa.PartOfSpeechRA, "cat"); IMoInflClass inflClass = stemMsa.InflectionClassRA; if (inflClass == null) { // use default inflection class of the POS or // the first ancestor POS that has a non-zero default inflection class int inflClassHvo = 0; IPartOfSpeech pos = stemMsa.PartOfSpeechRA; while (pos != null && inflClassHvo == 0) { if (pos.DefaultInflectionClassRAHvo != 0) inflClassHvo = pos.DefaultInflectionClassRAHvo; else { int clsid = m_cache.GetClassOfObject(pos.OwnerHVO); if (clsid == PartOfSpeech.kClassId) pos = PartOfSpeech.CreateFromDBObject(m_cache, pos.OwnerHVO); else pos = null; } } if (inflClassHvo != 0) inflClass = MoInflClass.CreateFromDBObject(m_cache, inflClassHvo); } CreateInflectionClassXmlAttribute(doc, stemMsaNode, inflClass, "inflClass"); CreateRequiresInflectionXmlAttribute(doc, stemMsa.PartOfSpeechRAHvo, stemMsaNode); CreateFeatureStructureNodes(doc, stemMsaNode, stemMsa.MsFeaturesOA, stemMsa.Hvo); CreateProductivityRestrictionNodes(doc, stemMsaNode, stemMsa.ProdRestrictRC, "productivityRestriction"); CreateFromPOSNodes(doc, stemMsaNode, stemMsa.FromPartsOfSpeechRC, "fromPartsOfSpeech"); }
protected void CreateMsaXmlElement(XmlNode node, XmlDocument doc, XmlNode morphNode, string sHvo) { XmlNode attr; // morphname contains the hvo of the msa attr = node.SelectSingleNode(sHvo); if (attr != null) { string sObjHvo = attr.Value; // Irregulary inflected forms can have a combination MSA hvo: the LexEntry hvo, a period, and an index to the LexEntryRef var indexOfPeriod = ParseFiler.IndexOfPeriodInMsaHvo(ref sObjHvo); ICmObject obj = m_cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(Convert.ToInt32(sObjHvo)); switch (obj.GetType().Name) { default: throw new ApplicationException(String.Format("Invalid MSA type: {0}.", obj.GetType().Name)); case "MoStemMsa": IMoStemMsa stemMsa = obj as IMoStemMsa; CreateStemMsaXmlElement(doc, morphNode, stemMsa); break; case "MoInflAffMsa": IMoInflAffMsa inflMsa = obj as IMoInflAffMsa; CreateInflectionClasses(doc, morphNode); CreateInflMsaXmlElement(doc, morphNode, inflMsa); break; case "MoDerivAffMsa": IMoDerivAffMsa derivMsa = obj as IMoDerivAffMsa; CreateDerivMsaXmlElement(doc, morphNode, derivMsa); break; case "MoUnclassifiedAffixMsa": IMoUnclassifiedAffixMsa unclassMsa = obj as IMoUnclassifiedAffixMsa; CreateUnclassifedMsaXmlElement(doc, morphNode, unclassMsa); break; case "LexEntry": // is an irregularly inflected form // get the MoStemMsa of its variant var entry = obj as ILexEntry; if (entry.EntryRefsOS.Count > 0) { var index = ParseFiler.IndexOfLexEntryRef(attr.Value, indexOfPeriod); var lexEntryRef = entry.EntryRefsOS[index]; var sense = FDO.DomainServices.MorphServices.GetMainOrFirstSenseOfVariant(lexEntryRef); stemMsa = sense.MorphoSyntaxAnalysisRA as IMoStemMsa; CreateStemMsaXmlElement(doc, morphNode, stemMsa); } break; case "LexEntryInflType": // This is one of the null allomorphs we create when building the // input for the parser in order to still get the Word Grammar to have something in any // required slots in affix templates. CreateInflMsaForLexEntryInflType(doc, morphNode, obj as ILexEntryInflType); break; } } }