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; } }); } }
/// <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 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; } } }
private static void WriteDerivMsaXmlElement(XmlWriter writer, IMoDerivAffMsa derivMsa) { writer.WriteStartElement("derivMsa"); WritePosXmlAttribute(writer, derivMsa.FromPartOfSpeechRA, "fromCat"); WritePosXmlAttribute(writer, derivMsa.ToPartOfSpeechRA, "toCat"); WriteInflectionClassXmlAttribute(writer, derivMsa.FromInflectionClassRA, "fromInflClass"); WriteInflectionClassXmlAttribute(writer, derivMsa.ToInflectionClassRA, "toInflClass"); WriteRequiresInflectionXmlAttribute(writer, derivMsa.ToPartOfSpeechRA); WriteFeatureStructureNodes(writer, derivMsa.FromMsFeaturesOA, derivMsa.Hvo, "fromFS"); WriteFeatureStructureNodes(writer, derivMsa.ToMsFeaturesOA, derivMsa.Hvo, "toFS"); WriteProductivityRestrictionNodes(writer, derivMsa.FromProdRestrictRC, "fromProductivityRestriction"); WriteProductivityRestrictionNodes(writer, derivMsa.ToProdRestrictRC, "toProductivityRestriction"); writer.WriteEndElement(); //derivMsa }
protected void CreateDerivMsaXmlElement(XmlDocument doc, XmlNode morphNode, IMoDerivAffMsa derivMsa) { XmlNode derivMsaNode = CreateXmlElement(doc, "derivMsa", morphNode); CreatePOSXmlAttribute(doc, derivMsaNode, derivMsa.FromPartOfSpeechRA, "fromCat"); CreatePOSXmlAttribute(doc, derivMsaNode, derivMsa.ToPartOfSpeechRA, "toCat"); CreateInflectionClassXmlAttribute(doc, derivMsaNode, derivMsa.FromInflectionClassRA, "fromInflClass"); CreateInflectionClassXmlAttribute(doc, derivMsaNode, derivMsa.ToInflectionClassRA, "toInflClass"); CreateRequiresInflectionXmlAttribute(doc, derivMsa.ToPartOfSpeechRAHvo, derivMsaNode); CreateFeatureStructureNodes(doc, derivMsaNode, derivMsa.FromMsFeaturesOA, derivMsa.Hvo, "fromFS"); CreateFeatureStructureNodes(doc, derivMsaNode, derivMsa.ToMsFeaturesOA, derivMsa.Hvo, "toFS"); CreateProductivityRestrictionNodes(doc, derivMsaNode, derivMsa.FromProdRestrictRC, "fromProductivityRestriction"); CreateProductivityRestrictionNodes(doc, derivMsaNode, derivMsa.ToProdRestrictRC, "toProductivityRestriction"); }
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; } } }
private bool CheckForAffixDataLoss(IMoAffixForm affix, List <IMoMorphSynAnalysis> rgmsaAffix) { bool fLoseInflCls = affix.InflectionClassesRC.Count > 0; bool fLoseInfixLoc = false; bool fLoseGramInfo = false; bool fLoseRule = false; switch (affix.ClassID) { case MoAffixProcess.kclsidMoAffixProcess: fLoseRule = true; break; case MoAffixAllomorph.kclsidMoAffixAllomorph: IMoAffixAllomorph allo = affix as IMoAffixAllomorph; fLoseInfixLoc = allo.PositionRS.Count > 0; fLoseGramInfo = allo.MsEnvPartOfSpeechRAHvo != 0 || allo.MsEnvFeaturesOAHvo != 0; break; } for (int i = 0; !fLoseGramInfo && i < rgmsaAffix.Count; ++i) { IMoInflAffMsa msaInfl = rgmsaAffix[i] as IMoInflAffMsa; if (msaInfl != null) { if (msaInfl.AffixCategoryRAHvo != 0 || msaInfl.FromProdRestrictRC.Count > 0 || msaInfl.SlotsRC.Count > 0 || msaInfl.InflFeatsOAHvo != 0) { fLoseGramInfo = true; } continue; } IMoDerivAffMsa msaDeriv = rgmsaAffix[i] as IMoDerivAffMsa; if (msaDeriv != null) { if (msaDeriv.AffixCategoryRAHvo != 0 || msaDeriv.FromInflectionClassRAHvo != 0 || msaDeriv.FromPartOfSpeechRAHvo != 0 || msaDeriv.FromProdRestrictRC.Count > 0 || msaDeriv.FromStemNameRAHvo != 0 || msaDeriv.StratumRAHvo != 0 || msaDeriv.ToInflectionClassRAHvo != 0 || msaDeriv.ToProdRestrictRC.Count > 0 || msaDeriv.FromMsFeaturesOAHvo != 0 || msaDeriv.ToMsFeaturesOAHvo != 0) { fLoseGramInfo = true; } continue; } IMoDerivStepMsa msaStep = rgmsaAffix[i] as IMoDerivStepMsa; if (msaStep != null) { if (msaStep.InflectionClassRAHvo != 0 || msaStep.ProdRestrictRC.Count > 0 || msaStep.InflFeatsOAHvo != 0 || msaStep.MsFeaturesOAHvo != 0) { fLoseGramInfo = true; } continue; } } if (fLoseInflCls || fLoseInfixLoc || fLoseGramInfo || fLoseRule) { string sMsg; if (fLoseInflCls && fLoseInfixLoc && fLoseGramInfo) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseInflClsInfixLocGramInfo", m_ksPath); } else if (fLoseRule && fLoseInflCls && fLoseGramInfo) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseRuleInflClsGramInfo", m_ksPath); } else if (fLoseInflCls && fLoseInfixLoc) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseInflClsInfixLoc", m_ksPath); } else if (fLoseInflCls && fLoseGramInfo) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseInflClsGramInfo", m_ksPath); } else if (fLoseInfixLoc && fLoseGramInfo) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseInfixLocGramInfo", m_ksPath); } else if (fLoseRule && fLoseInflCls) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseRuleInflCls", m_ksPath); } else if (fLoseRule) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseRule", m_ksPath); } else if (fLoseInflCls) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseInflCls", m_ksPath); } else if (fLoseInfixLoc) { sMsg = m_mediator.StringTbl.GetStringWithXPath("ChangeMorphTypeLoseInfixLoc", 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); }
///<summary> /// Copies attributes associated with the current "To" 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 CopyFromAttributesIfValid(IMoDerivAffMsa srcMsa) { // inflection classes if (IsReferenceAttributeValid(srcMsa.FromInflectionClassRA, (int)MoDerivAffMsaTags.kflidFromInflectionClass)) { if (srcMsa.FromInflectionClassRA != FromInflectionClassRA) FromInflectionClassRA = srcMsa.FromInflectionClassRA; } else if (FromInflectionClassRA != null) { FromInflectionClassRA = null; } // inflection features if (srcMsa.FromMsFeaturesOA == null) { FromMsFeaturesOA = null; } else { if (FromMsFeaturesOA != srcMsa.FromMsFeaturesOA) CopyObject<IFsFeatStruc>.CloneFdoObject(srcMsa.FromMsFeaturesOA, newMsa => FromMsFeaturesOA = newMsa); RemoveInvalidFeatureSpecs(FromPartOfSpeechRA, FromMsFeaturesOA); if (FromMsFeaturesOA.IsEmpty) FromMsFeaturesOA = null; } // stem names if (IsReferenceAttributeValid(srcMsa.FromStemNameRA, (int)MoDerivAffMsaTags.kflidFromStemName)) { if (srcMsa.FromStemNameRA != FromStemNameRA) FromStemNameRA = srcMsa.FromStemNameRA; } else if (FromStemNameRA != null) { FromStemNameRA = null; } }
///<summary> /// Copies attributes associated with the current "From" 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 CopyToAttributesIfValid(IMoDerivAffMsa srcMsa) { // inflection classes if (IsReferenceAttributeValid(srcMsa.ToInflectionClassRA, MoDerivAffMsaTags.kflidToInflectionClass)) { if (srcMsa.ToInflectionClassRA != ToInflectionClassRA) ToInflectionClassRA = srcMsa.ToInflectionClassRA; } else if (ToInflectionClassRA != null) { ToInflectionClassRA = null; } // inflection features if (srcMsa.ToMsFeaturesOA == null) { ToMsFeaturesOA = null; } else { if (ToMsFeaturesOA != srcMsa.ToMsFeaturesOA) CopyObject<IFsFeatStruc>.CloneFdoObject(srcMsa.ToMsFeaturesOA, newMsa => ToMsFeaturesOA = newMsa); RemoveInvalidFeatureSpecs(ToPartOfSpeechRA, ToMsFeaturesOA); if (ToMsFeaturesOA.IsEmpty) ToMsFeaturesOA = null; } }
private void WriteMoDerivAffMsa(TextWriter w, IMoDerivAffMsa msa) { if (String.IsNullOrEmpty(msa.PosFieldName)) w.WriteLine("<grammatical-info value=\"\">"); else w.WriteLine("<grammatical-info value=\"{0}\">", MakeSafeAndNormalizedAttribute(msa.PosFieldName)); w.WriteLine("<trait name=\"type\" value=\"derivAffix\"/>"); if (msa.FromPartOfSpeechRA != null) { WriteTrait(w, RangeNames.sPartsOfSpeechOAold1, msa.FromPartOfSpeechRA.Name, m_wsBestAnalVern); } if (msa.FromInflectionClassRA != null) { w.WriteLine("<trait name=\"from-{0}-infl-class\" value=\"{1}\"/>", MakeSafeAndNormalizedAttribute(msa.FromInflectionClassRA.Owner.ShortName), BestAlternative(msa.FromInflectionClassRA.Name, m_wsEn)); } foreach (var restrict in msa.FromProdRestrictRC) { WriteTrait(w, RangeNames.sProdRestrictOAfrom, restrict.Name, m_wsBestAnalVern); } if (msa.FromMsFeaturesOA != null && !msa.FromMsFeaturesOA.IsEmpty) { w.WriteLine("<trait name=\"from-inflection-feature\" value=\"{0}\"/>", MakeSafeAndNormalizedAttribute(msa.FromMsFeaturesOA.LiftName)); } if (msa.FromStemNameRA != null) { WriteTrait(w, "from-stem-name", msa.FromStemNameRA.Name, m_wsBestAnalVern); } if (msa.ToInflectionClassRA != null) { w.WriteLine("<trait name=\"{0}-infl-class\" value=\"{1}\"/>", MakeSafeAndNormalizedAttribute(msa.ToInflectionClassRA.Owner.ShortName), BestAlternative(msa.ToInflectionClassRA.Name, m_wsEn)); } foreach (var restrict in msa.ToProdRestrictRC) { WriteTrait(w, RangeNames.sProdRestrictOA, restrict.Name, m_wsBestAnalVern); } if (msa.ToMsFeaturesOA != null && !msa.ToMsFeaturesOA.IsEmpty) { w.WriteLine("<trait name=\"{0}\" value=\"{1}\"/>", RangeNames.sMSAinflectionFeature, MakeSafeAndNormalizedAttribute(msa.ToMsFeaturesOA.LiftName)); } WriteLiftResidue(w, msa); w.WriteLine("</grammatical-info>"); }
/// <summary> /// Constructor. /// </summary> private DummyGenericMSA(IMoDerivAffMsa derivMsa) { m_type = MsaType.kDeriv; m_mainPOS = derivMsa.FromPartOfSpeechRAHvo; m_secondaryPOS = derivMsa.ToPartOfSpeechRAHvo; }
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; } } }