/// <summary> /// This replaces a MoForm belonging to this LexEntry with another one, presumably /// changing from a stem to an affix or vice versa. (A version of this code originally /// appeared in MorphTypeAtomicLauncher.cs, but is also needed for LIFT import.) /// </summary> /// <param name="mfOld"></param> /// <param name="mfNew"></param> public void ReplaceMoForm(IMoForm mfOld, IMoForm mfNew) { // save the environment references, if any. int[] envs = null; if (mfOld is IMoStemAllomorph) envs = (mfOld as IMoStemAllomorph).PhoneEnvRC.HvoArray; else if (mfOld is IMoAffixAllomorph) envs = (mfOld as IMoAffixAllomorph).PhoneEnvRC.HvoArray; else envs = new int[0]; int[] inflClasses = null; if (mfOld is IMoAffixForm) inflClasses = (mfOld as IMoAffixForm).InflectionClassesRC.HvoArray; else inflClasses = new int[0]; // if we are converting from one affix form to another, we should save the morph type int oldAffMorphType = 0; if (mfOld is IMoAffixForm) oldAffMorphType = mfOld.MorphTypeRAHvo; if (mfOld.OwningFlid == (int)LexEntry.LexEntryTags.kflidLexemeForm) { this.AlternateFormsOS.Append(mfNew); // trick to get it to be in DB so SwapReferences works } else { // insert the new form in the right location in the sequence. Debug.Assert(mfOld.OwningFlid == (int)LexEntry.LexEntryTags.kflidAlternateForms); bool fInserted = false; for (int i = 0; i < this.AlternateFormsOS.Count; ++i) { if (this.AlternateFormsOS.HvoArray[i] == mfOld.Hvo) { this.AlternateFormsOS.InsertAt(mfNew, i); fInserted = true; break; } } if (!fInserted) this.AlternateFormsOS.Append(mfNew); // This should NEVER happen, but... } mfOld.SwapReferences(mfNew.Hvo); MultiUnicodeAccessor muaOrigForm = mfOld.Form; MultiUnicodeAccessor muaNewForm = mfNew.Form; muaNewForm.MergeAlternatives(muaOrigForm); if (mfOld.OwningFlid == (int)LexEntry.LexEntryTags.kflidLexemeForm) this.LexemeFormOA = mfNew; // do we need to remove it from AlternateFormsOS?? else this.AlternateFormsOS.Remove(mfOld); // restore the environment references, if any. foreach (int hvo in envs) { if (mfNew is IMoStemAllomorph) (mfNew as IMoStemAllomorph).PhoneEnvRC.Add(hvo); else if (mfNew is IMoAffixAllomorph) (mfNew as IMoAffixAllomorph).PhoneEnvRC.Add(hvo); } foreach (int hvo in inflClasses) { if (mfNew is IMoAffixForm) (mfNew as IMoAffixForm).InflectionClassesRC.Add(hvo); } if (oldAffMorphType != 0 && mfNew is IMoAffixForm) mfNew.MorphTypeRAHvo = oldAffMorphType; }
// Swap values of various attributes between an existing form that is a LexemeForm and // a newly created one. Includes adding the new one to the alternate forms of the entry, and // the id of the old one to a map of things to delete. private void SwapFormValues(ILexEntry entry, IMoForm origForm, IMoForm newForm, int typeHvo, Set<int> idsToDel) { entry.AlternateFormsOS.Add(newForm); origForm.SwapReferences(newForm); var muaOrigForm = origForm.Form; var muaNewForm = newForm.Form; muaNewForm.MergeAlternatives(muaOrigForm); newForm.MorphTypeRA = m_cache.ServiceLocator.GetInstance<IMoMorphTypeRepository>().GetObject(typeHvo); idsToDel.Add(origForm.Hvo); }
// Swap values of various attributes between an existing form that is a LexemeForm and // a newly created one. Includes adding the new one to the alternate forms of the entry, and // the id of the old one to a map of things to delete. private void SwapFormValues(ILexEntry entry, IMoForm origForm, IMoForm newForm, int typeHvo, Set<int> idsToDel) { entry.AlternateFormsOS.Append(newForm); // trick to get it to be in DB so SwapReferences works origForm.SwapReferences(newForm.Hvo); MultiUnicodeAccessor muaOrigForm = origForm.Form; MultiUnicodeAccessor muaNewForm = newForm.Form; muaNewForm.MergeAlternatives(muaOrigForm); newForm.MorphTypeRAHvo = typeHvo; idsToDel.Add(origForm.Hvo); }