/// <summary>
        /// Given a (potentially) owning object, and the flid in which is does/will own
        /// the feature structure, find the relevant POS.
        /// </summary>
        /// <param name="cobj"></param>
        /// <param name="owningFlid"></param>
        /// <returns></returns>
        private IPartOfSpeech GetPosFromCmObjectAndFlid(ICmObject cobj, int owningFlid)
        {
            IPartOfSpeech pos = null;

            switch (cobj.ClassID)
            {
            case MoInflAffMsa.kclsidMoInflAffMsa:
                IMoInflAffMsa infl = cobj as IMoInflAffMsa;
                if (infl != null)
                {
                    pos = infl.PartOfSpeechRA;
                }
                break;

            case MoDerivAffMsa.kclsidMoDerivAffMsa:
                IMoDerivAffMsa deriv = cobj as IMoDerivAffMsa;
                if (deriv != null)
                {
                    if (owningFlid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromMsFeatures)
                    {
                        pos = deriv.FromPartOfSpeechRA;
                    }
                    else if (owningFlid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidToMsFeatures)
                    {
                        pos = deriv.ToPartOfSpeechRA;
                    }
                }
                break;

            case MoStemMsa.kclsidMoStemMsa:
                IMoStemMsa stem = cobj as IMoStemMsa;
                if (stem != null)
                {
                    pos = stem.PartOfSpeechRA;
                }
                break;

            case MoStemName.kclsidMoStemName:
                IMoStemName sn = cobj as IMoStemName;
                pos = PartOfSpeech.CreateFromDBObject(sn.Cache, sn.OwnerHVO);
                break;

            case MoAffixAllomorph.kclsidMoAffixAllomorph:
                // get entry of the allomorph and then get the msa of first sense and return its (from) POS
                ILexEntry entry = LexEntry.CreateFromDBObject(m_cache, cobj.OwnerHVO);
                if (entry == null)
                {
                    return(pos);
                }
                ILexSense sense = entry.SensesOS.FirstItem;
                if (sense == null)
                {
                    return(pos);
                }
                IMoMorphSynAnalysis msa = sense.MorphoSyntaxAnalysisRA;
                pos = GetPosFromCmObjectAndFlid(msa, (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromMsFeatures);
                break;
            }
            return(pos);
        }
        private void ValidateSenseWithAnalysis(ILexSense sense, WfiGloss wfiGloss, int hvoSbWordPos, bool fMatchMainPossibility, IMoStemAllomorph allomorph)
        {
            WfiAnalysis wfiAnalysis = wfiGloss.Owner as WfiAnalysis;

            CompareTss(sense.Gloss.GetAlternativeTss(Cache.DefaultAnalWs),
                       wfiGloss.Form.GetAlternativeTss(Cache.DefaultAnalWs));

            // make sure the morph is linked to the lexicon sense, msa, and part of speech.
            IWfiMorphBundle morphBundle = wfiAnalysis.MorphBundlesOS[0];

            Assert.AreEqual(sense.Hvo, morphBundle.SenseRAHvo);
            Assert.AreEqual(sense.MorphoSyntaxAnalysisRAHvo, morphBundle.MsaRAHvo);
            if (!fMatchMainPossibility)
            {
                // expect exact possibility
                Assert.AreEqual(hvoSbWordPos, (sense.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRAHvo);
            }
            else
            {
                IPartOfSpeech posTarget = PartOfSpeech.CreateFromDBObject(Cache, hvoSbWordPos);
                Assert.AreEqual(posTarget.MainPossibility.Hvo, (sense.MorphoSyntaxAnalysisRA as MoStemMsa).PartOfSpeechRA.MainPossibility.Hvo);
            }
            Assert.AreEqual(allomorph.Hvo, morphBundle.MorphRAHvo);
            Assert.AreEqual(hvoSbWordPos, wfiAnalysis.CategoryRAHvo);
        }
Example #3
0
        public bool OnMoveReversalPOS(object cmd)
        {
            FdoCache cache = Cache;
            ObjectLabelCollection labels = new ObjectLabelCollection();

            foreach (IPartOfSpeech pos in MergeOrMoveCandidates)
            {
                labels.Add(ObjectLabel.CreateObjectLabelOnly(cache, pos.Hvo, "ShortNameTSS", "best analysis"));
            }
            using (SimpleListChooser dlg = new SimpleListChooser(cache, null, labels, 0,
                                                                 LexEdStrings.ksCategoryToMoveTo, null))
            {
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    IPartOfSpeech currentPOS = POS;
                    IPartOfSpeech newOwner   = PartOfSpeech.CreateFromDBObject(cache, dlg.ChosenOne.Hvo);
                    cache.BeginUndoTask(LexEdStrings.ksUndoMoveRevCategory,
                                        LexEdStrings.ksRedoMoveRevCategory);
                    ICmObject newOwningObj = newOwner.MoveIfNeeded(currentPOS);
                    newOwner.SubPossibilitiesOS.Append(currentPOS);
                    cache.EndUndoTask();
                    // Note: PropChanged should happen on the old owner and the new in the 'Add" method call.
                    // Have to jump to a main PartOfSpeech, as RecordClerk doesn't know anything about subcategories.
                    m_mediator.BroadcastMessageUntilHandled("JumpToRecord", newOwner.MainPossibility.Hvo);
                }
            }

            return(true);
        }
Example #4
0
        public bool OnPromoteReversalSubPOS(object cmd)
        {
            Slice slice = m_dataEntryForm.CurrentSlice;

            Debug.Assert(slice != null, "No slice was current");
            if (slice != null)
            {
                FdoCache       cache       = m_dataEntryForm.Cache;
                ICmPossibility sliceObj    = slice.Object as ICmPossibility;
                int            hvoNewOwner = cache.GetOwnerOfObject(sliceObj.OwnerHVO);
                switch (cache.GetClassOfObject(hvoNewOwner))
                {
                default:
                    throw new ArgumentException("Illegal class.");

                case PartOfSpeech.kclsidPartOfSpeech:
                {
                    IPartOfSpeech pos = PartOfSpeech.CreateFromDBObject(cache, hvoNewOwner);
                    pos.SubPossibilitiesOS.Append(sliceObj);
                    break;
                }

                case CmPossibilityList.kclsidCmPossibilityList:
                {
                    ICmPossibilityList posList = CmPossibilityList.CreateFromDBObject(cache, hvoNewOwner);
                    posList.PossibilitiesOS.Append(sliceObj);
                    break;
                }
                }
            }
            return(true);
        }
Example #5
0
        /// <summary>
        /// Determine if a PartOfSpeech requires inflection.
        /// If it or any of its parent POSes have a template, it requires inflection.
        /// </summary>
        /// <param name="posHvo">hvo of the Part of Speech</param>
        /// <returns>true if it does, false otherwise</returns>
        protected bool RequiresInflection(int posHvo)
        {
            bool fResult = false;              // be pessimistic

            if (posHvo > 0)
            {
                IPartOfSpeech pos = PartOfSpeech.CreateFromDBObject(m_cache, posHvo);
                fResult = pos.RequiresInflection();
            }
            return(fResult);
        }
Example #6
0
        //methods

        public override ObjectLabel Execute()
        {
            IMoInflAffixSlot slot = new MoInflAffixSlot();
            IPartOfSpeech    pos  = PartOfSpeech.CreateFromDBObject(m_cache, m_posHvo);

            pos.AffixSlotsOC.Add(slot);
            string sNewSlotName = m_mediator.StringTbl.GetString("NewSlotName", "Linguistics/Morphology/TemplateTable");

            slot.Name.AnalysisDefaultWritingSystem = sNewSlotName;
            slot.Optional = m_fOptional;
            return(ObjectLabel.CreateObjectLabel(m_cache, slot.Hvo, ""));
        }
Example #7
0
        protected void CreateStemMsaXmlElement(XmlDocument doc, XmlNode morphNode, IMoStemMsa stemMsa)
        {
            XmlNode stemMsaNode = CreateXmlElement(doc, "stemMsa", morphNode);

            CreatePOSXmlAttribute(doc, stemMsaNode, stemMsa.PartOfSpeechRA, "cat");
            IMoInflClass inflClass = stemMsa.InflectionClassRA;

            if (inflClass == null)
            {             // use default inflection class of the POS or
                // the first ancestor POS that has a non-zero default inflection class
                int           inflClassHvo = 0;
                IPartOfSpeech pos          = stemMsa.PartOfSpeechRA;
                while (pos != null && inflClassHvo == 0)
                {
                    if (pos.DefaultInflectionClassRAHvo != 0)
                    {
                        inflClassHvo = pos.DefaultInflectionClassRAHvo;
                    }
                    else
                    {
                        int clsid = m_cache.GetClassOfObject(pos.OwnerHVO);
                        if (clsid == PartOfSpeech.kClassId)
                        {
                            pos = PartOfSpeech.CreateFromDBObject(m_cache, pos.OwnerHVO);
                        }
                        else
                        {
                            pos = null;
                        }
                    }
                }
                if (inflClassHvo != 0)
                {
                    inflClass = MoInflClass.CreateFromDBObject(m_cache, inflClassHvo);
                }
            }
            CreateInflectionClassXmlAttribute(doc, stemMsaNode, inflClass, "inflClass");
            CreateRequiresInflectionXmlAttribute(doc, stemMsa.PartOfSpeechRAHvo, stemMsaNode);
            CreateFeatureStructureNodes(doc, stemMsaNode, stemMsa.MsFeaturesOA, stemMsa.Hvo);
            CreateProductivityRestrictionNodes(doc, stemMsaNode, stemMsa.ProdRestrictRC, "productivityRestriction");
            CreateFromPOSNodes(doc, stemMsaNode, stemMsa.FromPartsOfSpeechRC, "fromPartsOfSpeech");
        }
Example #8
0
        private Set <int> GetHvoSlots()
        {
            Set <int>     hvoSlots;
            IPartOfSpeech pos = PartOfSpeech.CreateFromDBObject(m_cache, m_selectedMainPOSHvo);

            if (m_morphType == null)
            {             // Not called by InsertEntryDlg; need to figure out the morphtype(s)
                LexEntry lex = m_mediator.PropertyTable.GetValue("ActiveClerkSelectedObject") as LexEntry;
                if (lex != null)
                {
                    hvoSlots = MoInflAffMsa.GetSetOfSlots(m_cache, lex, pos);
                }
                else
                {
                    hvoSlots = new Set <int>(pos.AllAffixSlotIDs);
                }
            }
            else
            {             //  Called by InsertEntryDlg so we know the morphtype
                bool fIsPrefixal = false;
                bool fIsSuffixal = false;
                if (MoMorphType.IsPrefixishType(m_cache, m_morphType.Hvo))
                {
                    fIsPrefixal = true;
                }
                if (MoMorphType.IsSuffixishType(m_cache, m_morphType.Hvo))
                {
                    fIsSuffixal = true;
                }
                if (fIsPrefixal && fIsSuffixal)
                {
                    hvoSlots = new Set <int>(pos.AllAffixSlotIDs);
                }
                else
                {
                    hvoSlots =
                        MoInflAffixTemplate.GetSomeSlots(m_cache, new Set <int>(pos.AllAffixSlotIDs), fIsPrefixal);
                }
            }
            return(hvoSlots);
        }
Example #9
0
        /// <summary>
        /// Handle the context menu for inserting a POS.
        /// </summary>
        /// <param name="mediator"></param>
        /// <param name="classId"></param>
        /// <param name="hvoOwner"></param>
        /// <param name="flid"></param>
        /// <param name="insertionPosition"></param>
        /// <returns></returns>
        public new static PartOfSpeechUi CreateNewUiObject(Mediator mediator, uint classId, int hvoOwner, int flid, int insertionPosition)
        {
            PartOfSpeechUi posUi = null;

            using (MasterCategoryListDlg dlg = new MasterCategoryListDlg())
            {
                FdoCache cache = (FdoCache)mediator.PropertyTable.GetValue("cache");
                Debug.Assert(cache != null);
                IPartOfSpeech newOwner = PartOfSpeech.CreateFromDBObject(cache, hvoOwner);
                dlg.SetDlginfo(newOwner.OwningList, mediator, true, newOwner);
                switch (dlg.ShowDialog((Form)mediator.PropertyTable.GetValue("window")))
                {
                case DialogResult.OK:                         // Fall through.
                case DialogResult.Yes:
                    posUi = new PartOfSpeechUi(dlg.SelectedPOS);
                    mediator.SendMessage("JumpToRecord", dlg.SelectedPOS.Hvo);
                    break;
                }
            }
            return(posUi);
        }
        protected override TreeNode MakeMenuItems(PopupTree popupTree, int hvoTarget)
        {
            int tagNamePOS = UseAbbr ?
                             (int)CmPossibility.CmPossibilityTags.kflidAbbreviation :
                             (int)CmPossibility.CmPossibilityTags.kflidName;

            List <HvoTreeNode> relevantPartsOfSpeech = new List <HvoTreeNode>();

            InflectionClassPopupTreeManager.GatherPartsOfSpeech(Cache, List.Hvo,
                                                                (int)CmPossibilityList.CmPossibilityListTags.kflidPossibilities,
                                                                (int)CmPossibility.CmPossibilityTags.kflidSubPossibilities,
                                                                (int)PartOfSpeech.PartOfSpeechTags.kflidInflectableFeats,
                                                                tagNamePOS, WritingSystem,
                                                                relevantPartsOfSpeech);
            relevantPartsOfSpeech.Sort();
            TreeNode match = null;

            foreach (HvoTreeNode item in relevantPartsOfSpeech)
            {
                popupTree.Nodes.Add(item);
                IPartOfSpeech pos = (IPartOfSpeech)PartOfSpeech.CreateFromDBObject(Cache, item.Hvo, false);
                foreach (IFsFeatStruc fs in pos.ReferenceFormsOC)
                {
                    // Note: beware of using fs.ShortName. That can be
                    // absolutely EMPTY (if the user has turned off the 'Show Abbreviation as its label'
                    // field for both the feature category and value).
                    // ChooserName shows the short name if it is non-empty, otherwise the long name.
                    HvoTreeNode node = new HvoTreeNode(fs.ChooserNameTS, fs.Hvo);
                    item.Nodes.Add(node);
                    if (fs.Hvo == hvoTarget)
                    {
                        match = node;
                    }
                }
                item.Nodes.Add(new HvoTreeNode(Cache.MakeUserTss(LexTextControls.ksChooseInflFeats), kMore));
            }
            return(match);
        }
        protected override void m_treeCombo_AfterSelect(object sender, TreeViewEventArgs e)
        {
            HvoTreeNode selectedNode = e.Node as HvoTreeNode;
            PopupTree   pt           = GetPopupTree();

            switch (selectedNode.Hvo)
            {
            case kMore:
                // Only launch the dialog by a mouse click (or simulated mouse click).
                if (e.Action != TreeViewAction.ByMouse)
                {
                    break;
                }
                // Force the PopupTree to Hide() to trigger popupTree_PopupTreeClosed().
                // This will effectively revert the list selection to a previous confirmed state.
                // Whatever happens below, we don't want to actually leave the "More..." node selected!
                // This is at least required if the user selects "Cancel" from the dialog below.
                pt.Hide();
                using (MsaInflectionFeatureListDlg dlg = new MsaInflectionFeatureListDlg())
                {
                    HvoTreeNode   parentNode = selectedNode.Parent as HvoTreeNode;
                    int           hvoPos     = parentNode.Hvo;
                    IPartOfSpeech pos        = (IPartOfSpeech)PartOfSpeech.CreateFromDBObject(Cache, hvoPos, false);
                    dlg.SetDlgInfo(Cache, m_mediator, pos);
                    switch (dlg.ShowDialog(ParentForm))
                    {
                    case DialogResult.OK:
                    {
                        int hvoFs = 0;
                        if (dlg.FS != null)
                        {
                            hvoFs = dlg.FS.Hvo;
                        }
                        LoadPopupTree(hvoFs);
                        // everything should be setup with new node selected, so return.
                        return;
                    }

                    case DialogResult.Yes:
                    {
                        // go to m_highestPOS in editor
                        // Also, is there some way to know the application name and tool name without hard coding them?
                        FdoUi.FwLink linkJump = new SIL.FieldWorks.FdoUi.FwLink("Language Explorer", "posEdit",
                                                                                dlg.HighestPOS.Guid, Cache.ServerName, Cache.DatabaseName);
                        m_mediator.PostMessage("FollowLink", linkJump);
                        if (ParentForm != null && ParentForm.Modal)
                        {
                            // Close the dlg that opened the popup tree,
                            // since its hotlink was used to close it,
                            // and a new item has been created.
                            ParentForm.DialogResult = DialogResult.Cancel;
                            ParentForm.Close();
                        }
                        break;
                    }

                    default:
                        // NOTE: If the user has selected "Cancel", then don't change
                        // our m_lastConfirmedNode to the "More..." node. Keep it
                        // the value set by popupTree_PopupTreeClosed() when we
                        // called pt.Hide() above. (cf. comments in LT-2522)
                        break;
                    }
                }
                break;

            default:
                break;
            }

            base.m_treeCombo_AfterSelect(sender, e);
        }