public void MergeAppendAtomic() { CheckDisposed(); int engWs = Cache.LanguageEncodings.GetWsFromIcuLocale("en"); ILexEntry lmeKeeper = m_entriesCol.Add(new LexEntry()); MoStemAllomorph amKeeper = new MoStemAllomorph(); lmeKeeper.LexemeFormOA = amKeeper; ILexEntry lmeSrc = m_entriesCol.Add(new LexEntry()); MoStemAllomorph amSrc = new MoStemAllomorph(); lmeSrc.LexemeFormOA = amSrc; string oldForm = "old form"; string newForm = "new form"; amKeeper.Form.SetAlternative(oldForm, engWs); amSrc.Form.SetAlternative(newForm, engWs); lmeKeeper.MergeObject(lmeSrc, true); Assert.AreEqual(oldForm + ' ' + newForm, amKeeper.Form.GetAlternative(engWs)); // Nothing should happen if the child objects are of different types. MoAffixAllomorph maa = new MoAffixAllomorph(); lmeSrc = m_entriesCol.Add(new LexEntry()); lmeSrc.LexemeFormOA = maa; maa.Form.SetAlternative(newForm, engWs); amKeeper.Form.SetAlternative(oldForm, engWs); lmeKeeper.MergeObject(lmeSrc, true); Assert.AreEqual(oldForm, amKeeper.Form.GetAlternative(engWs)); }
private void CacheEnvironments(MoStemAllomorph allomorph) { CacheEnvironments(allomorph.PhoneEnvRC.HvoArray); AppendPhoneEnv(kDummyPhoneEnvID, null); }
public void CliticVsStemMsaWithoutCategory() { CheckDisposed(); LexEntry entry = new LexEntry(); Cache.LangProject.LexDbOA.EntriesOC.Add(entry); MoStemAllomorph allomorph = new MoStemAllomorph(); entry.LexemeFormOA = allomorph; MoStemMsa msa = new MoStemMsa(); entry.MorphoSyntaxAnalysesOC.Add(msa); SetMorphType(allomorph, MoMorphType.kguidMorphClitic); Assert.AreEqual("Clitic of unknown category", msa.LongNameTs.Text); MoStemAllomorph allo2 = new MoStemAllomorph(); entry.AlternateFormsOS.Append(allo2); SetMorphType(allomorph, MoMorphType.kguidMorphStem); Assert.AreEqual("Stem/root of unknown category; takes any affix", msa.LongNameTs.Text); }
public void FromPartsOfSpeechIsRelevant() { CheckDisposed(); LexEntry entry = new LexEntry(); Cache.LangProject.LexDbOA.EntriesOC.Add(entry); MoStemAllomorph allomorph = new MoStemAllomorph(); entry.AlternateFormsOS.Append(allomorph); MoStemMsa msa = new MoStemMsa(); entry.MorphoSyntaxAnalysesOC.Add(msa); SetMorphType(allomorph, MoMorphType.kguidMorphStem); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphProclitic); Assert.IsTrue(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should now be relevant since the entry has a proclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphEnclitic); Assert.IsTrue(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should now be relevant since the entry has an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphClitic); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphBoundRoot); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphBoundStem); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphCircumfix); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphDiscontiguousPhrase); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphInfix); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphInfixingInterfix); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphParticle); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphPhrase); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphPrefix); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphPrefixingInterfix); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphRoot); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphSimulfix); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphSuffix); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphSuffixingInterfix); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); SetMorphType(allomorph, MoMorphType.kguidMorphSuprafix); Assert.IsFalse(msa.IsFieldRelevant((int)MoStemMsa.MoStemMsaTags.kflidFromPartsOfSpeech), "FromPartsOfSpeech should not be relevant until the entry contains a proclitic or an enclitic."); }
public void CheckNumberOfEntries() { CheckDisposed(); m_fdoCache.LangProject.LexDbOA.EntriesOC.Add(new LexEntry()); m_fdoCache.LangProject.PartsOfSpeechOA.PossibilitiesOS.Append(new PartOfSpeech()); PartOfSpeech pos = (Ling.PartOfSpeech)m_fdoCache.LangProject.PartsOfSpeechOA.PossibilitiesOS.FirstItem; int hvoLme = m_fdoCache.LangProject.LexDbOA.EntriesOC.HvoArray[0]; ILexEntry lme = LexEntry.CreateFromDBObject(m_fdoCache, hvoLme); int cRef1 = pos.NumberOfLexEntries; MoStemMsa msm = new MoStemMsa(); lme.MorphoSyntaxAnalysesOC.Add(msm); msm.PartOfSpeechRA = pos; int cRef2 = pos.NumberOfLexEntries; Assert.IsTrue(cRef1 + 1 == cRef2, "NumberOfLexEntries for MoStemMsa was " + cRef2 + " but should have been" + (cRef1 + 1)); MoMorphType mmt = (Ling.MoMorphType)m_fdoCache.LangProject.LexDbOA.MorphTypesOA.PossibilitiesOS.FirstItem; cRef1 = mmt.NumberOfLexEntries; MoStemAllomorph msa = new MoStemAllomorph(); lme.AlternateFormsOS.Append(msa); msa.MorphTypeRA = mmt; cRef2 = mmt.NumberOfLexEntries; Assert.IsTrue(cRef1 + 1 == cRef2, "NumberOfLexEntries for MoMorphType was " + cRef2 + " but should have been" + (cRef1 + 1)); }
public void LexemeFormStemAllomorphIsRelevant() { LexEntry stemEntry = new LexEntry (); Cache.LangProject.LexDbOA.EntriesOC.Add(stemEntry); MoStemAllomorph stemAllomorph = new MoStemAllomorph(); stemEntry.LexemeFormOA = stemAllomorph; Assert.IsFalse(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should not be relevant when there is no morph type."); foreach (IMoMorphType mmt in Cache.LangProject.LexDbOA.MorphTypesOA.PossibilitiesOS) { stemAllomorph.MorphTypeRA = mmt; switch (mmt.Guid.ToString()) { case MoMorphType.kguidMorphRoot: Assert.IsTrue(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should be relevant for a root morph type."); break; case MoMorphType.kguidMorphBoundRoot: Assert.IsTrue(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should be relevant for a bound root morph type."); break; case MoMorphType.kguidMorphStem: Assert.IsTrue(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should be relevant for a stem morph type."); break; case MoMorphType.kguidMorphBoundStem: Assert.IsTrue(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should be relevant for a bound stem morph type."); break; case MoMorphType.kguidMorphCircumfix: Assert.IsFalse(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should not be relevant for a circumfix morph type."); break; case MoMorphType.kguidMorphDiscontiguousPhrase: Assert.IsFalse(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should not be relevant for a discontiguous phrasemorph type."); break; case MoMorphType.kguidMorphClitic: Assert.IsFalse(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should not be relevant for a clitic morph type."); break; case MoMorphType.kguidMorphEnclitic: Assert.IsFalse(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should not be relevant for an enclitic morph type."); break; case MoMorphType.kguidMorphInfix: Assert.IsFalse(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should not be relevant for an infix morph type."); break; case MoMorphType.kguidMorphInfixingInterfix: Assert.IsFalse(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should not be relevant for an infixing interfix morph type."); break; case MoMorphType.kguidMorphParticle: Assert.IsFalse(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should not be relevant for a particle morph type."); break; case MoMorphType.kguidMorphPhrase: Assert.IsTrue(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should be relevant for a phrase morph type."); break; case MoMorphType.kguidMorphPrefix: Assert.IsFalse(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should not be relevant for a prefix morph type."); break; case MoMorphType.kguidMorphPrefixingInterfix: Assert.IsFalse(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should not be relevant for a prefixing interfix morph type."); break; case MoMorphType.kguidMorphProclitic: Assert.IsFalse(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should not be relevant for a proclitic morph type."); break; case MoMorphType.kguidMorphSimulfix: Assert.IsFalse(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should not be relevant for a simulfix morph type."); break; case MoMorphType.kguidMorphSuffix: Assert.IsFalse(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should not be relevant for a suffix morph type."); break; case MoMorphType.kguidMorphSuffixingInterfix: Assert.IsFalse(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should not be relevant for a suffixing interfix morph type."); break; case MoMorphType.kguidMorphSuprafix: Assert.IsFalse(stemAllomorph.IsFieldRelevant((int)MoStemAllomorph.MoStemAllomorphTags.kflidStemName), "Stem allomorph stem name should not be relevant for a suprafix morph type."); break; } } }
private void SetMorphType(MoStemAllomorph allomorph, string sType) { foreach (MoMorphType mt in Cache.LangProject.LexDbOA.MorphTypesOA.PossibilitiesOS) { if (mt.Guid.ToString() == sType) { allomorph.MorphTypeRA = mt; break; } } }
public override void DoIt(Set<int> itemsToChange, ProgressState state) { m_cache.BeginUndoTask(XMLViewsStrings.ksUndoBulkEdit, XMLViewsStrings.ksRedoBulkEdit); ISilDataAccess sda = m_cache.MainCacheAccessor; BulkEditBar.ForceRefreshOnUndoRedo(sda); HvoTssComboItem item = m_combo.SelectedItem as HvoTssComboItem; if (item == null) return; int hvoSelMorphType = item.Hvo; bool fSelAffix = MoMorphType.IsAffixType(m_cache, hvoSelMorphType); bool fAnyFundamentalChanges = false; // Preliminary check and warning if changing fundamental type. foreach (int hvoLexEntry in itemsToChange) { int hvoLexemeForm = sda.get_ObjectProp(hvoLexEntry, m_flidParent); if (hvoLexemeForm == 0) continue; int hvoMorphType = sda.get_ObjectProp(hvoLexemeForm, m_flidAtomicProp); if (hvoMorphType == 0) continue; bool fAffix = MoMorphType.IsAffixType(m_cache, hvoMorphType); if (fAffix != fSelAffix) { string msg = String.Format(XMLViewsStrings.ksMorphTypeChangesSlow, (fAffix ? XMLViewsStrings.ksAffixes : XMLViewsStrings.ksStems), (fAffix ? XMLViewsStrings.ksStems : XMLViewsStrings.ksAffixes)); if (MessageBox.Show(this.m_combo, msg, XMLViewsStrings.ksChangingMorphType, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK) { return; } fAnyFundamentalChanges = true; break; // user OKd it, no need to check further. } } if (fAnyFundamentalChanges) { m_containingViewer.SetListModificationInProgress(true); } try { // Report progress 50 times or every 100 items, whichever is more // (but no more than once per item!) Set<int> idsToDel = new Set<int>(); Dictionary<IMoForm, ILexEntry> newForms = new Dictionary<IMoForm, ILexEntry>(); int interval = Math.Min(80, Math.Max(itemsToChange.Count / 50, 1)); int i = 0; foreach (int hvoLexEntry in itemsToChange) { // Guess we're 80% done when through all but deleting leftover objects and moving // new MoForms to LexemeForm slot. if ((i + 1) % interval == 0) { state.PercentDone = i * 80 / itemsToChange.Count; state.Breath(); i++; } int hvoLexemeForm = sda.get_ObjectProp(hvoLexEntry, m_flidParent); if (hvoLexemeForm == 0) continue; int hvoMorphType = sda.get_ObjectProp(hvoLexemeForm, m_flidAtomicProp); if (hvoMorphType == 0) continue; bool fAffix = MoMorphType.IsAffixType(m_cache, hvoMorphType); if (fAffix == fSelAffix) { if (hvoMorphType != hvoSelMorphType) { sda.SetObjProp(hvoLexemeForm, m_flidAtomicProp, hvoSelMorphType); sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvoLexemeForm, m_flidAtomicProp, 0, (hvoSelMorphType == 0 ? 0 : 1), (hvoMorphType == 0 ? 0 : 1)); } else if (fAffix) { ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, hvoLexEntry); IMoAffixAllomorph affix = MoAffixAllomorph.CreateFromDBObject(m_cache, hvoLexemeForm); MoStemAllomorph stem = new MoStemAllomorph(); int[] envs = affix.PhoneEnvRC.HvoArray; SwapFormValues(entry, affix, stem, hvoSelMorphType, idsToDel); foreach (int hvo in envs) stem.PhoneEnvRC.Add(hvo); newForms[stem] = entry; //entry.ChangeAffixToStem(hvoSelMorphType, affix); } else { ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, hvoLexEntry); IMoStemAllomorph stem = MoStemAllomorph.CreateFromDBObject(m_cache, hvoLexemeForm); MoAffixAllomorph affix = new MoAffixAllomorph(); int[] envs = stem.PhoneEnvRC.HvoArray; SwapFormValues(entry, stem, affix, hvoSelMorphType, idsToDel); foreach (int hvo in envs) affix.PhoneEnvRC.Add(hvo); newForms[affix] = entry; //entry.ChangeStemToAffix(hvoSelMorphType, stem); } } else if (fAffix) { ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, hvoLexEntry); IMoAffixAllomorph affix = MoAffixAllomorph.CreateFromDBObject(m_cache, hvoLexemeForm); MoStemAllomorph stem = new MoStemAllomorph(); int[] envs = affix.PhoneEnvRC.HvoArray; SwapFormValues(entry, affix, stem, hvoSelMorphType, idsToDel); foreach (int hvo in envs) stem.PhoneEnvRC.Add(hvo); newForms[stem] = entry; //entry.ChangeAffixToStem(hvoSelMorphType, affix); } else if (fAffix) { ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, hvoLexEntry); IMoAffixAllomorph affix = MoAffixAllomorph.CreateFromDBObject(m_cache, hvoLexemeForm); IMoForm stem = new MoStemAllomorph(); int[] envs = affix.PhoneEnvRC.HvoArray; SwapFormValues(entry, affix, stem, hvoSelMorphType, idsToDel); (stem as IMoStemAllomorph).PhoneEnvRC.Add(envs); newForms[stem] = entry; //entry.ChangeAffixToStem(hvoSelMorphType, affix); } else { ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, hvoLexEntry); IMoStemAllomorph stem = MoStemAllomorph.CreateFromDBObject(m_cache, hvoLexemeForm); IMoForm affix = new MoAffixAllomorph(); int[] envs = stem.PhoneEnvRC.HvoArray; SwapFormValues(entry, stem, affix, hvoSelMorphType, idsToDel); (affix as MoAffixAllomorph).PhoneEnvRC.Add(envs); newForms[affix] = entry; //entry.ChangeStemToAffix(hvoSelMorphType, stem); } } if (fAnyFundamentalChanges) { CmObject.DeleteObjects(idsToDel, m_cache); // Get rid of all the old lexeme forms in one go. state.PercentDone = 90; state.Breath(); foreach (KeyValuePair<IMoForm, ILexEntry> pair in newForms) { pair.Value.LexemeFormOA = pair.Key; } state.PercentDone = 100; state.Breath(); } m_cache.EndUndoTask(); } finally { if (fAnyFundamentalChanges) m_containingViewer.SetListModificationInProgress(false); } }
/// <summary> /// Make a new MoForm (actually the appropriate subclass, as deduced by FindMorphType /// from fullForm), add it to the morphemes of the owning lex entry, set its /// MoMorphType, also as deduced by FindMorphType from tssfullForm, and also set the form /// itself. /// If the entry doesn't already have a lexeme form, put the new morph there. /// </summary> /// <param name="cache"></param> /// <param name="owner"></param> /// <param name="tssfullForm">uses the ws of tssfullForm</param> /// <returns></returns> public static IMoForm MakeMorph(FdoCache cache, ILexEntry owner, ITsString tssfullForm) { int clsidForm; // The subclass of MoMorph to create if we need a new object. string realForm = tssfullForm.Text; // Gets stripped of morpheme-type characters. IMoMorphType mmt = MoMorphType.FindMorphType(cache, new MoMorphTypeCollection(cache), ref realForm, out clsidForm); IMoForm allomorph = null; switch (clsidForm) { case MoStemAllomorph.kclsidMoStemAllomorph: allomorph = new MoStemAllomorph(); break; case MoAffixAllomorph.kclsidMoAffixAllomorph: allomorph = new MoAffixAllomorph(); break; default: throw new InvalidProgramException( "unexpected MoForm subclass returned from FindMorphType"); } if (owner.LexemeFormOAHvo == 0) owner.LexemeFormOA = allomorph; else { // An earlier version inserted at the start, to avoid making it the default // underlying form, which was the last one. But now we have an explicit // lexeme form. So go ahead and put it at the end. allomorph = owner.AlternateFormsOS.Append(allomorph); } ITsString tssRealForm; if (tssfullForm.Text != realForm) { // make a new tsString with the old ws. tssRealForm = StringUtils.MakeTss(realForm, StringUtils.GetWsAtOffset(tssfullForm, 0)); } else { tssRealForm = tssfullForm; } allomorph.MorphTypeRA = mmt; // Has to be done, before the next call. allomorph.FormMinusReservedMarkers = tssRealForm; return allomorph; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create an allomorph. /// </summary> /// <param name="entry">The entry.</param> /// <param name="msa">The msa.</param> /// <param name="tssform">The tssform.</param> /// <param name="morphType">Type of the morph.</param> /// <param name="fLexemeForm">set to <c>true</c> to create a lexeme form.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public static IMoForm CreateAllomorph(ILexEntry entry, IMoMorphSynAnalysis msa, ITsString tssform, IMoMorphType morphType, bool fLexemeForm) { IMoForm allomorph = null; switch (morphType.Guid.ToString()) { case Ling.MoMorphType.kguidMorphProclitic: // Fall through. case Ling.MoMorphType.kguidMorphClitic: // Fall through. case Ling.MoMorphType.kguidMorphEnclitic: Debug.Assert(msa is IMoStemMsa, "Wrong MSA for a clitic."); IMoStemMsa stemMsa = (IMoStemMsa) msa; goto case Ling.MoMorphType.kguidMorphBoundStem; case Ling.MoMorphType.kguidMorphRoot: // Fall through. case Ling.MoMorphType.kguidMorphBoundRoot: // Fall through. case Ling.MoMorphType.kguidMorphStem: // Fall through. case Ling.MoMorphType.kguidMorphParticle: // Fall through. case Ling.MoMorphType.kguidMorphPhrase: // Fall through. case Ling.MoMorphType.kguidMorphDiscontiguousPhrase: // Fall through. // AndyB_Yahoo: On particles, (and LT-485), these are always to be // roots that never take any affixes // AndyB_Yahoo: Therefore, they need to have StemMsas and Stem // allomorphs case Ling.MoMorphType.kguidMorphBoundStem: allomorph = new MoStemAllomorph(); break; default: // All others, which should get an non-stem MSA and an affix allo. Debug.Assert(!(msa is IMoStemMsa), "Wrong MSA for a affix."); allomorph = new MoAffixAllomorph(); break; } if (fLexemeForm) entry.LexemeFormOA = allomorph; else allomorph = (IMoForm) entry.AlternateFormsOS.Append(allomorph); allomorph.MorphTypeRA = morphType; // Has to be done before the next call. ITsString tssAllomorphForm = null; int maxLength = entry.Cache.MaxFieldLength((int) MoForm.MoFormTags.kflidForm); if (tssform.Length > maxLength) { string sMessage = String.Format(Strings.ksTruncatedXXXToYYYChars, fLexemeForm ? Strings.ksLexemeForm : Strings.ksAllomorph, maxLength); System.Windows.Forms.MessageBox.Show(sMessage, Strings.ksWarning, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); tssAllomorphForm = tssform.GetSubstring(0, maxLength); } else { tssAllomorphForm = tssform; } allomorph.FormMinusReservedMarkers = tssAllomorphForm; if ((morphType.Guid.ToString() == Ling.MoMorphType.kguidMorphInfix) || (morphType.Guid.ToString() == Ling.MoMorphType.kguidMorphInfixingInterfix)) { HandleInfix(entry, allomorph); } return allomorph; }
/// <summary> /// Change the affix to a stem (possibly) /// </summary> /// <param name="entry"></param> /// <param name="selectedHvo"></param> /// <param name="sUndo"></param> /// <param name="sRedo"></param> /// <returns>true if change made; false otherwise</returns> private bool ChangeAffixToStem(ILexEntry entry, int selectedHvo, string sUndo, string sRedo) { IMoAffixForm affix = m_obj as IMoAffixForm; if (affix == null) throw new ApplicationException("Affix form is not defined"); List<IMoMorphSynAnalysis> rgmsaOld = new List<IMoMorphSynAnalysis>(); if (m_obj.OwningFlid == (int)LexEntry.LexEntryTags.kflidLexemeForm) { foreach (IMoMorphSynAnalysis msa in entry.MorphoSyntaxAnalysesOC) { if (!(msa is IMoStemMsa)) rgmsaOld.Add(msa); } } if (CheckForAffixDataLoss(affix, rgmsaOld)) return false; FdoCache cache = m_cache; cache.BeginUndoTask(sUndo, sRedo); IMoStemAllomorph stem = new MoStemAllomorph(); SwapValues(entry, affix, stem, selectedHvo, rgmsaOld); // may cause slice/button to be disposed... cache.EndUndoTask(); return true; }