Exemple #1
0
        protected void AddMissingMSAs()
        {
            int count = 0;

            Console.WriteLine("AddMissingMSAs()...");
            LexDb l = m_cache.LangProj.LexDbOA;

            foreach (LexEntry e in l.EntriesOC)
            {
                if (e.MorphoSyntaxAnalysesOC.Count == 0)
                {
                    ++count;
                    Console.WriteLine("Adding Stem MSAs to " + e.ShortName);
                    MoStemMsa s = e.MorphoSyntaxAnalysesOC.Add(new SIL.FieldWorks.FDO.Ling.MoStemMsa()) as MoStemMsa;
                }
            }
            Console.WriteLine("Changed " + count.ToString() + " entries.");
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <param name="ld"></param>
        /// <param name="cf"></param>
        /// <param name="defn"></param>
        /// <param name="hvoDomain"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        protected ILexEntry MakeLexEntry(ILexDb ld, string cf, string defn, int hvoDomain)
        {
            ILexEntry le = ld.EntriesOC.Add(new LexEntry());

            le.CitationForm.VernacularDefaultWritingSystem = cf;
            ILexSense ls = le.SensesOS.Append(new LexSense());

            ls.Definition.AnalysisDefaultWritingSystem.Text = defn;
            if (hvoDomain != 0)
            {
                ls.SemanticDomainsRC.Add(hvoDomain);
            }
            MoMorphSynAnalysis msa = new MoStemMsa();

            le.MorphoSyntaxAnalysesOC.Add(msa);
            ls.MorphoSyntaxAnalysisRA = msa;
            return(le);
        }
        /// <summary>
        /// Execute the change requested by the current selection in the combo.
        /// Basically we want the MoInflClass indicated by m_selectedHvo, (even if 0?? not yet possible),
        /// to become the InflectionClass of each record that is appropriate to change.
        /// We do nothing to records where the check box is turned off,
        /// and nothing to ones that currently have an MSA other than an MoStemMsa,
        /// and nothing to ones that currently have an MSA with the wrong POS.
        /// (a) If the owning entry has an MoStemMsa with the right inflection class (and presumably POS),
        /// set the sense to use it.
        /// (b) If all senses using the current MoStemMsa are to be changed, just update
        /// the inflection class of that MoStemMsa.
        /// We could add this...but very probably unused MSAs would have been taken over
        /// when setting the POS.
        /// --(c) If the entry has an MoStemMsa which is not being used at all, change it to
        /// --the required POS and inflection class and use it.
        /// (d) Make a new MoStemMsa in the LexEntry with the required POS and inflection class
        /// and point the sense at it.
        /// </summary>
        public void DoIt(Set <int> itemsToChange, ProgressState state)
        {
            CheckDisposed();

            int hvoPos = GetPOS();
            // A Set of eligible parts of speech to use in filtering.
            Set <int> possiblePOS = GetPossiblePartsOfSpeech();
            // Make a Dictionary from HVO of entry to list of modified senses.
            Dictionary <int, List <ILexSense> > sensesByEntry = new Dictionary <int, List <ILexSense> >();
            int tagOwningEntry = m_cache.VwCacheDaAccessor.GetVirtualHandlerName("LexSense", "OwningEntry").Tag;
            int i = 0;
            // Report progress 50 times or every 100 items, whichever is more (but no more than once per item!)
            int interval = Math.Min(100, Math.Max(itemsToChange.Count / 50, 1));

            foreach (int hvoSense in itemsToChange)
            {
                i++;
                if (i % interval == 0)
                {
                    state.PercentDone = i * 20 / itemsToChange.Count;
                    state.Breath();
                }
                if (!IsItemEligible(m_cache.MainCacheAccessor, hvoSense, possiblePOS))
                {
                    continue;
                }
                ILexSense           ls  = (ILexSense)CmObject.CreateFromDBObject(m_cache, hvoSense, false);
                IMoMorphSynAnalysis msa = ls.MorphoSyntaxAnalysisRA;
                int hvoEntry            = m_cache.MainCacheAccessor.get_ObjectProp(ls.Hvo, tagOwningEntry);
                if (!sensesByEntry.ContainsKey(hvoEntry))
                {
                    sensesByEntry[hvoEntry] = new List <ILexSense>();
                }
                sensesByEntry[hvoEntry].Add(ls);
            }
            m_cache.BeginUndoTask(FdoUiStrings.ksUndoBEInflClass, FdoUiStrings.ksRedoBEInflClass);
            BulkEditBar.ForceRefreshOnUndoRedo(m_cache.MainCacheAccessor);
            i        = 0;
            interval = Math.Min(100, Math.Max(sensesByEntry.Count / 50, 1));
            foreach (KeyValuePair <int, List <ILexSense> > kvp in sensesByEntry)
            {
                i++;
                if (i % interval == 0)
                {
                    state.PercentDone = i * 80 / sensesByEntry.Count + 20;
                    state.Breath();
                }
                ILexEntry        entry          = (ILexEntry)CmObject.CreateFromDBObject(m_cache, kvp.Key, false);
                List <ILexSense> sensesToChange = kvp.Value;
                IMoStemMsa       msmTarget      = null;
                foreach (IMoMorphSynAnalysis msa in entry.MorphoSyntaxAnalysesOC)
                {
                    IMoStemMsa msm = msa as IMoStemMsa;
                    if (msm != null && msm.InflectionClassRAHvo == m_selectedHvo)
                    {
                        // Can reuse this one!
                        msmTarget = msm;
                        break;
                    }
                }
                if (msmTarget == null)
                {
                    // See if we can reuse an existing MoStemMsa by changing it.
                    // This is possible if it is used only by senses in the list, or not used at all.
                    List <ILexSense> otherSenses = new List <ILexSense>();
                    if (entry.SensesOS.Count != sensesToChange.Count)
                    {
                        foreach (ILexSense ls in entry.SensesOS)
                        {
                            if (!sensesToChange.Contains(ls))
                            {
                                otherSenses.Add(ls);
                            }
                        }
                    }
                    foreach (IMoMorphSynAnalysis msa in entry.MorphoSyntaxAnalysesOC)
                    {
                        IMoStemMsa msm = msa as IMoStemMsa;
                        if (msm == null)
                        {
                            continue;
                        }
                        bool fOk = true;
                        foreach (ILexSense ls in otherSenses)
                        {
                            if (ls.MorphoSyntaxAnalysisRA == msm)
                            {
                                fOk = false;
                                break;
                            }
                        }
                        if (fOk)
                        {
                            // Can reuse this one! Nothing we don't want to change uses it.
                            // Adjust its POS as well as its inflection class, just to be sure.
                            msmTarget = msm;
                            msmTarget.PartOfSpeechRAHvo    = hvoPos;
                            msmTarget.InflectionClassRAHvo = m_selectedHvo;
                            break;
                        }
                    }
                }
                if (msmTarget == null)
                {
                    // Nothing we can reuse...make a new one.
                    msmTarget = new MoStemMsa();
                    entry.MorphoSyntaxAnalysesOC.Add(msmTarget);
                    msmTarget.PartOfSpeechRAHvo    = hvoPos;
                    msmTarget.InflectionClassRAHvo = m_selectedHvo;
                }
                // Finally! Make the senses we want to change use it.
                foreach (ILexSense ls in sensesToChange)
                {
                    ls.MorphoSyntaxAnalysisRA = msmTarget;
                }
            }
            m_cache.EndUndoTask();
        }
Exemple #4
0
        private void m_MSAPopupTreeManager_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // unless we get a mouse click or simulated mouse click (e.g. by ENTER or TAB),
            // do not treat as an actual selection.
            if (m_handlingMessage || e.Action != TreeViewAction.ByMouse)
            {
                return;
            }
            HvoTreeNode htn = e.Node as HvoTreeNode;

            if (htn == null)
            {
                return;
            }

            // Don't try changing values on a deleted object!  See LT-8656 and LT-9119.
            if (!m_cache.VerifyValidObject(m_obj))
            {
                return;
            }

            int hvoSel = htn.Hvo;

            // if hvoSel is negative, then MSAPopupTreeManager's AfterSelect has handled it,
            // except possibly for refresh.
            if (hvoSel < 0)
            {
                ContainingDataTree.RefreshList(false);
                return;
            }
            LexSense sense = m_obj as LexSense;
            // Setting sense.DummyMSA can cause the DataTree to want to refresh.  Don't
            // let this happen until after we're through!  See LT-9713 and LT-9714.
            bool fOldDoNotRefresh = ContainingDataTree.DoNotRefresh;

            try
            {
                m_handlingMessage = true;
                int clidSel = 0;
                if (hvoSel > 0)
                {
                    clidSel = m_cache.GetClassOfObject(hvoSel);
                }
                bool didChange = false;
                if (clidSel == PartOfSpeech.kclsidPartOfSpeech)
                {
                    ContainingDataTree.DoNotRefresh = true;
                    m_cache.BeginUndoTask(
                        String.Format(DetailControlsStrings.ksUndoSet, m_fieldName),
                        String.Format(DetailControlsStrings.ksRedoSet, m_fieldName));
                    DummyGenericMSA dummyMSA = new DummyGenericMSA();
                    dummyMSA.MsaType = sense.GetDesiredMsaType();
                    dummyMSA.MainPOS = hvoSel;
                    MoStemMsa stemMsa = sense.MorphoSyntaxAnalysisRA as MoStemMsa;
                    if (stemMsa != null)
                    {
                        dummyMSA.FromPartsOfSpeech = stemMsa.FromPartsOfSpeechRC;
                    }
                    sense.DummyMSA = dummyMSA;
                    didChange      = true;
                }
                else if (sense.MorphoSyntaxAnalysisRAHvo != hvoSel)
                {
                    ContainingDataTree.DoNotRefresh = true;
                    m_cache.BeginUndoTask(
                        String.Format(DetailControlsStrings.ksUndoSet, m_fieldName),
                        String.Format(DetailControlsStrings.ksRedoSet, m_fieldName));
                    sense.MorphoSyntaxAnalysisRAHvo = hvoSel;
                    didChange = true;
                }
                if (didChange)
                {
                    m_cache.EndUndoTask();
                }
                if (!ContainingDataTree.RefreshListNeeded)
                {
                    m_MSAPopupTreeManager.LoadPopupTree(sense.MorphoSyntaxAnalysisRAHvo);
                    // Don't refresh the datatree unless the popup has actually been loaded.
                    // It could be setting the selection in the process of loading!  See LT-9191.
                    if (m_MSAPopupTreeManager.IsTreeLoaded)
                    {
                        ContainingDataTree.RefreshList(false);
                    }
                }
            }
            finally
            {
                m_handlingMessage = false;
                // We still can't refresh the data at this point without causing a crash due to
                // a pending Windows message.  See LT-9713 and LT-9714.
                if (ContainingDataTree.DoNotRefresh != fOldDoNotRefresh)
                {
                    Mediator.BroadcastMessage("DelayedRefreshList", fOldDoNotRefresh);
                }
            }
        }