Exemple #1
0
        /// <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);
        }
Exemple #2
0
		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));
		}
Exemple #3
0
        /// <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="owningEntry"></param>
        /// <param name="tssfullForm">uses the ws of tssfullForm</param>
        /// <returns></returns>
        public static IMoForm MakeMorph(ILexEntry owningEntry, ITsString tssfullForm)
        {
            int clsidForm;                   // The subclass of MoMorph to create if we need a new object.
            var realForm = tssfullForm.Text; // Gets stripped of morpheme-type characters.
            var mmt      = FindMorphType(owningEntry.Cache, ref realForm, out clsidForm);

            if (mmt.Guid == MoMorphTypeTags.kguidMorphStem)
            {
                // Might just be that our 'fullform' went in without any 'morpheme-type characters'
                // But really should be an affix type (for instance) (LT-12995)
                // Try to use the owningEntry's morph type.
                if (!owningEntry.IsMorphTypesMixed && owningEntry.MorphTypes.Count > 0)
                {
                    mmt = owningEntry.MorphTypes[0];
                }
                if (mmt.IsAffixType)
                {
                    clsidForm = MoAffixAllomorphTags.kClassId;
                }
            }
            //MoForm allomorph = null;
            IMoForm allomorph;

            switch (clsidForm)
            {
            case MoStemAllomorphTags.kClassId:
                allomorph = new MoStemAllomorph();
                break;

            case MoAffixAllomorphTags.kClassId:
                allomorph = new MoAffixAllomorph();
                break;

            default:
                throw new InvalidProgramException(
                          "unexpected MoForm subclass returned from FindMorphType");
            }
            if (owningEntry.LexemeFormOA == null)
            {
                owningEntry.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.
                owningEntry.AlternateFormsOS.Add(allomorph);
            }
            allomorph.MorphTypeRA = mmt;             // Has to be done, before the next call.

            var wsVern = TsStringUtils.GetWsAtOffset(tssfullForm, 0);

            allomorph.Form.set_String(wsVern,
                                      TsStringUtils.MakeString(EnsureNoMarkers(tssfullForm.Text, owningEntry.Cache), wsVern));
            return(allomorph);
        }
Exemple #4
0
        protected void ConvertStemName(XmlDocument doc, XmlNode node, IMoForm form, XmlNode tempNode)
        {
            MoStemAllomorph sallo = form as MoStemAllomorph;
            IMoStemName     sn    = sallo.StemNameRA;

            if (sn != null)
            {
                tempNode = CreateXmlElement(doc, "stemName", node);
                CreateXmlAttribute(doc, "id", sn.Hvo.ToString(), tempNode);
                tempNode.InnerXml = CreateEntities(sn.Name.BestAnalysisAlternative.Text);
            }
            else
            {               // There's no overt stem name on this allomorph, but there might be overt stem names
                // on other allomorphs in this lexical entry.  This allomorph, then, cannot bear any
                // of the features of these other stem names.  If so, there will be a property named
                // NotStemNameddd or NotStemNamedddNotStemNamedddd, etc.
                tempNode = CreateNotStemNameElement(doc, node, tempNode);
            }
        }
Exemple #5
0
 private void CacheEnvironments(MoStemAllomorph allomorph)
 {
     CacheEnvironments(allomorph.PhoneEnvRC.HvoArray);
     AppendPhoneEnv(kDummyPhoneEnvID, null);
 }