Exemplo n.º 1
0
        /// <summary>
        /// Change the affix to a stem (possibly)
        /// </summary>
        /// <param name="entry"></param>
        /// <param name="type"></param>
        /// <returns>true if change made; false otherwise</returns>
        private bool ChangeAffixToStem(ILexEntry entry, IMoMorphType type)
        {
            var affix = m_obj as IMoAffixForm;

            if (affix == null)
            {
                throw new ApplicationException("Affix form is not defined");
            }
            var rgmsaOld = new List <IMoMorphSynAnalysis>();

            if (m_obj.OwningFlid == LexEntryTags.kflidLexemeForm)
            {
                foreach (var msa in entry.MorphoSyntaxAnalysesOC)
                {
                    if (!(msa is IMoStemMsa))
                    {
                        rgmsaOld.Add(msa);
                    }
                }
            }
            if (CheckForAffixDataLoss(affix, rgmsaOld))
            {
                return(false);
            }
            FdoCache cache = m_cache;
            var      stem  = m_cache.ServiceLocator.GetInstance <IMoStemAllomorphFactory>().Create();

            SwapValues(entry, affix, stem, type, rgmsaOld);             // may cause slice/button to be disposed...
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get the MoMorphType objects for the major affix types.
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="mmtPrefix"></param>
        /// <param name="mmtSuffix"></param>
        /// <param name="mmtInfix"></param>
        public static void GetMajorAffixMorphTypes(LcmCache cache, out IMoMorphType mmtPrefix,
                                                   out IMoMorphType mmtSuffix, out IMoMorphType mmtInfix)
        {
            mmtPrefix = null;
            mmtSuffix = null;
            mmtInfix  = null;

            foreach (IMoMorphType mmt in cache.LanguageProject.LexDbOA.MorphTypesOA.PossibilitiesOS)
            {
                switch (mmt.Guid.ToString())
                {
                case MoMorphTypeTags.kMorphPrefix:
                    mmtPrefix = mmt;
                    break;

                case MoMorphTypeTags.kMorphSuffix:
                    mmtSuffix = mmt;
                    break;

                case MoMorphTypeTags.kMorphInfix:
                    mmtInfix = mmt;
                    break;
                }
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adds the lexeme to the lexicon.
        /// </summary>
        /// <exception cref="ArgumentException">if matching lexeme is already in lexicon</exception>
        /// ------------------------------------------------------------------------------------
        public void AddLexeme(LexicalEntry lexeme)
        {
            LexicalProviderManager.ResetLexicalProviderTimer();
            Logger.WriteEvent("Adding new lexeme from an external application: " + lexeme.LexicalForm);

            NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
            {
                string sForm = lexeme.LexicalForm;
                switch (lexeme.Type)
                {
                case LexemeType.Word:
                    ITsString tss = TsStringUtils.MakeTss(lexeme.LexicalForm, m_cache.DefaultVernWs);
                    m_cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(tss);
                    break;

                default:
                    {
                        SandboxGenericMSA msa = new SandboxGenericMSA();
                        msa.MsaType           = (lexeme.Type == LexemeType.Stem) ? MsaType.kStem : MsaType.kUnclassified;

                        IMoMorphType morphType = GetMorphTypeForLexemeType(lexeme.Type);
                        ITsString tssForm      = TsStringUtils.MakeTss(sForm, m_cache.DefaultVernWs);
                        m_cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(morphType, tssForm, null, msa);
                        break;
                    }
                }
            });
        }
Exemplo n.º 4
0
        private bool ChangeStemToAffix(ILexEntry entry, IMoMorphType type)
        {
            var stem = m_obj as IMoStemAllomorph;

            if (stem == null)
            {
                throw new ApplicationException("Stem allomorph is not defined");
            }
            var rgmsaOld = new List <IMoMorphSynAnalysis>();

            if (m_obj.OwningFlid == LexEntryTags.kflidLexemeForm)
            {
                foreach (var msa in entry.MorphoSyntaxAnalysesOC)
                {
                    if (msa is IMoStemMsa)
                    {
                        rgmsaOld.Add(msa);
                    }
                }
            }
            if (CheckForStemDataLoss(stem, rgmsaOld))
            {
                return(false);
            }
            FdoCache cache = m_cache;
            var      affix = m_cache.ServiceLocator.GetInstance <IMoAffixAllomorphFactory>().Create();

            SwapValues(entry, stem, affix, type, rgmsaOld);
            return(true);
        }
Exemplo n.º 5
0
        public void Search()
        {
            using (var searchEngine = new LexEntrySearchEngine(Cache))
            {
                var          entryFactory = Cache.ServiceLocator.GetInstance <ILexEntryFactory>();
                IMoMorphType stem         = Cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>().GetObject(MoMorphTypeTags.kguidMorphStem);
                ILexEntry    form1        = entryFactory.Create(stem, Cache.TsStrFactory.MakeString("form1", Cache.DefaultVernWs), "gloss1", new SandboxGenericMSA());
                ILexEntry    form2        = entryFactory.Create(stem, Cache.TsStrFactory.MakeString("form2", Cache.DefaultVernWs), "gloss2", new SandboxGenericMSA());
                ILexEntry    form3        = entryFactory.Create(stem, Cache.TsStrFactory.MakeString("form3", Cache.DefaultVernWs), "gloss3", new SandboxGenericMSA());

                m_actionHandler.EndUndoTask();

                Assert.That(searchEngine.Search(new[] { new SearchField(LexEntryTags.kflidLexemeForm, Cache.TsStrFactory.MakeString("fo", Cache.DefaultVernWs)) }),
                            Is.EquivalentTo(new[] { form1.Hvo, form2.Hvo, form3.Hvo }));

                Assert.That(searchEngine.Search(new[] { new SearchField(LexEntryTags.kflidLexemeForm, Cache.TsStrFactory.MakeString("form1", Cache.DefaultVernWs)) }),
                            Is.EquivalentTo(new[] { form1.Hvo }));

                Assert.That(searchEngine.Search(new[] { new SearchField(LexEntryTags.kflidLexemeForm, Cache.TsStrFactory.MakeString("form4", Cache.DefaultVernWs)) }),
                            Is.Empty);

                Assert.That(searchEngine.Search(new[] { new SearchField(LexSenseTags.kflidGloss, Cache.TsStrFactory.MakeString("gl", Cache.DefaultAnalWs)) }),
                            Is.EquivalentTo(new[] { form1.Hvo, form2.Hvo, form3.Hvo }));
            }
        }
Exemplo n.º 6
0
 protected override void HandleMatchingSelectionChanged()
 {
     if (m_selEntryID > 0)
     {
         // Make sure that none of the allomorphs of this entry match the original
         // form before we can enable btnOK.
         ILexEntry le = LexEntry.CreateFromDBObject(m_cache, m_selEntryID);
         // true if current list of MoForms contains one with matching form text.
         bool fMatchingForm = false;
         // true if current list of MoForms contains one of correct type
         bool fMatchingType = false;
         // If we don't know a morpheme type, don't restrict by type.
         IMoMorphType mtOrig = null;
         if (m_hvoType == 0)
         {
             fMatchingType = true;
         }
         else
         {
             mtOrig = MoMorphType.CreateFromDBObject(m_cache, m_hvoType);
         }
         foreach (IMoForm mf in le.AllAllomorphs)
         {
             if (mf.Form.VernacularDefaultWritingSystem == m_formOrig)
             {
                 fMatchingForm = true;
                 fMatchingType = false;
             }
             // To prevent confusion, allow any type that is ambiguous with the
             // current type (or, of course, if it is the SAME type, which for some
             // reason is NOT considered ambiguous).
             if (mtOrig != null && mf.MorphTypeRA != null &&
                 (m_hvoType == mf.MorphTypeRA.Hvo ||
                  mtOrig.IsAmbiguousWith(m_cache, m_types, mtOrig, mf.MorphTypeRA)))
             {
                 fMatchingType = true;
             }
             if (fMatchingForm)
             {
                 break;
             }
         }
         m_fInconsistentType = !fMatchingType;
         m_fMatchingForm     = fMatchingForm;
         if (fMatchingForm && fMatchingType)
         {
             btnOK.Text = SIL.FieldWorks.LexText.Controls.LexTextControls.ksUseAllomorph;
         }
         else
         {
             btnOK.Text = SIL.FieldWorks.LexText.Controls.LexTextControls.ksAddAllomorph_;
         }
         btnOK.Enabled = true;
     }
     else
     {
         base.HandleMatchingSelectionChanged();
     }
 }
Exemplo n.º 7
0
 protected override void HandleMatchingSelectionChanged()
 {
     if (m_selObject != null)
     {
         // Make sure that none of the allomorphs of this entry match the original
         // form before we can enable btnOK.
         // true if current list of MoForms contains one with matching form text.
         bool fMatchingForm = false;
         // true if current list of MoForms contains one of correct type
         bool fMatchingType = false;
         // If we don't know a morpheme type, don't restrict by type.
         IMoMorphType mtOrig = null;
         if (m_hvoType == 0)
         {
             fMatchingType = true;
         }
         else
         {
             mtOrig = m_cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>().GetObject(m_hvoType);
         }
         foreach (var mf in ((ILexEntry)m_selObject).AllAllomorphs)
         {
             if (mf.Form.VernacularDefaultWritingSystem.Text == m_formOrig)
             {
                 fMatchingForm = true;
                 fMatchingType = false;
             }
             // To prevent confusion, allow any type that is ambiguous with the
             // current type (or, of course, if it is the SAME type, which for some
             // reason is NOT considered ambiguous).
             if (mtOrig != null && mf.MorphTypeRA != null &&
                 (m_hvoType == mf.MorphTypeRA.Hvo ||
                  mtOrig.IsAmbiguousWith(mf.MorphTypeRA)))
             {
                 fMatchingType = true;
             }
             if (fMatchingForm)
             {
                 break;
             }
         }
         m_fInconsistentType = !fMatchingType;
         m_fMatchingForm     = fMatchingForm;
         if (fMatchingForm && fMatchingType)
         {
             m_btnOK.Text = LexTextControls.ksUseAllomorph;
         }
         else
         {
             m_btnOK.Text = LexTextControls.ksAddAllomorph_;
         }
         m_btnOK.Enabled = true;
     }
     else
     {
         base.HandleMatchingSelectionChanged();
     }
 }
Exemplo n.º 8
0
		// Determines what to insert based on the presence of prefix and postfix tokens
		private void morphBreakInsert(IMoMorphType morphType)
		{
			if (!String.IsNullOrEmpty(morphType.Prefix) && !String.IsNullOrEmpty(morphType.Postfix))
				GroupText(prefixSpace() + morphType.Prefix, morphType.Postfix + postfixSpace(), true);
			else if (!String.IsNullOrEmpty(morphType.Prefix))
				InsertText(prefixSpace() + morphType.Prefix, false);
			else if (!String.IsNullOrEmpty(morphType.Postfix))
				InsertText(morphType.Postfix + postfixSpace(), false, true);
		}
Exemplo n.º 9
0
        protected ILexEntry AddLexeme(List <ICmObject> addList, string lexForm, string citationForm,
                                      IMoMorphType morphTypePoss, string gloss, IPartOfSpeech catPoss)
        {
            var ws = Cache.DefaultVernWs;
            var le = AddLexeme(addList, lexForm, morphTypePoss, gloss, catPoss);

            le.CitationForm.set_String(ws, citationForm);
            return(le);
        }
Exemplo n.º 10
0
        /// <summary>
        /// This sets the original citation form into the dialog.
        /// </summary>
        /// <param name="sWord"></param>
        /// <param name="sMorphs"></param>
        public void SetDlgInfo(ITsString tssCitationForm, ILexEntry le, Mediator mediator)
        {
            CheckDisposed();

            Debug.Assert(tssCitationForm != null);
            Debug.Assert(le != null);

            m_le       = le;
            m_cache    = le.Cache;
            m_mediator = mediator;

            m_fwtbCitationForm.Font =
                new Font(m_cache.LangProject.DefaultVernacularWritingSystemFont, 10);
            m_fwtbGloss.Font = new Font(m_cache.LangProject.DefaultAnalysisWritingSystemFont, 10);

            IVwStylesheet stylesheet = FontHeightAdjuster.StyleSheetFromMediator(mediator);

            // Set writing system factory and code for the two edit boxes.
            m_fwtbCitationForm.WritingSystemFactory = m_cache.LanguageWritingSystemFactoryAccessor;
            m_fwtbCitationForm.WritingSystemCode    =
                m_cache.LangProject.DefaultVernacularWritingSystem;
            m_fwtbCitationForm.StyleSheet         = stylesheet;
            m_fwtbCitationForm.AdjustStringHeight = false;
            m_fwtbGloss.WritingSystemFactory      = m_cache.LanguageWritingSystemFactoryAccessor;
            m_fwtbGloss.WritingSystemCode         = m_cache.LangProject.DefaultAnalysisWritingSystem;
            m_fwtbGloss.StyleSheet         = stylesheet;
            m_fwtbGloss.AdjustStringHeight = false;
            m_fwtbCitationForm.Tss         = tssCitationForm;
            m_fwtbGloss.Text             = String.Empty;
            m_fwtbCitationForm.HasBorder = false;

            m_msaGroupBox.Initialize(m_cache, mediator, this, new DummyGenericMSA());

            // get the current morph type from the lexical entry.
            IMoMorphType mmt = null;

            foreach (IMoForm mf in le.AlternateFormsOS)
            {
                mmt = mf.MorphTypeRA;
                if (mmt != null)
                {
                    m_msaGroupBox.MorphTypePreference = mmt;
                    break;                     // Assume the first allomorph's type is good enough.
                }
            }

            m_skipCheck        = true;
            m_cbIsStem.Checked = (m_msaGroupBox.MSAType == MsaType.kRoot || m_msaGroupBox.MSAType == MsaType.kStem);
            m_skipCheck        = false;

            // Adjust sizes of the two FwTextBoxes if needed, and adjust the locations for the
            // controls below them.  Do the same for the MSAGroupBox.
            AdjustHeightAndPositions(m_fwtbCitationForm);
            AdjustHeightAndPositions(m_fwtbGloss);
            AdjustHeightAndPositions(m_msaGroupBox);
        }
		protected override void CreateTestData()
		{
			base.CreateTestData();
			var servLoc = Cache.ServiceLocator;
			m_leFact = servLoc.GetInstance<ILexEntryFactory>();
			m_lerFact = servLoc.GetInstance<ILexEntryRefFactory>();
			//m_moFact = servLoc.GetInstance<IMoStemAllomorphFactory>();
			MockLauncher = new MockVectorReferenceLauncher();
			m_wsAnalysis = Cache.DefaultAnalWs;
			m_wsVern = Cache.DefaultVernWs;
			m_wsAnalStr = Cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(Cache.DefaultAnalWs);
			m_noun = GetNounPOS();
			m_stem = GetStemMorphType();
		}
Exemplo n.º 12
0
        protected override void CreateTestData()
        {
            base.CreateTestData();
            var servLoc = Cache.ServiceLocator;

            m_leFact  = servLoc.GetInstance <ILexEntryFactory>();
            m_lerFact = servLoc.GetInstance <ILexEntryRefFactory>();
            //m_moFact = servLoc.GetInstance<IMoStemAllomorphFactory>();
            MockLauncher = new MockAtomicReferenceLauncher();
            m_wsAnalysis = Cache.DefaultAnalWs;
            m_wsVern     = Cache.DefaultVernWs;
            m_wsAnalStr  = Cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(Cache.DefaultAnalWs);
            m_noun       = GetNounPOS();
            m_stem       = GetStemMorphType();
        }
Exemplo n.º 13
0
        private IMoMorphType GetMorphType()
        {
            IMoMorphType morphType      = null;
            string       sMorphTypeName = (m_fPrefix ? "prefix" : "suffix");
            int          iEnglishWs     = WritingSystemServices.FallbackUserWs(m_cache);

            foreach (var type in m_cache.LanguageProject.LexDbOA.MorphTypesOA.ReallyReallyAllPossibilities)
            {
                if (sMorphTypeName == type.Name.get_String(iEnglishWs).Text)
                {
                    morphType = type as IMoMorphType;
                    break;
                }
            }
            return(morphType);
        }
Exemplo n.º 14
0
        public void ResetIndex()
        {
            using (var searchEngine = new LexEntrySearchEngine(Cache))
            {
                var          entryFactory = Cache.ServiceLocator.GetInstance <ILexEntryFactory>();
                IMoMorphType stem         = Cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>().GetObject(MoMorphTypeTags.kguidMorphStem);
                ILexEntry    form1        = entryFactory.Create(stem, Cache.TsStrFactory.MakeString("form1", Cache.DefaultVernWs), "gloss1", new SandboxGenericMSA());
                ILexEntry    form2        = entryFactory.Create(stem, Cache.TsStrFactory.MakeString("form2", Cache.DefaultVernWs), "gloss2", new SandboxGenericMSA());
                ILexEntry    form3        = entryFactory.Create(stem, Cache.TsStrFactory.MakeString("form3", Cache.DefaultVernWs), "gloss3", new SandboxGenericMSA());

                m_actionHandler.EndUndoTask();

                Assert.That(searchEngine.Search(new[] { new SearchField(LexEntryTags.kflidLexemeForm, Cache.TsStrFactory.MakeString("fo", Cache.DefaultVernWs)) }),
                            Is.EquivalentTo(new[] { form1.Hvo, form2.Hvo, form3.Hvo }));
                Assert.That(searchEngine.Search(new[] { new SearchField(LexSenseTags.kflidGloss, Cache.TsStrFactory.MakeString("gl", Cache.DefaultAnalWs)) }),
                            Is.EquivalentTo(new[] { form1.Hvo, form2.Hvo, form3.Hvo }));

                m_actionHandler.BeginUndoTask("Undo doing stuff", "Redo doing stuff");
                ILexEntry form4 = entryFactory.Create(stem, Cache.TsStrFactory.MakeString("form4", Cache.DefaultVernWs), "gloss4", new SandboxGenericMSA());
                m_actionHandler.EndUndoTask();

                Assert.That(searchEngine.Search(new[] { new SearchField(LexEntryTags.kflidLexemeForm, Cache.TsStrFactory.MakeString("fo", Cache.DefaultVernWs)) }),
                            Is.EquivalentTo(new[] { form1.Hvo, form2.Hvo, form3.Hvo, form4.Hvo }));
                Assert.That(searchEngine.Search(new[] { new SearchField(LexSenseTags.kflidGloss, Cache.TsStrFactory.MakeString("gl", Cache.DefaultAnalWs)) }),
                            Is.EquivalentTo(new[] { form1.Hvo, form2.Hvo, form3.Hvo, form4.Hvo }));

                m_actionHandler.BeginUndoTask("Undo doing stuff", "Redo doing stuff");
                form1.Delete();
                m_actionHandler.EndUndoTask();

                Assert.That(searchEngine.Search(new[] { new SearchField(LexEntryTags.kflidLexemeForm, Cache.TsStrFactory.MakeString("fo", Cache.DefaultVernWs)) }),
                            Is.EquivalentTo(new[] { form2.Hvo, form3.Hvo, form4.Hvo }));
                Assert.That(searchEngine.Search(new[] { new SearchField(LexSenseTags.kflidGloss, Cache.TsStrFactory.MakeString("gl", Cache.DefaultAnalWs)) }),
                            Is.EquivalentTo(new[] { form2.Hvo, form3.Hvo, form4.Hvo }));

                m_actionHandler.BeginUndoTask("Undo doing stuff", "Redo doing stuff");
                form2.LexemeFormOA.Form.SetVernacularDefaultWritingSystem("other");
                form2.SensesOS[0].Gloss.SetAnalysisDefaultWritingSystem("other");
                m_actionHandler.EndUndoTask();

                Assert.That(searchEngine.Search(new[] { new SearchField(LexEntryTags.kflidLexemeForm, Cache.TsStrFactory.MakeString("fo", Cache.DefaultVernWs)) }),
                            Is.EquivalentTo(new[] { form3.Hvo, form4.Hvo }));
                Assert.That(searchEngine.Search(new[] { new SearchField(LexSenseTags.kflidGloss, Cache.TsStrFactory.MakeString("gl", Cache.DefaultAnalWs)) }),
                            Is.EquivalentTo(new[] { form3.Hvo, form4.Hvo }));
            }
        }
Exemplo n.º 15
0
        protected ILexEntry AddLexeme(List <ICmObject> addList, string lexForm, IMoMorphType morphTypePoss,
                                      string gloss, IPartOfSpeech categoryPoss)
        {
            var msa = new SandboxGenericMSA {
                MainPOS = categoryPoss
            };
            var comp = new LexEntryComponents {
                MorphType = morphTypePoss, MSA = msa
            };

            comp.GlossAlternatives.Add(m_tssFact.MakeString(gloss, Cache.DefaultAnalWs));
            comp.LexemeFormAlternatives.Add(m_tssFact.MakeString(lexForm, Cache.DefaultVernWs));
            var entry = m_entryFact.Create(comp);

            addList.Add(entry);
            return(entry);
        }
Exemplo n.º 16
0
        //methods

        public override ObjectLabel Execute()
        {
            // Make create lex entry dialog and invoke it.
            ObjectLabel result = null;

            using (InsertEntryDlg dlg = new InsertEntryDlg())
            {
                IMoMorphType morphType = GetMorphType();
                dlg.SetDlgInfo(m_cache, morphType, MsaType.kInfl, m_slot, m_mediator,
                               m_fPrefix ? InsertEntryDlg.MorphTypeFilterType.prefix : InsertEntryDlg.MorphTypeFilterType.suffix);
                dlg.DisableAffixTypeMainPosAndSlot();
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    bool fCreated;
                    int  entryID;
                    dlg.GetDialogInfo(out entryID, out fCreated);
                    if (entryID <= 0)
                    {
                        throw new ArgumentException("Expected entry ID to be greater than 0", "entryID");
                    }
                    ILexEntry lex = LexEntry.CreateFromDBObject(m_cache, entryID);
                    // TODO: what do to make sure it has an infl affix msa?
                    // this just assumes it will
                    bool fInflAffix = false;
                    foreach (IMoMorphSynAnalysis msa in lex.MorphoSyntaxAnalysesOC)
                    {
                        if (msa is IMoInflAffMsa)
                        {
                            fInflAffix = true;
                            break;
                        }
                    }
                    if (!fInflAffix)
                    {
                        int hvoNew = m_cache.CreateObject((int)MoInflAffMsa.kClassId,
                                                          lex.Hvo, (int)LexEntry.LexEntryTags.kflidMorphoSyntaxAnalyses, 0);
                    }
                    int[] hvos = lex.MorphoSyntaxAnalysesOC.HvoArray;
                    if (hvos.Length > 0)
                    {
                        result = ObjectLabel.CreateObjectLabel(m_cache, hvos[0], "");
                    }
                }
            }
            return(result);
        }
Exemplo n.º 17
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the lexeme type that most closely represents the specified morph type.
        /// </summary>
        /// <remarks>This method attempts to do it's best to get the correct lexeme type.
        /// However, the FW database contains many more morph types then can be represented with
        /// the few lexeme types. This creates some ambiguous mappings which are commented
        /// inside this method body.</remarks>
        /// ------------------------------------------------------------------------------------
        private static LexemeType GetLexemeTypeForMorphType(IMoMorphType type)
        {
            if (type != null)
            {
                switch (type.Guid.ToString())
                {
                case MoMorphTypeTags.kMorphCircumfix:
                case MoMorphTypeTags.kMorphInfix:
                case MoMorphTypeTags.kMorphInfixingInterfix:
                case MoMorphTypeTags.kMorphSimulfix:
                case MoMorphTypeTags.kMorphSuprafix:
                case MoMorphTypeTags.kMorphClitic:
                case MoMorphTypeTags.kMorphProclitic:
                    // These don't map neatly to a lexeme type, so we just return prefix
                    return(LexemeType.Prefix);

                case MoMorphTypeTags.kMorphEnclitic:
                    // This one also isn't a great match, but there is no better choice
                    return(LexemeType.Suffix);

                case MoMorphTypeTags.kMorphPrefix:
                case MoMorphTypeTags.kMorphPrefixingInterfix:
                    return(LexemeType.Prefix);

                case MoMorphTypeTags.kMorphSuffix:
                case MoMorphTypeTags.kMorphSuffixingInterfix:
                    return(LexemeType.Suffix);

                case MoMorphTypeTags.kMorphPhrase:
                case MoMorphTypeTags.kMorphDiscontiguousPhrase:
                    return(LexemeType.Phrase);

                case MoMorphTypeTags.kMorphStem:
                case MoMorphTypeTags.kMorphRoot:
                case MoMorphTypeTags.kMorphBoundRoot:
                case MoMorphTypeTags.kMorphBoundStem:
                case MoMorphTypeTags.kMorphParticle:
                    return(LexemeType.Stem);
                }
            }

            // Shouldn't ever get here, but since we don't know what type it is just return
            // a random default and hope for the best.
            return(LexemeType.Stem);
        }
Exemplo n.º 18
0
        private IMoMorphType GetMorphType()
        {
            IMoMorphType morphType = null;
            string       sMorphTypeName;

            sMorphTypeName = (m_fPrefix ? "prefix" : "suffix");
            int iEnglishWs = Cache.FallbackUserWs;

            foreach (ICmPossibility type in m_cache.LangProject.LexDbOA.MorphTypesOA.ReallyReallyAllPossibilities)
            {
                if (sMorphTypeName == type.Name.GetAlternative(iEnglishWs))
                {
                    morphType = type as IMoMorphType;
                    break;
                }
            }
            return(morphType);
        }
Exemplo n.º 19
0
        private void SwapValues(ILexEntry entry, IMoForm origForm, IMoForm newForm, IMoMorphType type,
                                List <IMoMorphSynAnalysis> rgmsaOld)
        {
            DataTree dtree = Slice.ContainingDataTree;
            int      idx   = Slice.IndexInContainer;

            dtree.DoNotRefresh = true;                  // don't let the datatree repeatedly redraw itself...
            entry.ReplaceMoForm(origForm, newForm);
            newForm.MorphTypeRA = type;
            entry.ReplaceObsoleteMsas(rgmsaOld);
            // Dispose of any obsolete slices: new ones will replace them automatically in a moment
            // when the datatree is redrawn.
            foreach (Slice slice in Slice.ContainingDataTree.Slices.ToArray())
            {
                if (slice.IsDisposed)
                {
                    continue;
                }
                if (slice.Object is IMoMorphSynAnalysis && rgmsaOld.Contains(slice.Object as IMoMorphSynAnalysis))
                {
                    slice.Dispose();
                }
                else if (slice is MSAReferenceComboBoxSlice)
                {
                    slice.Dispose();
                }
            }
            // now fix the record list, since it may be showing MoForm dependent columns (e.g. MorphType, Homograph, etc...)
            dtree.FixRecordList();
            dtree.DoNotRefresh = false;
            Slice sliceT = dtree.Slices[idx];

            if (sliceT != null && sliceT is MorphTypeAtomicReferenceSlice)
            {
                // When the new slice is created, the launch button is placed in the middle of
                // the slice rather than at the end.  This fiddling with the slice width seems
                // to fix that.  Then setting the index restores focus to the new slice.
                sliceT.Width += 1;
                sliceT.Width -= 1;
                dtree.GotoNextSliceAfterIndex(idx - 1);
            }
        }
Exemplo n.º 20
0
        protected ILexEntry AddVariantLexeme(List <ICmObject> addList, IVariantComponentLexeme origLe,
                                             string lexForm, IMoMorphType morphTypePoss, string gloss, IPartOfSpeech categoryPoss,
                                             ILexEntryType varType)
        {
            Assert.IsNotNull(varType, "Need a variant entry type!");
            var msa = new SandboxGenericMSA {
                MainPOS = categoryPoss
            };
            var comp = new LexEntryComponents {
                MorphType = morphTypePoss, MSA = msa
            };

            comp.GlossAlternatives.Add(m_tssFact.MakeString(gloss, Cache.DefaultAnalWs));
            comp.LexemeFormAlternatives.Add(m_tssFact.MakeString(lexForm, Cache.DefaultVernWs));
            var entry = m_entryFact.Create(comp);

            entry.MakeVariantOf(origLe, varType);
            addList.Add(entry);
            return(entry);
        }
Exemplo n.º 21
0
        /// <summary>
        /// If the given form matches exactly one of the morphtype prefixes, return that
        /// MoMorphType object.  If that morphtype also has a postfix, add the postfix to
        /// the adjusted form.  This allows better handling of suprafixes for the default
        /// prefix and postfix marking.  (See LT-6081 and LT-6082.)
        /// </summary>
        /// <param name="sForm"></param>
        /// <param name="sAdjustedForm"></param>
        /// <returns></returns>
        public IMoMorphType GetTypeIfMatchesPrefix(string sForm, out string sAdjustedForm)
        {
            sAdjustedForm = sForm;
            IMoMorphType mmtPossible = null;

            for (int i = 0; i < kmtLimit; ++i)
            {
                if (i == MoMorphType.kmtBoundRoot)
                {
                    continue;                           // save bound root for last to allow bound stem to have priority.
                }
                IMoMorphType mmt = (IMoMorphType)InnerList[i];
                if (mmt.Prefix != sForm)
                {
                    continue;
                }
                // If there's a type with a matching prefix and no postfix, return it.  Don't
                // worry about ambiguity -- that's life.
                if (mmt.Postfix == null)
                {
                    return(mmt);
                }
                // We have both a prefix and a postfix.  Save it in case it's unique.
                mmtPossible = mmt;
            }
            IMoMorphType mmtBoundRoot = (IMoMorphType)InnerList[MoMorphType.kmtBoundRoot];

            if (mmtBoundRoot.Prefix == sForm && mmtBoundRoot.Postfix == null)
            {
                return(mmtBoundRoot);
            }
            if (mmtPossible != null)
            {
                sAdjustedForm = mmtPossible.Prefix + mmtPossible.Postfix;
                return(mmtPossible);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 22
0
        private bool IsStemType(IMoMorphType type)
        {
            if (type == null)
            {
                return(false);
            }

            if ((type.Guid == MoMorphTypeTags.kguidMorphBoundRoot) ||
                (type.Guid == MoMorphTypeTags.kguidMorphBoundStem) ||
                (type.Guid == MoMorphTypeTags.kguidMorphEnclitic) ||
                (type.Guid == MoMorphTypeTags.kguidMorphParticle) ||
                (type.Guid == MoMorphTypeTags.kguidMorphProclitic) ||
                (type.Guid == MoMorphTypeTags.kguidMorphRoot) ||
                (type.Guid == MoMorphTypeTags.kguidMorphStem) ||
                (type.Guid == MoMorphTypeTags.kguidMorphClitic) ||
                (type.Guid == MoMorphTypeTags.kguidMorphPhrase) ||
                (type.Guid == MoMorphTypeTags.kguidMorphDiscontiguousPhrase))
            {
                return(true);
            }
            return(false);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Determines if the specified lexeme type matches the specified morph type
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private static bool LexemeTypeAndMorphTypeMatch(LexemeType type, IMoMorphType morphType)
        {
            if (type == LexemeType.Word || type == LexemeType.Lemma)
            {
                throw new ArgumentException("Morph type can never be of the specified lexeme type");
            }

            switch (type)
            {
            case LexemeType.Prefix: return(morphType.IsPrefixishType);

            case LexemeType.Suffix: return(morphType.IsSuffixishType);

            case LexemeType.Stem: return(morphType.IsStemType &&
                                         morphType.Guid != MoMorphTypeTags.kguidMorphPhrase &&
                                         morphType.Guid != MoMorphTypeTags.kguidMorphDiscontiguousPhrase);

            case LexemeType.Phrase:
                return(morphType.Guid == MoMorphTypeTags.kguidMorphPhrase ||
                       morphType.Guid == MoMorphTypeTags.kguidMorphDiscontiguousPhrase);
            }
            return(false);
        }
Exemplo n.º 24
0
        /// <summary>
        /// If the given form matches exactly one of the morphtype prefixes, return that
        /// MoMorphType object.  If that morphtype also has a postfix, add the postfix to
        /// the adjusted form.  This allows better handling of suprafixes for the default
        /// prefix and postfix marking.  (See LT-6081 and LT-6082.)
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="sForm">The form.</param>
        /// <param name="sAdjustedForm">The adjusted form.</param>
        /// <returns></returns>
        public static IMoMorphType GetTypeIfMatchesPrefix(LcmCache cache, string sForm, out string sAdjustedForm)
        {
            sAdjustedForm = sForm;
            IMoMorphType mmtPossible  = null;
            IMoMorphType mmtBoundRoot = null;

            foreach (IMoMorphType mmt in cache.LanguageProject.LexDbOA.MorphTypesOA.PossibilitiesOS)
            {
                if (mmt.Guid == MoMorphTypeTags.kguidMorphBoundRoot)
                {
                    // save bound root for last to allow bound stem to have priority.
                    mmtBoundRoot = mmt;
                }
                else if (mmt.Prefix == sForm)
                {
                    // If there's a type with a matching prefix and no postfix, return it.  Don't
                    // worry about ambiguity -- that's life.
                    if (mmt.Postfix == null)
                    {
                        return(mmt);
                    }
                    // We have both a prefix and a postfix.  Save it in case it's unique.
                    mmtPossible = mmt;
                }
            }
            if (mmtBoundRoot != null && mmtBoundRoot.Prefix == sForm && mmtBoundRoot.Postfix == null)
            {
                return(mmtBoundRoot);
            }

            if (mmtPossible != null)
            {
                sAdjustedForm = mmtPossible.Prefix + mmtPossible.Postfix;
                return(mmtPossible);
            }
            return(null);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets all lexemes in the Lexicon
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public IEnumerable <LexicalEntry> Lexemes()
        {
            LexicalProviderManager.ResetLexicalProviderTimer();

            List <LexicalEntry> entries = new List <LexicalEntry>();

            // Get all of the lexical entries in the database
            foreach (ILexEntry dbEntry in m_cache.ServiceLocator.GetInstance <ILexEntryRepository>().AllInstances())
            {
                IMoMorphType morphType = dbEntry.PrimaryMorphType;
                if (morphType != null)
                {
                    entries.Add(CreateEntryFromDbEntry(GetLexemeTypeForMorphType(morphType), dbEntry));
                }
            }

            // Get all the wordforms in the database
            foreach (IWfiWordform wordform in m_cache.ServiceLocator.GetInstance <IWfiWordformRepository>().AllInstances())
            {
                entries.Add(CreateEntryFromDbWordform(wordform));
            }

            return(entries);
        }
Exemplo n.º 26
0
		private bool ChangeStemToAffix(ILexEntry entry, IMoMorphType type)
		{
			var stem = m_obj as IMoStemAllomorph;
			if (stem == null)
				throw new ApplicationException("Stem allomorph is not defined");
			var rgmsaOld = new List<IMoMorphSynAnalysis>();
			if (m_obj.OwningFlid == LexEntryTags.kflidLexemeForm)
			{
				foreach (var msa in entry.MorphoSyntaxAnalysesOC)
				{
					if (msa is IMoStemMsa)
						rgmsaOld.Add(msa);
				}
			}
			if (CheckForStemDataLoss(stem, rgmsaOld))
				return false;
			FdoCache cache = m_cache;
			var affix = m_cache.ServiceLocator.GetInstance<IMoAffixAllomorphFactory>().Create();
			SwapValues(entry, stem, affix, type, rgmsaOld);
			return true;
		}
Exemplo n.º 27
0
		private bool IsStemType(IMoMorphType type)
		{
			if (type == null)
				return false;

			if ((type.Guid == MoMorphTypeTags.kguidMorphBoundRoot) ||
				(type.Guid == MoMorphTypeTags.kguidMorphBoundStem) ||
				(type.Guid == MoMorphTypeTags.kguidMorphEnclitic) ||
				(type.Guid == MoMorphTypeTags.kguidMorphParticle) ||
				(type.Guid == MoMorphTypeTags.kguidMorphProclitic) ||
				(type.Guid == MoMorphTypeTags.kguidMorphRoot) ||
				(type.Guid == MoMorphTypeTags.kguidMorphStem) ||
				(type.Guid == MoMorphTypeTags.kguidMorphClitic) ||
				(type.Guid == MoMorphTypeTags.kguidMorphPhrase) ||
				(type.Guid == MoMorphTypeTags.kguidMorphDiscontiguousPhrase))
				return true;
			return false;
		}
Exemplo n.º 28
0
 // This one is different because for stems, spaces must always be included on both sides where needed
 private void morphBreakInsertStem(IMoMorphType morphType)
 {
     groupText(prefixSpace() + morphType.Prefix, morphType.Postfix + postfixSpace(), true);
 }
Exemplo n.º 29
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create a new entry.
		/// The caller is expected to call PropChanged on the cache to notify the record
		/// list of the new record.
		/// </summary>
		/// <param name="cache">The cache.</param>
		/// <param name="morphType">Type of the morph.</param>
		/// <param name="tssLexemeForm">The TSS lexeme form.</param>
		/// <param name="gloss">The gloss.</param>
		/// <param name="dummyMSA">The dummy MSA.</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public static ILexEntry CreateEntry(FdoCache cache, IMoMorphType morphType,
			ITsString tssLexemeForm, string gloss, DummyGenericMSA dummyMSA)
		{
			using (new UndoRedoTaskHelper(cache, Strings.ksUndoCreateEntry, Strings.ksRedoCreateEntry))
			{
				ILexEntry entry = null;
				// NO: Since this fires a PropChanged, and we do it ourselves later on.
				// entry = (LexEntry)entries.Add(new LexEntry());

				// CreateObject creates the entry without a PropChanged.
				int entryHvo = cache.CreateObject(LexEntry.kClassId,
					cache.LangProject.LexDbOAHvo,
					(int)LexDb.LexDbTags.kflidEntries,
					0); // 0 is fine, since the entries prop is not a sequence.
				entry = LexEntry.CreateFromDBObject(cache, entryHvo);

				ILexSense sense = LexSense.CreateSense(entry, dummyMSA, gloss);

				if (morphType.Guid.ToString() == MoMorphType.kguidMorphCircumfix)
				{
					// Set Lexeme form to lexeme form and circumfix
					SetCircumfixLexemeForm(cache, entry, tssLexemeForm, morphType);
					// Create two allomorphs, one for the left member and one for the right member.
					SplitCircumfixIntoLeftAndRightAllomorphs(cache, entry, tssLexemeForm, sense);
				}
				else
				{
					IMoForm allomorph = MoForm.CreateAllomorph(entry, sense.MorphoSyntaxAnalysisRA, tssLexemeForm, morphType, true);
				}
				(entry as LexEntry).UpdateHomographNumbersAccountingForNewEntry();
				return entry;
			}
		}
Exemplo n.º 30
0
		/// <summary>
		/// Checks two morph types objects to see if they are ambiguous,
		/// regarding the markers used to type them.
		/// </summary>
		/// <param name="cache">FDO cache.</param>
		/// <param name="types">Collection of morph types.</param>
		/// <param name="first">First morph type to compare</param>
		/// <param name="second">Second morph type to compare</param>
		/// <returns>True, if the two morph types are ambiguous, otherwise false.</returns>
		public bool IsAmbiguousWith(FdoCache cache, MoMorphTypeCollection types,
			IMoMorphType first, IMoMorphType second)
		{
			// Debug.Assert(types != null); JohnT removed assert as argument is not used and new caller does not provide
			Debug.Assert(first != null);
			Debug.Assert(second != null);
			int idxFirst = FindMorphTypeIndex(cache, first);
			int idxSecond = FindMorphTypeIndex(cache, second);
			bool areAmbiguous = false;

			switch (idxFirst)
			{
				case kmtCircumfix:
				case kmtRoot:
				case kmtProclitic:
				case kmtClitic:
				case kmtParticle:
				case kmtEnclitic:
				case kmtStem:
				case kmtPhrase:
				case kmtDiscontiguousPhrase:
					if (idxSecond != idxFirst)
						areAmbiguous = (idxSecond == kmtCircumfix)
							|| (idxSecond == kmtRoot)
							|| (idxSecond == kmtClitic)
							|| (idxSecond == kmtProclitic)
							|| (idxSecond == kmtParticle)
							|| (idxSecond == kmtEnclitic)
							|| (idxSecond == kmtStem)
							|| (idxSecond == kmtPhrase)
							|| (idxSecond == kmtDiscontiguousPhrase);
					break;
				case kmtBoundStem:
					areAmbiguous = (idxSecond == kmtBoundRoot);
					break;
				case kmtBoundRoot:
					areAmbiguous = (idxSecond == kmtBoundStem);
					break;
				case kmtInfix:
					areAmbiguous = (idxSecond == kmtInfixingInterfix);
					break;
				case kmtInfixingInterfix:
					areAmbiguous = (idxSecond == kmtInfix);
					break;
				case kmtPrefix:
					areAmbiguous = (idxSecond == kmtPrefixingInterfix);
					break;
				case kmtPrefixingInterfix:
					areAmbiguous = (idxSecond == kmtPrefix);
					break;
				case kmtSuffix:
					areAmbiguous = (idxSecond == kmtSuffixingInterfix);
					break;
				case kmtSuffixingInterfix:
					areAmbiguous = (idxSecond == kmtSuffix);
					break;
				default:
					break;
			}

			return areAmbiguous;
		}
Exemplo n.º 31
0
		/// ------------------------------------------------------------------------------------
		/// <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>
		/// ------------------------------------------------------------------------------------
		internal static IMoForm CreateAllomorph(ILexEntry entry, IMoMorphSynAnalysis msa,
											  ITsString tssform, IMoMorphType morphType, bool fLexemeForm)
		{
			MoForm allomorph = null;
			switch (morphType.Guid.ToString())
			{
				case MoMorphTypeTags.kMorphProclitic: // Fall through.
				case MoMorphTypeTags.kMorphClitic: // Fall through.
				case MoMorphTypeTags.kMorphEnclitic:
					Debug.Assert(msa is MoStemMsa, "Wrong MSA for a clitic.");
#pragma warning disable 168
					var stemMsa = (IMoStemMsa)msa;
#pragma warning restore 168
					goto case MoMorphTypeTags.kMorphBoundStem;
				case MoMorphTypeTags.kMorphRoot: // Fall through.
				case MoMorphTypeTags.kMorphBoundRoot: // Fall through.
				case MoMorphTypeTags.kMorphStem: // Fall through.
				case MoMorphTypeTags.kMorphParticle: // Fall through.
				case MoMorphTypeTags.kMorphPhrase: // Fall through.
				case MoMorphTypeTags.kMorphDiscontiguousPhrase: // 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 MoMorphTypeTags.kMorphBoundStem:
					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
				entry.AlternateFormsOS.Add(allomorph);
			allomorph.MorphTypeRA = morphType; // Has to be done before the next call.
			ITsString tssAllomorphForm = tssform;

			allomorph.FormMinusReservedMarkers = tssAllomorphForm;
			if ((morphType.Guid == MoMorphTypeTags.kguidMorphInfix) ||
				(morphType.Guid == MoMorphTypeTags.kguidMorphInfixingInterfix))
			{
				HandleInfix(entry, allomorph);
			}
			return allomorph;
		}
Exemplo n.º 32
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Determines if the specified lexeme type matches the specified morph type
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private static bool LexemeTypeAndMorphTypeMatch(LexemeType type, IMoMorphType morphType)
		{
			if (type == LexemeType.Word || type == LexemeType.Lemma)
				throw new ArgumentException("Morph type can never be of the specified lexeme type");

			switch (type)
			{
				case LexemeType.Prefix: return morphType.IsPrefixishType;
				case LexemeType.Suffix: return morphType.IsSuffixishType;
				case LexemeType.Stem: return morphType.IsStemType &&
					morphType.Guid != MoMorphTypeTags.kguidMorphPhrase &&
					morphType.Guid != MoMorphTypeTags.kguidMorphDiscontiguousPhrase;
				case LexemeType.Phrase:
					return morphType.Guid == MoMorphTypeTags.kguidMorphPhrase ||
						morphType.Guid == MoMorphTypeTags.kguidMorphDiscontiguousPhrase;
			}
			return false;
		}
Exemplo n.º 33
0
		/// <summary>
		/// Get the MoMorphType objects for the major affix types.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="mmtPrefix"></param>
		/// <param name="mmtSuffix"></param>
		/// <param name="mmtInfix"></param>
		public static void GetMajorAffixMorphTypes(FdoCache cache, out IMoMorphType mmtPrefix,
			out IMoMorphType mmtSuffix, out IMoMorphType mmtInfix)
		{
			mmtPrefix = null;
			mmtSuffix = null;
			mmtInfix = null;

			foreach (IMoMorphType mmt in cache.LangProject.LexDbOA.MorphTypesOA.PossibilitiesOS)
			{
				switch (mmt.Guid.ToString())
				{
					case MoMorphType.kguidMorphPrefix:
						mmtPrefix = mmt;
						break;
					case MoMorphType.kguidMorphSuffix:
						mmtSuffix = mmt;
						break;
					case MoMorphType.kguidMorphInfix:
						mmtInfix = mmt;
						break;
				}
			}
		}
Exemplo n.º 34
0
		partial void MorphTypeRASideEffects(IMoMorphType oldObjValue, IMoMorphType newObjValue)
		{
			ClearMonomorphemicMorphData();
			if (Owner is LexEntry && Owner.IsValidObject)
			{
				var entry = ((LexEntry) Owner);
				// Now we have to figure out the old PrimaryMorphType of the entry.
				// It is determined by the first item in this list which HAD a morph type (if any)
				var morphs = entry.AlternateFormsOS.Reverse().ToList();
				if (entry.LexemeFormOA != null)
					morphs.Insert(0, entry.LexemeFormOA);
				IMoMorphType oldPrimaryType = null;
				foreach (var morph in morphs)
				{
					// If the morpheme is this, the one that is changing, then we consider
					// the old value that this is changing from, in determining the old PMT.
					var mt = (morph == this ? oldObjValue : morph.MorphTypeRA);
					if (mt != null)
					{
						oldPrimaryType = mt;
						break;
					}
				}
				if (oldPrimaryType != entry.PrimaryMorphType)
					entry.UpdateHomographs(oldPrimaryType);
			}
		}
Exemplo n.º 35
0
		/// <summary>
		/// Create a new circumfix allomorph and add it to the given entry.
		/// </summary>
		/// <param name="entry"></param>
		/// <param name="sense"></param>
		/// <param name="lexemeForm"></param>
		/// <param name="morphType"></param>
		/// <returns></returns>
		public IMoAffixAllomorph CreateCircumfix(ILexEntry entry, ILexSense sense, ITsString lexemeForm, IMoMorphType morphType)
		{
			var lexemeAllo = new MoAffixAllomorph();
			entry.LexemeFormOA = lexemeAllo;
			lexemeAllo.Form.set_String(TsStringUtils.GetWsAtOffset(lexemeForm, 0), lexemeForm);
			lexemeAllo.MorphTypeRA = morphType;
			lexemeAllo.IsAbstract = true;

			// split citation form into left and right parts
			var aSpacePeriod = new[] { ' ', '.' };
			var lexemeFormAsString = lexemeForm.Text;
			var wsVern = TsStringUtils.GetWsAtOffset(lexemeForm, 0);
			var iLeftEnd = lexemeFormAsString.IndexOfAny(aSpacePeriod);
			var sLeftMember = iLeftEnd < 0 ? lexemeFormAsString : lexemeFormAsString.Substring(0, iLeftEnd);
			var iRightBegin = lexemeFormAsString.LastIndexOfAny(aSpacePeriod);
			var sRightMember = iRightBegin < 0 ? lexemeFormAsString : lexemeFormAsString.Substring(iRightBegin + 1);
			// Create left and right allomorphs
			IMoMorphType mmtPrefix;
			IMoMorphType mmtSuffix;
			IMoMorphType mmtInfix;
			MorphServices.GetMajorAffixMorphTypes(m_cache, out mmtPrefix, out mmtSuffix, out mmtInfix);
			int clsidForm;
			var mmt = MorphServices.FindMorphType(m_cache, ref sLeftMember, out clsidForm);
			if ((mmt.Hvo != mmtPrefix.Hvo) &&
				(mmt.Hvo != mmtInfix.Hvo))
				mmt = mmtPrefix; // force a prefix if it's neither a prefix nor an infix
#pragma warning disable 168
			var allomorph = MoForm.CreateAllomorph(entry, sense.MorphoSyntaxAnalysisRA,
												   TsStringUtils.MakeTss(sLeftMember, wsVern), mmt, false);
#pragma warning disable 168
			mmt = MorphServices.FindMorphType(m_cache, ref sRightMember, out clsidForm);
			if ((mmt.Hvo != mmtInfix.Hvo) &&
				(mmt.Hvo != mmtSuffix.Hvo))
				mmt = mmtSuffix; // force a suffix if it's neither a suffix nor an infix
			allomorph = MoForm.CreateAllomorph(entry, sense.MorphoSyntaxAnalysisRA,
											   TsStringUtils.MakeTss(sRightMember, wsVern), mmt, false);

			return lexemeAllo;
		}
Exemplo n.º 36
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create a new entry.
		/// </summary>
		/// <param name="morphType">Type of the morph.</param>
		/// <param name="tssLexemeForm">The TSS lexeme form.</param>
		/// <param name="gloss">The gloss.</param>
		/// <param name="sandboxMSA">The dummy MSA.</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public ILexEntry Create(IMoMorphType morphType, ITsString tssLexemeForm, ITsString gloss, SandboxGenericMSA sandboxMSA)
		{
			var entry = Create();
			var sense = m_cache.ServiceLocator.GetInstance<ILexSenseFactory>().Create(entry, sandboxMSA, gloss);

			if (morphType.Guid == MoMorphTypeTags.kguidMorphCircumfix)
			{
				m_cache.ServiceLocator.GetInstance<IMoAffixAllomorphFactory>().CreateCircumfix(
					entry, sense, tssLexemeForm, morphType);
			}
			else
			{
#pragma warning disable 168
				var allomorph = MoForm.CreateAllomorph(entry, sense.MorphoSyntaxAnalysisRA, tssLexemeForm, morphType, true);
#pragma warning restore 168
			}
			// (We don't want a citation form by default.  See LT-7220.)
			return entry;
		}
Exemplo n.º 37
0
		/// <summary>
		/// Creates a new LexEntry with the given fields
		/// </summary>
		/// <param name="morphType"></param>
		/// <param name="tssLexemeForm"></param>
		/// <param name="gloss">string for gloss, placed in DefaultAnalysis ws</param>
		/// <param name="sandboxMSA"></param>
		/// <returns></returns>
		public ILexEntry Create(IMoMorphType morphType, ITsString tssLexemeForm, string gloss, SandboxGenericMSA sandboxMSA)
		{
			int writingSystem = m_cache.WritingSystemFactory.GetWsFromStr(m_cache.LangProject.DefaultAnalysisWritingSystem.Id);
			var tssGloss = m_cache.TsStrFactory.MakeString(gloss, writingSystem);
			return Create(morphType, tssLexemeForm, tssGloss, sandboxMSA);
		}
Exemplo n.º 38
0
        /// <summary>
        /// This sets the original wordform and morph-broken word into the dialog.
        /// </summary>
        /// <param name="sWord"></param>
        /// <param name="sMorphs"></param>
        public void Initialize(ITsString tssWord, string sMorphs, ILgWritingSystemFactory wsf,
                               FdoCache cache, SIL.Utils.StringTable stringTable, IVwStylesheet stylesheet)
        {
            CheckDisposed();

            Debug.Assert(tssWord != null);
            Debug.Assert(wsf != null);
            ITsTextProps ttp = tssWord.get_Properties(0);

            Debug.Assert(ttp != null);
            int var;
            int ws = ttp.GetIntPropValues((int)FwTextPropType.ktptWs, out var);

            Debug.Assert(ws != 0);
            IWritingSystem wsVern = wsf.get_EngineOrNull(ws);

            Debug.Assert(wsVern != null);
            // The following is needed for Graphite fonts.
            string sFontVar = wsVern.FontVariation;

            if (sFontVar == null)
            {
                sFontVar = "";
            }

            this.m_txtMorphs.WritingSystemFactory = wsf;
            this.m_txtMorphs.WritingSystemCode    = ws;
            this.m_txtMorphs.Text = sMorphs;
            m_sMorphs             = sMorphs;

            // Fix the help strings to use the actual MorphType markers.
            IMoMorphType mmtStem      = null;
            IMoMorphType mmtPrefix    = null;
            IMoMorphType mmtSuffix    = null;
            IMoMorphType mmtInfix     = null;
            IMoMorphType mmtBoundStem = null;
            IMoMorphType mmtProclitic = null;
            IMoMorphType mmtEnclitic  = null;
            IMoMorphType mmtSimulfix  = null;
            IMoMorphType mmtSuprafix  = null;

            MoMorphType.GetMajorMorphTypes(cache, out mmtStem, out mmtPrefix, out mmtSuffix, out mmtInfix,
                                           out mmtBoundStem, out mmtProclitic, out mmtEnclitic, out mmtSimulfix, out mmtSuprafix);
            // Format the labels according to the MoMorphType Prefix/Postfix values.
            string sExample1     = stringTable.GetString("EditMorphBreaks-Example1", "DialogStrings");
            string sExample2     = stringTable.GetString("EditMorphBreaks-Example2", "DialogStrings");
            string sStemExample  = stringTable.GetString("EditMorphBreaks-stemExample", "DialogStrings");
            string sAffixExample = stringTable.GetString("EditMorphBreaks-affixExample", "DialogStrings");

            lblHelp2_Example1.Text = String.Format(sExample1,
                                                   mmtStem.Prefix == null ? "" : mmtStem.Prefix,
                                                   mmtStem.Postfix == null ? "" : mmtStem.Postfix);
            lblHelp2_Example2.Text = String.Format(sExample2,
                                                   mmtSuffix.Prefix == null ? "" : mmtSuffix.Prefix,
                                                   mmtSuffix.Postfix == null ? "" : mmtSuffix.Postfix);
            lblBreak_stemExample.Text = String.Format(sStemExample,
                                                      mmtStem.Prefix == null ? "" : mmtStem.Prefix,
                                                      mmtStem.Postfix == null ? "" : mmtStem.Postfix);
            lblBreak_boundStemExample.Text = String.Format(sStemExample,
                                                           mmtBoundStem.Prefix == null ? "" : mmtBoundStem.Prefix,
                                                           mmtBoundStem.Postfix == null ? "" : mmtBoundStem.Postfix);
            lblBreak_prefixExample.Text = String.Format(sAffixExample,
                                                        mmtPrefix.Prefix == null ? "" : " " + mmtPrefix.Prefix,
                                                        mmtPrefix.Postfix == null ? "" : mmtPrefix.Postfix + " ");
            lblBreak_suffixExample.Text = String.Format(sAffixExample,
                                                        mmtSuffix.Prefix == null ? "" : " " + mmtSuffix.Prefix,
                                                        mmtSuffix.Postfix == null ? "" : mmtSuffix.Postfix + " ");
            lblBreak_infixExample.Text = String.Format(sAffixExample,
                                                       mmtInfix.Prefix == null ? "" : " " + mmtInfix.Prefix,
                                                       mmtInfix.Postfix == null ? "" : mmtInfix.Postfix + " ");
            lblBreak_procliticExample.Text = String.Format(sAffixExample,
                                                           mmtProclitic.Prefix == null ? "" : " " + mmtProclitic.Prefix,
                                                           mmtProclitic.Postfix == null ? "" : mmtProclitic.Postfix + " ");
            lblBreak_encliticExample.Text = String.Format(sAffixExample,
                                                          mmtEnclitic.Prefix == null ? "" : " " + mmtEnclitic.Prefix,
                                                          mmtEnclitic.Postfix == null ? "" : mmtEnclitic.Postfix + " ");
            lblBreak_simulfixExample.Text = String.Format(sAffixExample,
                                                          mmtSimulfix.Prefix == null ? "" : " " + mmtSimulfix.Prefix,
                                                          mmtSimulfix.Postfix == null ? "" : mmtSimulfix.Postfix + " ");
            lblBreak_suprafixExample.Text = String.Format(sAffixExample,
                                                          mmtSuprafix.Prefix == null ? "" : " " + mmtSuprafix.Prefix,
                                                          mmtSuprafix.Postfix == null ? "" : mmtSuprafix.Postfix + " ");

            morphBreakContextMenu = new MorphBreakHelperMenu(m_txtMorphs, FwApp.App, cache, stringTable);
            m_txtMorphs.AdjustForStyleSheet(this, null, stylesheet);
        }
Exemplo n.º 39
0
		/// <summary>
		/// Checks two morph types objects to see if they are ambiguous,
		/// regarding the markers used to type them.
		/// </summary>
		/// <param name="other">morph type to compare with</param>
		/// <returns>True, if the two morph types are ambiguous, otherwise false.</returns>
		public bool IsAmbiguousWith(IMoMorphType other)
		{
			Debug.Assert(other != null);
			var areAmbiguous = false;

			switch (Guid.ToString())
			{
				case MoMorphTypeTags.kMorphCircumfix:
				case MoMorphTypeTags.kMorphRoot:
				case MoMorphTypeTags.kMorphClitic:
				case MoMorphTypeTags.kMorphParticle:
				case MoMorphTypeTags.kMorphStem:
					if (Guid != other.Guid)
					{
						areAmbiguous = (other.Guid == MoMorphTypeTags.kguidMorphCircumfix)
									   || (other.Guid == MoMorphTypeTags.kguidMorphRoot)
									   || (other.Guid == MoMorphTypeTags.kguidMorphClitic)
									   || (other.Guid == MoMorphTypeTags.kguidMorphParticle)
									   || (other.Guid == MoMorphTypeTags.kguidMorphStem);
					}
					break;
				case MoMorphTypeTags.kMorphPhrase:
					areAmbiguous = (other.Guid == MoMorphTypeTags.kguidMorphDiscontiguousPhrase);
					break;
				case MoMorphTypeTags.kMorphDiscontiguousPhrase:
					areAmbiguous = (other.Guid == MoMorphTypeTags.kguidMorphPhrase);
					break;
				case MoMorphTypeTags.kMorphBoundStem:
					areAmbiguous = (other.Guid == MoMorphTypeTags.kguidMorphBoundRoot);
					break;
				case MoMorphTypeTags.kMorphBoundRoot:
					areAmbiguous = (other.Guid == MoMorphTypeTags.kguidMorphBoundStem);
					break;
				case MoMorphTypeTags.kMorphInfix:
					areAmbiguous = (other.Guid == MoMorphTypeTags.kguidMorphInfixingInterfix);
					break;
				case MoMorphTypeTags.kMorphInfixingInterfix:
					areAmbiguous = (other.Guid == MoMorphTypeTags.kguidMorphInfix);
					break;
				case MoMorphTypeTags.kMorphPrefix:
					areAmbiguous = (other.Guid == MoMorphTypeTags.kguidMorphPrefixingInterfix);
					break;
				case MoMorphTypeTags.kMorphPrefixingInterfix:
					areAmbiguous = (other.Guid == MoMorphTypeTags.kguidMorphPrefix);
					break;
				case MoMorphTypeTags.kMorphSuffix:
					areAmbiguous = (other.Guid == MoMorphTypeTags.kguidMorphSuffixingInterfix);
					break;
				case MoMorphTypeTags.kMorphSuffixingInterfix:
					areAmbiguous = (other.Guid == MoMorphTypeTags.kguidMorphSuffix);
					break;
				default:
					break;
			}

			return areAmbiguous;
		}
Exemplo n.º 40
0
		/// <summary>
		/// Create a new IMoMorphType instance with the given guid and owner.
		/// It will be added to the end of the SubPossibilities list.
		/// </summary>
		IMoMorphType IMoMorphTypeFactory.Create(Guid guid, IMoMorphType owner)
		{
			if (owner == null) throw new ArgumentNullException("owner");

			IMoMorphType mmt;
			if (guid == Guid.Empty)
			{
				mmt = Create();
			}
			else
			{
				int hvo = ((IDataReader)m_cache.ServiceLocator.GetInstance<IDataSetup>()).GetNextRealHvo();
				mmt = new MoMorphType(m_cache, hvo, guid);
			}
			owner.SubPossibilitiesOS.Add(mmt);
			return mmt;
		}
Exemplo n.º 41
0
		/// <summary>
		/// Get the MoMorphType objects for the major types.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="mmtStem"></param>
		/// <param name="mmtPrefix"></param>
		/// <param name="mmtSuffix"></param>
		/// <param name="mmtInfix"></param>
		/// <param name="mmtBoundStem"></param>
		/// <param name="mmtProclitic"></param>
		/// <param name="mmtEnclitic"></param>
		/// <param name="mmtSimulfix"></param>
		/// <param name="mmtSuprafix"></param>
		public static void GetMajorMorphTypes(FdoCache cache, out IMoMorphType mmtStem, out IMoMorphType mmtPrefix,
			out IMoMorphType mmtSuffix, out IMoMorphType mmtInfix, out IMoMorphType mmtBoundStem, out IMoMorphType mmtProclitic,
			out IMoMorphType mmtEnclitic, out IMoMorphType mmtSimulfix, out IMoMorphType mmtSuprafix)
		{
			mmtStem = null;
			mmtPrefix = null;
			mmtSuffix = null;
			mmtInfix = null;
			mmtBoundStem = null;
			mmtProclitic = null;
			mmtEnclitic = null;
			mmtSimulfix = null;
			mmtSuprafix = null;

			foreach (IMoMorphType mmt in cache.LangProject.LexDbOA.MorphTypesOA.PossibilitiesOS)
			{
				switch (mmt.Guid.ToString())
				{
					case MoMorphType.kguidMorphStem:
						mmtStem = mmt;
						break;
					case MoMorphType.kguidMorphPrefix:
						mmtPrefix = mmt;
						break;
					case MoMorphType.kguidMorphSuffix:
						mmtSuffix = mmt;
						break;
					case MoMorphType.kguidMorphInfix:
						mmtInfix = mmt;
						break;
					case MoMorphType.kguidMorphBoundStem:
						mmtBoundStem = mmt;
						break;
					case MoMorphType.kguidMorphProclitic:
						mmtProclitic = mmt;
						break;
					case MoMorphType.kguidMorphEnclitic:
						mmtEnclitic = mmt;
						break;
					case MoMorphType.kguidMorphSimulfix:
						mmtSimulfix = mmt;
						break;
					case MoMorphType.kguidMorphSuprafix:
						mmtSuprafix = mmt;
						break;
				}
			}
		}
Exemplo n.º 42
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the lexeme type that most closely represents the specified morph type.
		/// </summary>
		/// <remarks>This method attempts to do it's best to get the correct lexeme type.
		/// However, the FW database contains many more morph types then can be represented with
		/// the few lexeme types. This creates some ambiguous mappings which are commented
		/// inside this method body.</remarks>
		/// ------------------------------------------------------------------------------------
		private LexemeType GetLexemeTypeForMorphType(IMoMorphType type)
		{
			switch (type.Guid.ToString())
			{
				case MoMorphTypeTags.kMorphCircumfix:
				case MoMorphTypeTags.kMorphInfix:
				case MoMorphTypeTags.kMorphInfixingInterfix:
				case MoMorphTypeTags.kMorphSimulfix:
				case MoMorphTypeTags.kMorphSuprafix:
				case MoMorphTypeTags.kMorphClitic:
				case MoMorphTypeTags.kMorphProclitic:
					// These don't map neatly to a lexeme type, so we just return prefix
					return LexemeType.Prefix;

				case MoMorphTypeTags.kMorphEnclitic:
					// This one also isn't a great match, but there is no better choice
					return LexemeType.Suffix;

				case MoMorphTypeTags.kMorphPrefix:
				case MoMorphTypeTags.kMorphPrefixingInterfix:
					return LexemeType.Prefix;

				case MoMorphTypeTags.kMorphSuffix:
				case MoMorphTypeTags.kMorphSuffixingInterfix:
					return LexemeType.Suffix;

				case MoMorphTypeTags.kMorphPhrase:
				case MoMorphTypeTags.kMorphDiscontiguousPhrase:
					return LexemeType.Phrase;

				case MoMorphTypeTags.kMorphStem:
				case MoMorphTypeTags.kMorphRoot:
				case MoMorphTypeTags.kMorphBoundRoot:
				case MoMorphTypeTags.kMorphBoundStem:
				case MoMorphTypeTags.kMorphParticle:
					return LexemeType.Stem;
			}

			// Shouldn't ever get here, but since we don't know what type it is just return
			// a random default and hope for the best.
			return LexemeType.Stem;
		}
Exemplo n.º 43
0
		/// <summary>
		///  Get the enumeration MorphType for the given MoMorphType object.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="mmt"></param>
		/// <returns></returns>
		public static int FindMorphTypeIndex(FdoCache cache, IMoMorphType mmt)
		{
			Debug.Assert(cache != null);
			if (mmt == null)
				return kmtUnknown;
			//Debug.Assert(mmt != null); // JT: can happen from MorphType routine if Morph has no type set.

			int mtIdx;
			switch (mmt.Guid.ToString())
			{
				case MoMorphType.kguidMorphBoundRoot:
					mtIdx = kmtBoundRoot;
					break;
				case MoMorphType.kguidMorphBoundStem:
					mtIdx = kmtBoundStem;
					break;
				case MoMorphType.kguidMorphCircumfix:
					mtIdx = kmtCircumfix;
					break;
				case MoMorphType.kguidMorphClitic:
					mtIdx = kmtClitic;
					break;
				case MoMorphType.kguidMorphEnclitic:
					mtIdx = kmtEnclitic;
					break;
				case MoMorphType.kguidMorphInfix:
					mtIdx = kmtInfix;
					break;
				case MoMorphType.kguidMorphParticle:
					mtIdx = kmtParticle;
					break;
				case MoMorphType.kguidMorphPrefix:
					mtIdx = kmtPrefix;
					break;
				case MoMorphType.kguidMorphProclitic:
					mtIdx = kmtProclitic;
					break;
				case MoMorphType.kguidMorphRoot:
					mtIdx = kmtRoot;
					break;
				case MoMorphType.kguidMorphSimulfix:
					mtIdx = kmtSimulfix;
					break;
				case MoMorphType.kguidMorphStem:
					mtIdx = kmtStem;
					break;
				case MoMorphType.kguidMorphSuffix:
					mtIdx = kmtSuffix;
					break;
				case MoMorphType.kguidMorphSuprafix:
					mtIdx = kmtSuprafix;
					break;
				case MoMorphType.kguidMorphInfixingInterfix:
					mtIdx = kmtInfixingInterfix;
					break;
				case MoMorphType.kguidMorphPrefixingInterfix:
					mtIdx = kmtPrefixingInterfix;
					break;
				case MoMorphType.kguidMorphSuffixingInterfix:
					mtIdx = kmtSuffixingInterfix;
					break;
				case MoMorphType.kguidMorphPhrase:
					mtIdx = kmtPhrase;
					break;
				case MoMorphType.kguidMorphDiscontiguousPhrase:
					mtIdx = kmtDiscontiguousPhrase;
					break;
				default:
					throw new ArgumentException("Unrecognized morph type Guid.", "mmt");
			}
			return mtIdx;
		}
Exemplo n.º 44
0
		static private void SetCircumfixLexemeForm(FdoCache cache, ILexEntry entry, ITsString tssLexemeForm, IMoMorphType morphType)
		{
			int iHvo = cache.CreateObject(MoAffixAllomorph.kClassId, entry.Hvo, (int)LexEntry.LexEntryTags.kflidLexemeForm, 0);
			MoAffixAllomorph lexemeAllo = new MoAffixAllomorph(cache, iHvo);
			lexemeAllo.Form.SetAlternativeTss(tssLexemeForm);
			lexemeAllo.MorphTypeRA = morphType;
			lexemeAllo.IsAbstract = true;
		}
Exemplo n.º 45
0
		/// <summary>
		/// Makes a lex entry with lexeme form in 2 wss
		/// </summary>
		/// <param name="form1"></param>
		/// <param name="wsId1"> </param>
		/// <param name="form2"></param>
		/// <param name="wsId2"> </param>
		/// <param name="mt"></param>
		/// <returns></returns>
		private ILexEntry MakeStemEntryMultiWs(string form1, int wsId1, string form2, int wsId2, IMoMorphType mt)
		{
			var result = Cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create();
			var morph = Cache.ServiceLocator.GetInstance<IMoStemAllomorphFactory>().Create();
			result.LexemeFormOA = morph;
			morph.MorphTypeRA = mt;
			morph.Form.set_String(wsId1, Cache.TsStrFactory.MakeString(form1, wsId1));
			morph.Form.set_String(wsId2, Cache.TsStrFactory.MakeString(form2, wsId2));
			return result;
		}
Exemplo n.º 46
0
		/// ------------------------------------------------------------------------------------
		/// <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;
		}
Exemplo n.º 47
0
		/// <summary>
		/// Given that we have set the form of hvoMorph (in the sandbox cache) to the given
		/// form, figure defaults for the LexEntry, LexGloss, and LexPos lines as far as
		/// possible. It is assumed that all three following lines are empty to begin with.
		/// Also set matching text for any other WSs that are displayed for MoForm.
		/// (This is important because if the user confirms the analysis, we will write that
		/// information back to the MoForm. If we leave the lines blank that process could
		/// remove the other alternatives.)
		/// </summary>
		/// <param name="hvoMorph"></param>
		/// <param name="form"></param>
		internal void EstablishDefaultEntry(int hvoMorph, string form, IMoMorphType mmt, bool fMonoMorphemic)
		{
			CheckDisposed();
			int hvoFormSec = m_caches.DataAccess.get_ObjectProp(hvoMorph, ktagSbMorphForm);
			// remove any existing mapping for this morph form, which might exist
			// from a previous analysis
			m_caches.RemoveSec(hvoFormSec);
			var defFormReal = DefaultMorph(form, mmt);
			if (defFormReal == null)
				return; // this form never occurs anywhere, can't supply any default.
			var otherWritingSystemsForMorphForm = m_choices.OtherWritingSystemsForFlid(InterlinLineChoices.kflidMorphemes, RawWordformWs);
			if (otherWritingSystemsForMorphForm.Any())
			{
				var hvoSbForm = m_caches.DataAccess.get_ObjectProp(hvoMorph, ktagSbMorphForm);
				foreach (var ws in otherWritingSystemsForMorphForm)
				{
					try
					{
						m_caches.DataAccess.SetMultiStringAlt(hvoSbForm, ktagSbNamedObjName, ws,
							defFormReal.Form.get_String(ws));
					}
					catch (Exception e)
					{
						if (e is ArgumentException &&
							e.Message.StartsWith("Magic writing system invalid in string"))
						{
							// probably using TryAWord and the ws is WritingSystemServices.kwsFirstVern
							// is OK so continue (yes, this is a hack)
							continue;
						}
						throw;
					}
				}
			}
			var le = defFormReal.Owner as ILexEntry;
			int hvoEntry = m_caches.FindOrCreateSec(le.Hvo, kclsidSbNamedObj,
				kSbWord, ktagSbWordDummy);
			ITsString tssName;
			tssName = le.HeadWord;
			int wsVern = RawWordformWs;
			int hvoEntryToDisplay = le.Hvo;
			ILexEntryRef ler = DomainObjectServices.GetVariantRef(le, fMonoMorphemic);
			if (ler != null)
			{
				ICmObject coRef = ler.ComponentLexemesRS[0];
				if (coRef is ILexSense)
					hvoEntryToDisplay = (coRef as ILexSense).EntryID;
				else
					hvoEntryToDisplay = coRef.Hvo;
			}
			tssName = LexEntryVc.GetLexEntryTss(Cache, hvoEntryToDisplay, wsVern, ler);
			m_caches.DataAccess.SetMultiStringAlt(hvoEntry, ktagSbNamedObjName, this.RawWordformWs, tssName);
			m_caches.DataAccess.SetObjProp(hvoMorph, ktagSbMorphEntry, hvoEntry);
			m_caches.DataAccess.SetInt(hvoEntry, ktagSbNamedObjGuess, 1);
			m_caches.DataAccess.PropChanged(m_rootb, (int)PropChangeType.kpctNotifyAll,
				hvoMorph, ktagSbMorphGloss, 0, 1, 0);
			// Establish the link between the SbNamedObj that represents the MoForm, and the
			// selected MoForm.  (This is used when building the real WfiAnalysis.)
			m_caches.Map(hvoFormSec, defFormReal.Hvo);
			// This takes too long! Wait at least for a click in the bundle.
			//SetSelectedEntry(hvoEntryReal);
			EstablishDefaultSense(hvoMorph, le, null, null);
		}
Exemplo n.º 48
0
        public void ParserDataChanges()
        {
            XmlNode node;

#if !ShowDumpResult
            m_fxtResult.Save(Path.Combine(System.IO.Path.GetTempPath(), "TestFxtUpdateBefore.xml"));
#endif
            // -------------
            // Make data changes
            // -------------
            // Make a change to stem allomorph
            ILangProject lp           = Cache.LangProject;
            ILexDb       lexdb        = lp.LexDbOA;
            int[]        aiLexEntries = lexdb.EntriesOC.HvoArray;
            int          hvoLexEntry  = aiLexEntries[0];
            ILexEntry    lexEntry     = CmObject.CreateFromDBObject(Cache, hvoLexEntry) as ILexEntry;
            Assert.IsNotNull(lexEntry);
            IMoStemAllomorph stemAllomorph = lexEntry.LexemeFormOA as IMoStemAllomorph;
            Assert.IsNotNull(stemAllomorph);
            stemAllomorph.Form.SetAlternative("bili-changed", Cache.DefaultVernWs);
            int hvoStemAllomorph = stemAllomorph.Hvo;
            stemAllomorph.IsAbstract = true;

            // Delete an affix allomorph
            hvoLexEntry = aiLexEntries[3];
            lexEntry    = CmObject.CreateFromDBObject(Cache, hvoLexEntry) as ILexEntry;
            Assert.IsNotNull(lexEntry);
            IMoAffixAllomorph affixAllomorph = lexEntry.AlternateFormsOS[1] as IMoAffixAllomorph;
            Assert.IsNotNull(affixAllomorph);
            int hvoAffixAllomorph = affixAllomorph.Hvo;
            lexEntry.AlternateFormsOS.RemoveAt(1);
            Cache.PropChanged(null, PropChangeType.kpctNotifyAll, hvoLexEntry, (int)LexEntry.LexEntryTags.kflidAlternateForms, 1, 0, 1);

            // Add a new affix allomorph
            IMoAffixAllomorph newAffixAllomorph = new MoAffixAllomorph();
            lexEntry.AlternateFormsOS.Append(newAffixAllomorph);
            newAffixAllomorph.Form.SetAlternative("him-new", Cache.DefaultVernWs);
            int hvoNewAffixAllomorph = newAffixAllomorph.Hvo;
            Cache.PropChanged(null, PropChangeType.kpctNotifyAll, hvoLexEntry, (int)LexEntry.LexEntryTags.kflidAlternateForms, lexEntry.AlternateFormsOS.Count - 1, 1, 0);

            // add a compound rule
            IMoMorphData    morphData   = lp.MorphologicalDataOA;
            IMoEndoCompound compRuleNew = new MoEndoCompound();
            morphData.CompoundRulesOS.Append(compRuleNew);
            string sCompRuleName = "new compound rule";
            compRuleNew.Name.AnalysisDefaultWritingSystem = sCompRuleName;
            compRuleNew.HeadLast = true;
            int hvoPOS = lp.PartsOfSpeechOA.PossibilitiesOS.FirstItem.Hvo;
            compRuleNew.LeftMsaOA.PartOfSpeechRAHvo       = hvoPOS;
            compRuleNew.RightMsaOA.PartOfSpeechRAHvo      = hvoPOS;
            compRuleNew.OverridingMsaOA.PartOfSpeechRAHvo = hvoPOS;
            // Change compound rule description
            const string ksCompRuleDescription = "new description";
            compRuleNew.Description.AnalysisDefaultWritingSystem.Text = ksCompRuleDescription;
            Cache.PropChanged(null, PropChangeType.kpctNotifyAll, morphData.Hvo, (int)MoMorphData.MoMorphDataTags.kflidCompoundRules, morphData.CompoundRulesOS.Count - 1, 1, 0);

            // delete a compound rule
            IMoExoCompound compRuleDeleted            = morphData.CompoundRulesOS.FirstItem as IMoExoCompound;
            int            hvoCompRuleDeletedLeftMsa  = compRuleDeleted.LeftMsaOAHvo;
            int            hvoCompRuleDeletedRightMsa = compRuleDeleted.RightMsaOAHvo;
            int            hvoCompRuleDeletedToMsa    = compRuleDeleted.ToMsaOAHvo;
            morphData.CompoundRulesOS.RemoveAt(0);

            // add an ad hoc co-prohibition
            IMoAlloAdhocProhib alloAdHoc = new MoAlloAdhocProhib();
            morphData.AdhocCoProhibitionsOC.Add(alloAdHoc);
            alloAdHoc.Adjacency           = 2;
            alloAdHoc.FirstAllomorphRAHvo = hvoNewAffixAllomorph;
            alloAdHoc.RestOfAllosRS.Append(hvoNewAffixAllomorph);

            // change a "rest of allos" in extant ad hoc co-prohibition
            int[] hvosAdHocProhibs          = morphData.AdhocCoProhibitionsOC.HvoArray;
            IMoAlloAdhocProhib alloAdHocOld =
                CmObject.CreateFromDBObject(Cache, hvosAdHocProhibs[9]) as IMoAlloAdhocProhib;
            IMoAffixAllomorph alloAdHicOldFirstRestOfAllos = alloAdHocOld.RestOfAllosRS.FirstItem as IMoAffixAllomorph;
            IMoAffixAllomorph affixAllomorph2 = lexEntry.AlternateFormsOS[0] as IMoAffixAllomorph;
            alloAdHocOld.RestOfAllosRS.Append(affixAllomorph2);
            alloAdHocOld.RestOfAllosRS.RemoveAt(0);
            alloAdHocOld.Adjacency = 2;

            //Add a new productivity restriction
            ICmPossibilityList prodRestricts   = morphData.ProdRestrictOA;
            ICmPossibility     prodRestriction = new CmPossibility();
            prodRestricts.PossibilitiesOS.Append(prodRestriction);
            string sNewProdRestrictName = "new exception feature";
            prodRestriction.Name.AnalysisDefaultWritingSystem = sNewProdRestrictName;
            Cache.PropChanged(null, PropChangeType.kpctNotifyAll, prodRestricts.Hvo, (int)CmPossibilityList.CmPossibilityListTags.kflidPossibilities, prodRestricts.PossibilitiesOS.Count - 1, 1, 0);

            // Change a phonological enviroment string representation
            IPhPhonData    phonData       = lp.PhonologicalDataOA;
            IPhEnvironment env            = phonData.EnvironmentsOS.FirstItem;
            const string   ksEnvStringRep = "/ _ [C] [V] a e i o u";
            env.StringRepresentation.Text = ksEnvStringRep;

            // Add a new phonological enviroment string representation
            IPhEnvironment envNew = new PhEnvironment();
            phonData.EnvironmentsOS.Append(envNew);
            envNew.StringRepresentation.Text = "/ _ m";
            int hvoPhonData = phonData.Hvo;
            Cache.PropChanged(null, PropChangeType.kpctNotifyAll, hvoPhonData, (int)PhPhonData.PhPhonDataTags.kflidEnvironments, phonData.EnvironmentsOS.Count - 1, 1, 0);

            // Change parser parameters (to test Unicode string field type)
            string sParserParameters = morphData.ParserParameters.Trim();
            int    i = sParserParameters.IndexOf("</ParserParameters>");
            string sNewParserParameters = sParserParameters.Substring(0, i) + "<HermitCrab><stuff>1</stuff></HermitCrab>" + "</ParserParameters>";
            morphData.ParserParameters = sNewParserParameters;

            // Delete a lex entry
            int[]     hvosEntries                    = lexdb.EntriesOC.HvoArray;
            int       hvoEntryDeleted                = hvosEntries[hvosEntries.Length - 4];
            ILexEntry entryDeleted                   = CmObject.CreateFromDBObject(Cache, hvoEntryDeleted) as ILexEntry;
            int       hvoEntryDeletedLexemeForm      = entryDeleted.LexemeFormOAHvo;
            int[]     hvosEntryDeletedAlternateForms = entryDeleted.AlternateFormsOS.HvoArray;
            int[]     hvosEntryDeletedMSAs           = entryDeleted.MorphoSyntaxAnalysesOC.HvoArray;
            int[]     hvosEntryDeletedSenses         = entryDeleted.SensesOS.HvoArray;
            //entryDeleted.LexemeFormOA.DeleteUnderlyingObject();
            lexdb.EntriesOC.Remove(hvosEntries[hvosEntries.Length - 4]);
            //Cache.PropChanged(null, PropChangeType.kpctNotifyAll, morphData.Hvo, (int)MoMorphData.MoMorphDataTags.kflidParserParameters, 0, 0, 0);

            // Create a new lex entry
            ILexEntry entryNew = new LexEntry();
            lexdb.EntriesOC.Add(entryNew);

            IMoAffixAllomorph alloNew = new MoAffixAllomorph();
            entryNew.LexemeFormOA = alloNew;
            string sNewAlloForm = "dem";
            alloNew.Form.VernacularDefaultWritingSystem = sNewAlloForm;
            alloNew.MorphTypeRA = (IMoMorphType)lexdb.MorphTypesOA.LookupPossibilityByGuid(new Guid(MoMorphType.kguidMorphPrefix));

            IMoAffixAllomorph alloNew2 = new MoAffixAllomorph();
            entryNew.AlternateFormsOS.Append(alloNew2);
            string sNewAlloForm2 = "den";
            alloNew2.Form.VernacularDefaultWritingSystem = sNewAlloForm2;
            alloNew2.MorphTypeRA = (IMoMorphType)lexdb.MorphTypesOA.LookupPossibilityByGuid(new Guid(MoMorphType.kguidMorphPrefix));
            Cache.PropChanged(null, PropChangeType.kpctNotifyAll, entryNew.Hvo, (int)LexEntry.LexEntryTags.kflidAlternateForms, entryNew.AlternateFormsOS.Count - 1, 1, 0);

            ILexSense sense = new LexSense();
            entryNew.SensesOS.Append(sense);
            string sGloss = "MeToo";
            sense.Gloss.AnalysisDefaultWritingSystem = sGloss;

            IMoInflAffMsa inflAffixMsa = new MoInflAffMsa();
            entryNew.MorphoSyntaxAnalysesOC.Add(inflAffixMsa);
            sense.MorphoSyntaxAnalysisRA = inflAffixMsa;
            int[] hvosPOSes = lp.PartsOfSpeechOA.PossibilitiesOS.HvoArray;
            int   hvoVerb   = hvosPOSes[12];
            inflAffixMsa.PartOfSpeechRAHvo = hvoVerb;
            IPartOfSpeech pos     = CmObject.CreateFromDBObject(Cache, hvoVerb) as IPartOfSpeech;
            int           hvoSlot = pos.AffixSlotsOC.HvoArray[2];
            inflAffixMsa.SlotsRC.Add(hvoSlot);
            Cache.PropChanged(null, PropChangeType.kpctNotifyAll, entryNew.Hvo, (int)LexEntry.LexEntryTags.kflidSenses, entryNew.SensesOS.Count - 1, 1, 0);

            // Add an inflectional template
            int[]                hvoVerbSubCats = pos.SubPossibilitiesOS.HvoArray;
            int                  hvoIntransVerb = hvoVerbSubCats[2];
            IPartOfSpeech        posVI          = CmObject.CreateFromDBObject(Cache, hvoIntransVerb) as IPartOfSpeech;
            IMoInflAffixTemplate affixTemplate  = new MoInflAffixTemplate();
            posVI.AffixTemplatesOS.Append(affixTemplate);
            affixTemplate.Name.AnalysisDefaultWritingSystem = "derived verb";
            affixTemplate.Final = false;
            affixTemplate.SuffixSlotsRS.Append(hvoSlot);
            Cache.PropChanged(null, PropChangeType.kpctNotifyAll, posVI.Hvo, (int)PartOfSpeech.PartOfSpeechTags.kflidAffixTemplates, posVI.AffixTemplatesOS.Count - 1, 1, 0);

            // add a phonological feature
            IFsClosedFeature consFeat = new FsClosedFeature();
            Cache.LangProject.PhFeatureSystemOA.FeaturesOC.Add(consFeat);
            consFeat.Name.AnalysisDefaultWritingSystem         = "consonantal";
            consFeat.Abbreviation.AnalysisDefaultWritingSystem = "cons";
            IFsSymFeatVal consPlus = new FsSymFeatVal();
            consFeat.ValuesOC.Add(consPlus);
            consPlus.SimpleInit("+", "positive");
            IFsSymFeatVal consMinus = new FsSymFeatVal();
            consFeat.ValuesOC.Add(consMinus);
            consMinus.SimpleInit("-", "negative");
            IFsFeatStrucType fsType = null;
            if (Cache.LangProject.PhFeatureSystemOA.TypesOC.Count == 0)
            {
                fsType = new FsFeatStrucType();
                Cache.LangProject.PhFeatureSystemOA.TypesOC.Add(fsType);
                fsType.Abbreviation.AnalysisDefaultWritingSystem = "Phon";
            }
            else
            {
                foreach (IFsFeatStrucType type in Cache.LangProject.PhFeatureSystemOA.TypesOC)
                {
                    fsType = type;
                    break;
                }
            }
            fsType.FeaturesRS.Append(consFeat);

            // add a feature-based NC
            IPhNCFeatures featNC = new PhNCFeatures();
            Cache.LangProject.PhonologicalDataOA.NaturalClassesOS.Append(featNC);
            featNC.Name.AnalysisDefaultWritingSystem         = "Consonants (Features)";
            featNC.Abbreviation.AnalysisDefaultWritingSystem = "CF";
            IFsFeatStruc fs = new FsFeatStruc();
            featNC.FeaturesOA = fs;
            IFsClosedValue val = fs.FindOrCreateClosedValue(consFeat.Hvo);
            val.FeatureRA = consFeat;
            val.ValueRA   = consPlus;
            featNC.NotifyNew();

            // add phonological rule
            IPhRegularRule regRule = new PhRegularRule();
            Cache.LangProject.PhonologicalDataOA.PhonRulesOS.Append(regRule);
            regRule.NotifyNew();
            regRule.Name.AnalysisDefaultWritingSystem = "regular rule";
            IPhSimpleContextSeg segCtxt = new PhSimpleContextSeg();
            regRule.RightHandSidesOS[0].StrucChangeOS.Append(segCtxt);
            IPhPhoneme phoneme = null;
            foreach (IPhPhoneme phon in Cache.LangProject.PhonologicalDataOA.PhonemeSetsOS[0].PhonemesOC)
            {
                phoneme = phon;
                break;
            }
            segCtxt.FeatureStructureRA = phoneme;
            segCtxt.NotifyNew();

            IPhSimpleContextNC ncCtxt = new PhSimpleContextNC();
            regRule.RightHandSidesOS[0].LeftContextOA = ncCtxt;
            ncCtxt.FeatureStructureRA = featNC;
            ncCtxt.NotifyNew();

            // add a morphological rule
            IMoAffixProcess affRule = new MoAffixProcess();
            entryNew.AlternateFormsOS.Append(affRule);
            affRule.NotifyNew();
            ncCtxt = new PhSimpleContextNC();
            affRule.InputOS.Append(ncCtxt);
            ncCtxt.FeatureStructureRA = featNC;
            ncCtxt.NotifyNew();
            IMoCopyFromInput copy = new MoCopyFromInput();
            affRule.OutputOS.Append(copy);
            copy.ContentRA = ncCtxt;
            copy.NotifyNew();

            // -----------
            // Update the FXT result
            // -----------
            XmlDocument updatedFxtResult = UpdateFXT();

            // -----------
            // Test the updated results
            // -----------

            // Test changed stem allomorph: checks on MultiUnicode and boolean
            node = updatedFxtResult.SelectSingleNode("//MoStemAllomorph[@Id='" + hvoStemAllomorph + "']");
            Assert.IsNotNull(node);
            Assert.AreEqual(stemAllomorph.Form.VernacularDefaultWritingSystem, node.InnerText, "stem allomorph form change failed");
            XmlNode contentNode = node.SelectSingleNode("@IsAbstract");
            Assert.AreEqual("1", contentNode.InnerText, "stem allomorph is abstract should be true (=1)");

            // Test deleted affix allomorph: checks on owning sequence
            node = updatedFxtResult.SelectSingleNode("//MoAffixAllomorph[@Id='" + hvoAffixAllomorph + "']");
            Assert.IsNull(node, "Deleted affix allomorph should be null");
            node =
                updatedFxtResult.SelectSingleNode("//LexEntry[@id='" + hvoLexEntry + "']/AlternateForms[@dst='" +
                                                  hvoAffixAllomorph + "']");
            Assert.IsNull(node, "LexEntry should no longer have deleted alternate form");

            // Test added new affix allomorph: checks on owning sequence owned by an item with an @Id; also checks on addition of MoAffixAllomorph via AllAllomorphs
            string sXPath = "//LexEntry[@Id='" + hvoLexEntry + "']/AlternateForms[@dst='" +
                            hvoNewAffixAllomorph + "']";
            node = updatedFxtResult.SelectSingleNode(sXPath);
            Assert.IsNotNull(node, "LexEntry should have added alternate form");
            node = updatedFxtResult.SelectSingleNode("//MoAffixAllomorph[@Id='" + hvoNewAffixAllomorph + "']");
            Assert.IsNotNull(node, "Added affix allomorph should be present");
            sXPath = "//LexEntry[@Id='" + hvoLexEntry + "']";
            node   = updatedFxtResult.SelectSingleNode(sXPath);
            XmlNodeList nodes = node.SelectNodes("AlternateForms");
            Assert.AreEqual(3, nodes.Count, "Expected three Alternate forms in lex entry.");

            //Test newly added compound rule: checks on owning sequence owned by an Id-less element; also on multistring
            node = updatedFxtResult.SelectSingleNode("//MoEndoCompound[@Id='" + compRuleNew.Hvo + "']");
            Assert.IsNotNull(node, "did not find newly added compound rule");
            contentNode = node.SelectSingleNode("@HeadLast");
            Assert.IsNotNull(contentNode, "missing headlast attribute for coompound rule");
            Assert.AreEqual("1", contentNode.InnerText, "compound rule headlast value differs");
            contentNode = node.SelectSingleNode("Name");
            Assert.IsNotNull(contentNode, "missing Name for compound rule");
            Assert.AreEqual(sCompRuleName, contentNode.InnerText, "compound rule name differs");
            // check on MultiString
            contentNode = node.SelectSingleNode("Description");
            Assert.AreEqual(ksCompRuleDescription, contentNode.InnerText, "compound rule description differs");
            // check on count
            node  = updatedFxtResult.SelectSingleNode("//CompoundRules");
            nodes = node.SelectNodes("MoExoCompound | MoEndoCompound");
            Assert.AreEqual(6, nodes.Count, "Expected seven compound rules.");
            // check on owningAtom
            node = updatedFxtResult.SelectSingleNode("//MoStemMsa[@Id='" + compRuleNew.LeftMsaOAHvo + "']");
            Assert.IsNotNull(node, "missing real MoStemMsa for LeftMsa of newly added compound rule");
            node = updatedFxtResult.SelectSingleNode("//MoStemMsa[@Id='" + compRuleNew.RightMsaOAHvo + "']");
            Assert.IsNotNull(node, "missing real MoStemMsa for RightMsa of newly added compound rule");
            node = updatedFxtResult.SelectSingleNode("//MoStemMsa[@Id='" + compRuleNew.OverridingMsaOAHvo + "']");
            Assert.IsNotNull(node, "missing real MoStemMsa for OverridingMsa of newly added compound rule");

            // Test deleted compound rule
            node = updatedFxtResult.SelectSingleNode("//MoExoCompound[@Id='" + compRuleDeleted.Hvo + "']");
            Assert.IsNull(node, "compound rule should be deleted");
            node = updatedFxtResult.SelectSingleNode("//MoStemMsa[@Id='" + hvoCompRuleDeletedLeftMsa + "']");
            Assert.IsNull(node, "compound rule left MSA should be deleted");
            node = updatedFxtResult.SelectSingleNode("//MoStemMsa[@Id='" + hvoCompRuleDeletedRightMsa + "']");
            Assert.IsNull(node, "compound rule right MSA should be deleted");
            node = updatedFxtResult.SelectSingleNode("//MoStemMsa[@Id='" + hvoCompRuleDeletedToMsa + "']");
            Assert.IsNull(node, "compound rule to MSA should be deleted");

            //Test newly added allomorph ad hoc rule: checks on owning collection
            node = updatedFxtResult.SelectSingleNode("//MoAlloAdhocProhib[@Id='" + alloAdHoc.Hvo + "']");
            Assert.IsNotNull(node, "did not find newly added allo ad hoc rule");
            contentNode = node.SelectSingleNode("@Adjacency");
            Assert.IsNotNull(contentNode, "missing adjacency attribute for allo ad hoc rule");
            Assert.AreEqual("2", contentNode.InnerText, "allo ad hoc rule adjacency value differs");
            contentNode = node.SelectSingleNode("FirstAllomorph");
            Assert.IsNotNull(contentNode, "missing FirstAllomorph for allo ad hoc rule");
            contentNode = contentNode.SelectSingleNode("@dst");
            Assert.IsNotNull(contentNode, "missing dst attribute of FirstAllomorph for allo ad hoc rule");
            Assert.AreEqual(hvoNewAffixAllomorph.ToString(), contentNode.InnerText, "FirstAllomorph of allo ad hoc rule differs");
            contentNode = node.SelectSingleNode("RestOfAllos");
            Assert.IsNotNull(contentNode, "missing RestOfAllos for allo ad hoc rule");
            contentNode = contentNode.SelectSingleNode("@dst");
            Assert.IsNotNull(contentNode, "missing dst attribute of RestOfAllos for allo ad hoc rule");
            Assert.AreEqual(hvoNewAffixAllomorph.ToString(), contentNode.InnerText, "RestOfAllos of allo ad hoc rule differs");

            // test change of a "rest of allos" in extant ad hoc co-prohibition: check on reference sequence
            node = updatedFxtResult.SelectSingleNode("//MoAlloAdhocProhib[@Id='" + alloAdHocOld.Hvo + "']");
            Assert.IsNotNull(node, "did not find old allo ad hoc rule");
            contentNode = node.SelectSingleNode("RestOfAllos");
            Assert.IsNotNull(contentNode, "missing RestOfAllos for old allo ad hoc rule");
            contentNode = contentNode.SelectSingleNode("@dst");
            Assert.IsNotNull(contentNode, "missing dst attribute of RestOfAllos for old allo ad hoc rule");
            Assert.AreEqual(affixAllomorph2.Hvo.ToString(), contentNode.InnerText, "RestOfAllos of old allo ad hoc rule differs");
            nodes = node.SelectNodes("RestOfAllos");
            Assert.AreEqual(1, nodes.Count, "count of RestOfAllos of old allo ad hoc rule differs");
            // check on integer change
            contentNode = node.SelectSingleNode("@Adjacency");
            Assert.AreEqual("2", contentNode.InnerText, "Adjacency differs");
            node =
                updatedFxtResult.SelectSingleNode("//MoAffixAllomorph[@Id='" + alloAdHicOldFirstRestOfAllos.Hvo + "']");
            Assert.IsNotNull(node, "Original RestOfAllos allomorph should still be present");
            nodes = updatedFxtResult.SelectNodes("//MoAffixAllomorph[@Id='" + affixAllomorph2.Hvo + "']");
            Assert.AreEqual(1, nodes.Count, "Should only be one instance of new allomorph in RestOfAllos");


            // Test added productivity restriction: check on CmPossibilityList
            node = updatedFxtResult.SelectSingleNode("//ProdRestrict/CmPossibility");
            Assert.IsNotNull(node, "Did not find newly added productivity restriction");
            node = node.SelectSingleNode("Name");
            Assert.IsNotNull(node, "Expected Name node in productivity restrictioni");
            Assert.AreEqual(sNewProdRestrictName, node.InnerText, "name of productivity restriction differs");

            // Test phonological environment string representation: check on string
            node = updatedFxtResult.SelectSingleNode("//PhEnvironment[@Id='" + env.Hvo + "']/@StringRepresentation");
            Assert.AreEqual(ksEnvStringRep, node.InnerText, "phonological environment string differs");

            // Test adding a phonological environment string representation:
            // check on case where parent of owner has Id and is class name;
            // also check on case where there is a comment/text node within the result nodes
            node = updatedFxtResult.SelectSingleNode("//PhEnvironment[@Id='" + envNew.Hvo + "']");
            Assert.IsNotNull(node, "missing newly added phonological environment");
            nodes = updatedFxtResult.SelectNodes("//PhEnvironment");
            Assert.AreEqual(11, nodes.Count, "number of PhEnvironments differs");

            // Test Parser Parameters: check on unicode string
            node = updatedFxtResult.SelectSingleNode("//ParserParameters");
            string sResultParseParameters = node.OuterXml.Trim();
            Assert.AreEqual(sNewParserParameters, sResultParseParameters, "Parser Parameters content differs");

            // Test deletion of a lex entry: check on finding LexDb when there is no class LexDb in FXT file
            nodes = updatedFxtResult.SelectNodes("//LexEntry");
            Assert.AreEqual(61, nodes.Count, "number of LexEntries differs");
            node = updatedFxtResult.SelectSingleNode("//LexEntry[@Id='" + hvoEntryDeleted + "']");
            Assert.IsNull(node, "Deleted lex entry should be missing");
            foreach (int hvo in hvosEntryDeletedAlternateForms)
            {
                node = updatedFxtResult.SelectSingleNode("//MoStemAllomorph[@Id='" + hvo + "'] | //MoAffixAllomorph[@Id='" + hvo + "']");
                Assert.IsNull(node, "deleted entry's alternate form should also be gone");
            }
            foreach (int hvo in hvosEntryDeletedMSAs)
            {
                node = updatedFxtResult.SelectSingleNode("//MoStemMsa[@Id='" + hvo + "']");
                Assert.IsNull(node, "deleted entry's msa should also be gone");
            }
            foreach (int hvo in hvosEntryDeletedSenses)
            {
                node = updatedFxtResult.SelectSingleNode("//LexSense[@Id='" + hvo + "']");
                Assert.IsNull(node, "deleted entry's lexsense should also be gone");
            }
            node = updatedFxtResult.SelectSingleNode("//MoStemAllomorph[@Id='" + hvoEntryDeletedLexemeForm + "']");
            Assert.IsNull(node, "deleted entry's lexeme form should also be gone");

            // Test adding new entry
            node = updatedFxtResult.SelectSingleNode("//LexEntry[@Id='" + entryNew.Hvo + "']");
            Assert.IsNotNull(node, "new lex entry is missing");
            contentNode = node.SelectSingleNode("LexemeForm[@dst='" + alloNew.Hvo + "']");
            Assert.IsNotNull(contentNode, "missing lexeme form for new entry");
            contentNode = node.SelectSingleNode("AlternateForms[@dst='" + alloNew2.Hvo + "']");
            Assert.IsNotNull(contentNode, "missing alternate form in new lex entry");
            contentNode = node.SelectSingleNode("Sense[@dst='" + sense.Hvo + "']");
            Assert.IsNotNull(contentNode, "missing sense in new lex entry");
            contentNode = node.SelectSingleNode("MorphoSyntaxAnalysis[@dst='" + inflAffixMsa.Hvo + "']");
            Assert.IsNotNull(contentNode, "missing msa in new lex entry");
            contentNode = node.SelectSingleNode("AlternateForms[@dst='" + affRule.Hvo + "']");
            Assert.IsNotNull(contentNode, "missing affix process rule in new lex entry");

            node = updatedFxtResult.SelectSingleNode("//MoAffixAllomorph[@Id='" + alloNew.Hvo + "']");
            Assert.IsNotNull(node, "new lexeme form affix allomorph for new lex entry is missing");
            contentNode = node.SelectSingleNode("@MorphType");
            Assert.IsNotNull(contentNode, "@MorphType missing for new MoAffixAllomorph in lexeme form of new lex entry");
            IMoMorphType typeNew  = MoMorphType.CreateFromDBObject(Cache, Convert.ToInt32(contentNode.InnerText));
            string       sGuidNew = typeNew.Guid.ToString();
            Assert.AreEqual(MoMorphType.kguidMorphPrefix, sGuidNew, "morph type wrong for new MoAffixAllomorph in lexeme form of new lex entry");
            contentNode = node.SelectSingleNode("Form");
            Assert.IsNotNull(contentNode, "Form missing for new MoAffixAllomorph in lexeme form new lex entry");
            Assert.AreEqual(sNewAlloForm, contentNode.InnerText, "form wrong for new MoAffixAllomorph in lexeme form of new lex entry");

            node = updatedFxtResult.SelectSingleNode("//MoAffixAllomorph[@Id='" + alloNew2.Hvo + "']");
            Assert.IsNotNull(node, "new alternate form affix allomorph for new lex entry is missing");
            contentNode = node.SelectSingleNode("@MorphType");
            Assert.IsNotNull(contentNode, "@MorphType missing for new MoAffixAllomorph in alternate form of new lex entry");
            typeNew  = MoMorphType.CreateFromDBObject(Cache, Convert.ToInt32(contentNode.InnerText));
            sGuidNew = typeNew.Guid.ToString();
            Assert.AreEqual(MoMorphType.kguidMorphPrefix, sGuidNew, "morph type wrong for new MoAffixAllomorph in lexeme form of new lex entry");
            contentNode = node.SelectSingleNode("Form");
            Assert.IsNotNull(contentNode, "Form missing for new MoAffixAllomorph in alternate form new lex entry");
            Assert.AreEqual(sNewAlloForm2, contentNode.InnerText, "form wrong for new MoAffixAllomorph in alternate form of new lex entry");

            node = updatedFxtResult.SelectSingleNode("//LexSense[@Id='" + sense.Hvo + "']");
            Assert.IsNotNull(node, "new sense for new lex entry is missing");
            contentNode = node.SelectSingleNode("Gloss");
            Assert.IsNotNull(contentNode, "Gloss missing for new LexSense in new lex entry");
            Assert.AreEqual(sGloss, contentNode.InnerText, "Gloss wrong for new LexSense in new lex entry");

            node = updatedFxtResult.SelectSingleNode("//MoInflAffMsa[@Id='" + inflAffixMsa.Hvo + "']");
            Assert.IsNotNull(node, "new infl affix msa for new lex entry is missing");
            contentNode = node.SelectSingleNode("@PartOfSpeech");
            Assert.IsNotNull(contentNode, "@PartOfSpeech missing for new MoInflAffMsa in new lex entry");
            Assert.AreEqual(hvoVerb.ToString(), contentNode.InnerText, "part of speech wrong for new MoInflAffMsa in new lex entry");
            contentNode = node.SelectSingleNode("Slots/@dst");
            Assert.IsNotNull(contentNode, "Slots missing for new MoInflAffMsa in new lex entry");
            Assert.AreEqual(hvoSlot.ToString(), contentNode.InnerText, "slot wrong for new MoInflAffMsa in new lex entry");

            // Test adding new template
            node = updatedFxtResult.SelectSingleNode("//MoInflAffixTemplate[@Id='" + affixTemplate.Hvo + "']");
            Assert.IsNotNull(node, "new affix template missing");
            node =
                updatedFxtResult.SelectSingleNode("//PartOfSpeech[@Id='" + hvoIntransVerb +
                                                  "']/AffixTemplates/MoInflAffixTemplate[@Id='" + affixTemplate.Hvo +
                                                  "']");
            Assert.IsNotNull(node, "new affix template is in intransitive verb");

            // Test adding new phonological feature
            node = updatedFxtResult.SelectSingleNode("//PhFeatureSystem/Features/FsClosedFeature[@Id='" + consFeat.Hvo + "']");
            Assert.IsNotNull(node, "new phonological feature is missing");
            contentNode = node.SelectSingleNode("Abbreviation");
            Assert.IsNotNull(contentNode, "Abbreviation missing from new phonological feature");
            Assert.AreEqual(contentNode.InnerText, consFeat.Abbreviation.AnalysisDefaultWritingSystem, "Abbreviation wrong for new phonological feature");
            nodes = node.SelectNodes("Values/FsSymFeatVal");
            Assert.IsNotNull(nodes, "values missing from new phonological feature");
            Assert.AreEqual(nodes.Count, 2, "incorrect number of values in new phonological feature");
            node = updatedFxtResult.SelectSingleNode("//PhFeatureSystem/Types/FsFeatStrucType/Features/Feature[@dst='" + consFeat.Hvo + "']");
            Assert.IsNotNull(node, "reference to new phonological feature is missing from phonological feature system");

            // Test adding new feature-based NC
            node = updatedFxtResult.SelectSingleNode("//PhNCFeatures[@Id='" + featNC.Hvo + "']");
            Assert.IsNotNull(node, "new feature-based NC is missing");
            contentNode = node.SelectSingleNode("Abbreviation");
            Assert.IsNotNull(contentNode, "Abbreviation missing from new feature-based NC");
            Assert.AreEqual(contentNode.InnerText, featNC.Abbreviation.AnalysisDefaultWritingSystem, "Abbreviation wrong for new feature-based NC");
            contentNode = node.SelectSingleNode("FsFeatStruc/FsClosedValue[@Id='" + val.Hvo + "']");
            Assert.IsNotNull(contentNode, "value missing from new feature-based NC");
            Assert.AreEqual((contentNode as XmlElement).GetAttribute("Feature"), consFeat.Hvo.ToString(), "closed value feature is wrong in new feature-based NC");
            Assert.AreEqual((contentNode as XmlElement).GetAttribute("Value"), consPlus.Hvo.ToString(), "closed value is wrong in new feature-based NC");

            // Test adding new phonological rule
            node = updatedFxtResult.SelectSingleNode("//PhRegularRule[@Id='" + regRule.Hvo + "']");
            Assert.IsNotNull(node, "new phonological rule is missing");
            nodes = node.SelectNodes("StrucDesc/*");
            Assert.AreEqual(nodes.Count, 0);
            contentNode = node.SelectSingleNode("RightHandSides/PhSegRuleRHS/StrucChange/PhSimpleContextSeg[@dst='" + phoneme.Hvo + "']");
            Assert.IsNotNull(contentNode, "phoneme simple context missing in new phonological rule");
            contentNode = node.SelectSingleNode("RightHandSides/PhSegRuleRHS/LeftContext/PhSimpleContextNC[@dst='" + featNC.Hvo + "']");
            Assert.IsNotNull(contentNode, "NC simple context missing in new phonological rule");

            // Test adding new morphological rule
            node = updatedFxtResult.SelectSingleNode("//Lexicon/Allomorphs/MoAffixProcess[@Id='" + affRule.Hvo + "']");
            Assert.IsNotNull(node, "new morphological rule is missing");
            contentNode = node.SelectSingleNode("Input/PhSimpleContextNC[@dst='" + featNC.Hvo + "']");
            Assert.IsNotNull(contentNode, "NC simple context missing in new morphological rule");
            contentNode = node.SelectSingleNode("Output/MoCopyFromInput/Content[@dst='" + ncCtxt.Hvo + "']");
            Assert.IsNotNull(contentNode, "copy from input missing in new morphological rule");

            // Modify a phonological rule
            segCtxt = new PhSimpleContextSeg();
            regRule.StrucDescOS.Append(segCtxt);
            segCtxt.FeatureStructureRA = phoneme;
            segCtxt.NotifyNew();
            regRule.RightHandSidesOS[0].StrucChangeOS[0].DeleteUnderlyingObject();
            IPhPhonContext oldCtxt = regRule.RightHandSidesOS[0].LeftContextOA;
            Cache.LangProject.PhonologicalDataOA.ContextsOS.Append(oldCtxt);
            IPhSequenceContext seqCtxt = new PhSequenceContext();
            regRule.RightHandSidesOS[0].LeftContextOA = seqCtxt;
            seqCtxt.MembersRS.Append(oldCtxt);
            seqCtxt.NotifyNew();
            IPhSimpleContextBdry bdryCtxt = new PhSimpleContextBdry();
            Cache.LangProject.PhonologicalDataOA.ContextsOS.Append(bdryCtxt);
            bdryCtxt.FeatureStructureRAHvo = Cache.GetIdFromGuid(LangProject.kguidPhRuleWordBdry);
            bdryCtxt.NotifyNew();
            seqCtxt.MembersRS.Append(bdryCtxt);

            // Modify a morphological rule
            entryNew.LexemeFormOA = affRule;
            IMoInsertPhones insertPhones = new MoInsertPhones();
            affRule.OutputOS.InsertAt(insertPhones, 0);
            insertPhones.ContentRS.Append(phoneme);
            insertPhones.NotifyNew();
            affRule.InputOS[1].DeleteUnderlyingObject();

            // change order of a sequence vector
            lexEntry.AlternateFormsOS.InsertAt(newAffixAllomorph, 0);

            updatedFxtResult = UpdateFXT();

            // Test modifying a phonological rule
            node        = updatedFxtResult.SelectSingleNode("//PhRegularRule[@Id='" + regRule.Hvo + "']");
            contentNode = node.SelectSingleNode("StrucDesc/PhSimpleContextSeg[@dst='" + phoneme.Hvo + "']");
            Assert.IsNotNull(contentNode, "phoneme simple context missing from StrucDesc in modified phonological rule");
            contentNode = node.SelectSingleNode("RightHandSides/PhSegRuleRHS/StrucChange/PhSimpleContextSeg[@dst='" + phoneme.Hvo + "']");
            Assert.IsNull(contentNode, "phoneme simple context is not missing from StrucChange in modified phonological rule");
            contentNode = node.SelectSingleNode("RightHandSides/PhSegRuleRHS/LeftContext/PhSequenceContext[@Id='" + seqCtxt.Hvo + "']");
            Assert.IsNotNull(contentNode, "sequence context missing from modified phonological rule");
            contentNode = contentNode.SelectSingleNode("Members[@dst='" + bdryCtxt.Hvo + "']");
            Assert.IsNotNull(contentNode, "boundary context missing from sequence context in modified phonological rule");
            node = updatedFxtResult.SelectSingleNode("//PhPhonData/Contexts/PhSimpleContextBdry[@Id='" + bdryCtxt.Hvo + "']");
            Assert.IsNotNull(node, "boundary context missing from contexts in phonological data");

            // Test modifying a morphological rule
            node        = updatedFxtResult.SelectSingleNode("//LexEntry[@Id='" + entryNew.Hvo + "']");
            contentNode = node.SelectSingleNode("LexemeForm[@dst='" + affRule.Hvo + "']");
            Assert.IsNotNull(contentNode, "affix process rule is not the lexeme form for the lex entry");
            node        = updatedFxtResult.SelectSingleNode("//Lexicon/Allomorphs/MoAffixProcess[@Id='" + affRule.Hvo + "']");
            contentNode = node.SelectSingleNode("Input/PhSimpleContextNC[@dst='" + featNC.Hvo + "']");
            Assert.IsNull(contentNode, "NC simple context was not removed from morphological rule");
            nodes = node.SelectNodes("Output/*");
            Assert.AreEqual(nodes.Count, 2, "incorrect number of mappings in morphological rule");
            contentNode = node.SelectSingleNode("Output/*[position() = 1 and @Id='" + insertPhones.Hvo + "']");
            Assert.IsNotNull(contentNode, "insert phones missing from morphological rule");

            // Test changing order of a sequence vector
            node        = updatedFxtResult.SelectSingleNode("//LexEntry[@Id='" + lexEntry.Hvo + "']");
            contentNode = node.SelectSingleNode("AlternateForms[@dst='" + lexEntry.AlternateFormsOS[0].Hvo + "']/@ord");
            Assert.AreEqual("0", contentNode.InnerText);
            contentNode = node.SelectSingleNode("AlternateForms[@dst='" + lexEntry.AlternateFormsOS[1].Hvo + "']/@ord");
            Assert.AreEqual("1", contentNode.InnerText);
            contentNode = node.SelectSingleNode("AlternateForms[@dst='" + lexEntry.AlternateFormsOS[2].Hvo + "']/@ord");
            Assert.AreEqual("2", contentNode.InnerText);
        }
Exemplo n.º 49
0
			private void GetMorphInfo(out ITsString tssForm, out ITsString tssFullForm, out IMoMorphType morphType)
			{
				IMoForm morphReal;
				GetMorphInfo(out tssForm, out tssFullForm, out morphReal, out morphType);
			}
Exemplo n.º 50
0
		/// <summary>
		/// Set the class and morph type.
		/// </summary>
		/// <param name="mmt">The morph type.</param>
		private void SetMorphType(IMoMorphType mmt)
		{
			if (!m_cbMorphType.Items.Contains(mmt))
				return;

			m_morphType = mmt;
			m_msaGroupBox.MorphTypePreference = mmt;
			using (m_updateTextMonitor.Enter())
				m_cbMorphType.SelectedItem = mmt;
			EnableComplexFormTypeCombo();
		}
Exemplo n.º 51
0
			private void GetMorphInfo(out ITsString tssForm, out ITsString tssFullForm, out IMoForm morphReal, out IMoMorphType morphType)
			{
				morphReal = null;
				int hvoMorph = m_caches.DataAccess.get_ObjectProp(m_hvoMorph, ktagSbMorphForm);
				var hvoMorphReal = m_caches.RealHvo(hvoMorph);
				if (hvoMorphReal != 0)
					morphReal = m_caches.MainCache.ServiceLocator.GetInstance<IMoFormRepository>().GetObject(hvoMorphReal);
				ISilDataAccess sda = m_caches.DataAccess;
				tssForm = m_caches.DataAccess.get_MultiStringAlt(hvoMorph, ktagSbNamedObjName, m_sandbox.RawWordformWs);
				tssFullForm = m_sandbox.GetFullMorphForm(m_hvoMorph);
				string fullForm = tssFullForm.Text;
				morphType = null;
				if (morphReal != null)
				{
					morphType = morphReal.MorphTypeRA;
				}
				else
				{
					// if we don't have a form then we can't derive a type. (cf. LT-1621)
					if (string.IsNullOrEmpty(fullForm))
					{
						morphType = null;
					}
					else
					{
						// Find the type for this morpheme
						int clsidForm;
						string fullFormTmp = fullForm;
						morphType = MorphServices.FindMorphType(m_caches.MainCache, ref fullFormTmp, out clsidForm);
					}
				}
			}
Exemplo n.º 52
0
		private void SwapValues(ILexEntry entry, IMoForm origForm, IMoForm newForm, IMoMorphType type,
			List<IMoMorphSynAnalysis> rgmsaOld)
		{
			DataTree dtree = Slice.ContainingDataTree;
			int idx = Slice.IndexInContainer;
			dtree.DoNotRefresh = true;	// don't let the datatree repeatedly redraw itself...
			entry.ReplaceMoForm(origForm, newForm);
			newForm.MorphTypeRA = type;
			entry.ReplaceObsoleteMsas(rgmsaOld);
			// Dispose of any obsolete slices: new ones will replace them automatically in a moment
			// when the datatree is redrawn.
			foreach (Slice slice in Slice.ContainingDataTree.Slices.ToArray())
			{
				if (slice.IsDisposed)
					continue;
				if (slice.Object is IMoMorphSynAnalysis && rgmsaOld.Contains(slice.Object as IMoMorphSynAnalysis))
					slice.Dispose();
				else if (slice is MSAReferenceComboBoxSlice)
					slice.Dispose();
			}
			// now fix the record list, since it may be showing MoForm dependent columns (e.g. MorphType, Homograph, etc...)
			dtree.FixRecordList();
			dtree.DoNotRefresh = false;
			Slice sliceT = dtree.Slices[idx];
			if (sliceT != null && sliceT is MorphTypeAtomicReferenceSlice)
			{
				// When the new slice is created, the launch button is placed in the middle of
				// the slice rather than at the end.  This fiddling with the slice width seems
				// to fix that.  Then setting the index restores focus to the new slice.
				sliceT.Width += 1;
				sliceT.Width -= 1;
				dtree.GotoNextSliceAfterIndex(idx - 1);
			}
		}
Exemplo n.º 53
0
		// This one is different because for stems, spaces must always be included on both sides where needed
		private void morphBreakInsertStem(IMoMorphType morphType)
		{
			GroupText(prefixSpace() + morphType.Prefix, morphType.Postfix + postfixSpace(), true);
		}
Exemplo n.º 54
0
		/// <summary>
		/// Change the affix to a stem (possibly)
		/// </summary>
		/// <param name="entry"></param>
		/// <param name="type"></param>
		/// <returns>true if change made; false otherwise</returns>
		private bool ChangeAffixToStem(ILexEntry entry, IMoMorphType type)
		{
			var affix = m_obj as IMoAffixForm;
			if (affix == null)
				throw new ApplicationException("Affix form is not defined");
			var rgmsaOld = new List<IMoMorphSynAnalysis>();
			if (m_obj.OwningFlid == LexEntryTags.kflidLexemeForm)
			{
				foreach (var msa in entry.MorphoSyntaxAnalysesOC)
				{
					if (!(msa is IMoStemMsa))
						rgmsaOld.Add(msa);
				}
			}
			if (CheckForAffixDataLoss(affix, rgmsaOld))
				return false;
			FdoCache cache = m_cache;
			var stem = m_cache.ServiceLocator.GetInstance<IMoStemAllomorphFactory>().Create();
			SwapValues(entry, affix, stem, type, rgmsaOld);	// may cause slice/button to be disposed...
			return true;
		}
Exemplo n.º 55
0
		// Determines what to insert based on the presence of prefix and postfix tokens
		private void morphBreakInsert(IMoMorphType morphType)
		{
			if (!String.IsNullOrEmpty(morphType.Prefix) && !String.IsNullOrEmpty(morphType.Postfix))
				GroupText(prefixSpace() + morphType.Prefix, morphType.Postfix + postfixSpace(), true);
			else if (!String.IsNullOrEmpty(morphType.Prefix))
				InsertText(prefixSpace() + morphType.Prefix, false);
			else if (!String.IsNullOrEmpty(morphType.Postfix))
				InsertText(morphType.Postfix + postfixSpace(), false, true);
		}
Exemplo n.º 56
0
        /// <summary>
        /// Get the morph type and class ID for the given input string. Trims fullForm if needed.
        /// </summary>
        /// <param name="cache">The cache to look in.</param>
        /// <param name="fullForm">The MoForm form, plus optional key characters before and/or after the form.</param>
        /// <param name="clsidForm">Return the clsid for the form.</param>
        /// <returns>The MoMorphType indicated by the possible markers.</returns>
        /// <exception cref="ArgumentException">
        /// Thrown in the following cases:
        /// 1. The input form is an empty string,
        /// 2. The imput form is improperly marked according to the current settings of the
        ///		MoMorphType objects.
        /// </exception>
        public static IMoMorphType FindMorphType(LcmCache cache, ref string fullForm, out int clsidForm)
        {
            Debug.Assert(cache != null);
            Debug.Assert(fullForm != null);

            clsidForm = MoStemAllomorphTags.kClassId;                   // default
            IMoMorphType mt = null;

            fullForm = fullForm.Trim();
            if (fullForm.Length == 0)
            {
                throw new ArgumentException("The form is empty.", "fullForm");
            }

            string sLeading;
            string sTrailing;

            GetAffixMarkers(cache, fullForm, out sLeading, out sTrailing);

            /*
             * Not dealt with.
             * particle	(ambiguous: particle, circumfix, root, stem, clitic)
             * circumfix	(ambiguous: particle, circumfix, root, stem, clitic)
             * root		(ambiguous: particle, circumfix, root, stem, clitic)
             * clitic		(ambiguous: particle, circumfix, root, stem, clitic)
             * bound root	(ambiguous: bound root, bound stem)
             * infixing interfix		(ambiguous: infixing interfix, infix)
             * prefixing interfix		(ambiguous: prefixing interfix, prefix)
             * suffixing interfix		(ambiguous: suffixing interfix, suffix)
             * discontiguous phrase	(ambiguous: discontiguous phrase, phrase)
             * End of not dealt with.
             *
             * What we do deal with.
             * prefix-	(ambiguous: prefixing interfix, prefix)
             * =simulfix=
             * -suffix	(ambiguous: suffixing interfix, suffix)
             * -infix-	(ambiguous: infixing interfix, infix)
             * ~suprafix~
             * =enclitic
             * proclitic=
             * bound stem	(ambiguous: bound root, bound stem)
             * stem		(ambiguous: particle, circumfix, root, stem, clitic)
             * phrase		(ambiguous: discontiguous phrase, phrase)
             * End of what we do deal with.
             *
             * For ambiguous cases, pick 'root' and 'bound root', as per LarryH's suggestion on 11/18/2003.
             * (Changed: May, 2004). For ambiguous cases, pick 'stem' and 'bound stem',
             * as per WordWorks May, 2004 meeting (Andy Black & John Hatton).
             * For ambiguous cases, pick 'infix', 'prefix', and 'suffix'.
             */
            foreach (IMoMorphType mmt in cache.LanguageProject.LexDbOA.MorphTypesOA.PossibilitiesOS)
            {
                if (sLeading == mmt.Prefix && sTrailing == mmt.Postfix)
                {
                    // handle ambiguous cases
                    var morphTypeRep = cache.ServiceLocator.GetInstance <IMoMorphTypeRepository>();
                    switch (mmt.Guid.ToString())
                    {
                    case MoMorphTypeTags.kMorphPrefixingInterfix:
                        mt = morphTypeRep.GetObject(MoMorphTypeTags.kguidMorphPrefix);
                        break;

                    case MoMorphTypeTags.kMorphSuffixingInterfix:
                        mt = morphTypeRep.GetObject(MoMorphTypeTags.kguidMorphSuffix);
                        break;

                    case MoMorphTypeTags.kMorphInfixingInterfix:
                        mt = morphTypeRep.GetObject(MoMorphTypeTags.kguidMorphInfix);
                        break;

                    case MoMorphTypeTags.kMorphBoundRoot:
                        mt = morphTypeRep.GetObject(MoMorphTypeTags.kguidMorphBoundStem);
                        break;

                    case MoMorphTypeTags.kMorphParticle:
                    case MoMorphTypeTags.kMorphCircumfix:
                    case MoMorphTypeTags.kMorphRoot:
                    case MoMorphTypeTags.kMorphDiscontiguousPhrase:
                    case MoMorphTypeTags.kMorphPhrase:
                    case MoMorphTypeTags.kMorphClitic:
                        mt = morphTypeRep.GetObject(MoMorphTypeTags.kguidMorphStem);
                        break;

                    default:
                        mt = mmt;
                        break;
                    }

                    // handle phrase
                    if (mt.Guid == MoMorphTypeTags.kguidMorphStem && fullForm.IndexOf(" ") != -1)
                    {
                        mt = morphTypeRep.GetObject(MoMorphTypeTags.kguidMorphPhrase);
                    }

                    if (mt.IsAffixType)
                    {
                        clsidForm = MoAffixAllomorphTags.kClassId;
                    }
                    break;
                }
            }

            if (mt == null)
            {
                if (sLeading == null && sTrailing == null)
                {
                    throw new InvalidOperationException(String.Format(Strings.ksInvalidUnmarkedForm0, fullForm));
                }
                if (sLeading == null)
                {
                    throw new InvalidOperationException(String.Format(Strings.ksInvalidForm0Trailing1, fullForm, sTrailing));
                }
                if (sTrailing == null)
                {
                    throw new InvalidOperationException(String.Format(Strings.ksInvalidForm0Leading1, fullForm, sLeading));
                }
                throw new InvalidOperationException(String.Format(Strings.ksInvalidForm0Leading1Trailing2, fullForm, sLeading, sTrailing));
            }

            if (sLeading != null)
            {
                fullForm = fullForm.Substring(sLeading.Length);
            }
            if (sTrailing != null)
            {
                fullForm = fullForm.Substring(0, fullForm.Length - sTrailing.Length);
            }

            return(mt);
        }
Exemplo n.º 57
0
		ILexEntry MakeAffixEntry(string form, IMoMorphType mt)
		{
			var result = Cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create();
			var morph = Cache.ServiceLocator.GetInstance<IMoAffixAllomorphFactory>().Create();
			result.LexemeFormOA = morph;
			var vernWs = Cache.DefaultVernWs;
			morph.Form.set_String(vernWs, Cache.TsStrFactory.MakeString(form, vernWs));
			morph.MorphTypeRA = mt;
			return result;
		}
Exemplo n.º 58
0
        private void MakeMorphTypeChange(IMoMorphType selected)
        {
            var entry    = (ILexEntry)m_obj.Owner;
            var original = Target as IMoMorphType;
            var sUndo    = StringTable.Table.GetStringWithXPath("ChangeLexemeMorphTypeUndo", m_ksPath);
            var sRedo    = StringTable.Table.GetStringWithXPath("ChangeLexemeMorphTypeRedo", m_ksPath);

            var fRemoveComponents = false;

            if (selected.Guid == MoMorphTypeTags.kguidMorphRoot ||
                selected.Guid == MoMorphTypeTags.kguidMorphBoundRoot)
            {
                // changing to root...not allowed to have complex forms.
                foreach (ILexEntryRef ler in entry.EntryRefsOS)
                {
                    if (ler.RefType == LexEntryRefTags.krtComplexForm)
                    {
                        fRemoveComponents = true;
                        // If there are no components we will delete without asking...but must then check for more
                        // complex forms that DO have components.
                        if (ler.ComponentLexemesRS.Count > 0)
                        {
                            // TODO-Linux: Help is not implemented in Mono
                            if (MessageBox.Show(FindForm(), DetailControlsStrings.ksRootNoComponentsMessage,
                                                DetailControlsStrings.ksRootNoComponentsCaption, MessageBoxButtons.YesNo,
                                                MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0,
                                                m_propertyTable.GetValue <IHelpTopicProvider>("HelpTopicProvider").HelpFile,
                                                HelpNavigator.Topic,
                                                "/Using_Tools/Lexicon_tools/Lexicon_Edit/change_the_morph_type.htm") != DialogResult.Yes)
                            {
                                return;
                            }

                            break;
                        }
                    }
                }
            }

            UndoableUnitOfWorkHelper.Do(sUndo, sRedo, entry, () =>
            {
                if (fRemoveComponents)
                {
                    foreach (var ler in entry.EntryRefsOS.Where(entryRef =>
                                                                entryRef.RefType == LexEntryRefTags.krtComplexForm))
                    {
                        entry.EntryRefsOS.Remove(ler);
                    }
                }

                if (IsStemType(original) || m_obj is IMoStemAllomorph)
                {
                    if (IsStemType(selected))
                    {
                        Target = selected;
                    }
                    else
                    {
                        //have to switch from stem to affix
                        ChangeStemToAffix(entry, selected);
                    }
                }
                else
                {
                    // original is affix variety
                    if (IsStemType(selected))
                    {
                        //have to switch from affix to stem
                        ChangeAffixToStem(entry, selected);
                    }
                    else
                    {
                        Target = selected;
                    }
                }

                if (selected.Guid == MoMorphTypeTags.kguidMorphPhrase)
                {
                    ILexEntryRef ler = m_cache.ServiceLocator.GetInstance <ILexEntryRefFactory>().Create();
                    entry.EntryRefsOS.Add(ler);
                    ler.RefType        = LexEntryRefTags.krtComplexForm;
                    ler.HideMinorEntry = 1;
                }
            });
        }
Exemplo n.º 59
0
		/// <summary>
		/// Find the MoForm, from among those whose form (in some ws) is the given one
		/// starting from the most frequently referenced by the MorphBundles property of a WfiAnalysis.
		/// If there is no wordform analysis, then fall back to selecting any matching MoForm.
		/// </summary>
		/// <param name="form"></param>
		/// <returns></returns>
		internal IMoForm DefaultMorph(string form, IMoMorphType mmt)
		{
			CheckDisposed();
			// Find all the matching morphs and count how often used in WfiAnalyses
			int ws = RawWordformWs;
			// Fix FWR-2098 GJM: The definition of 'IsAmbiguousWith' seems not to include 'IsSameAs'.
			var morphs = (from mf in Cache.ServiceLocator.GetInstance<IMoFormRepository>().AllInstances()
						  where mf.Form.get_String(ws).Text == form && mf.MorphTypeRA != null
							&& (mf.MorphTypeRA == mmt || mf.MorphTypeRA.IsAmbiguousWith(mmt))
						  select mf).ToList();
			if (morphs.Count == 1)
				return morphs.First(); // special case: we can avoid the cost of figuring ReferringObjects.
			IMoForm bestMorph = null;
			var bestMorphCount = -1;
			foreach (var mf in morphs)
			{
				int count = (from source in mf.ReferringObjects where source is IWfiMorphBundle select source).Count();
				if (count > bestMorphCount)
				{
					bestMorphCount = count;
					bestMorph = mf;
				}
			}
			return bestMorph;
		}