Esempio n. 1
0
 /// <summary>
 /// Handle launching of the MSA editor.
 /// </summary>
 protected override void HandleChooser()
 {
     using (MsaCreatorDlg dlg = new MsaCreatorDlg())
     {
         MoMorphSynAnalysis originalMsa = m_obj as MoMorphSynAnalysis;
         ILexEntry          entry       = LexEntry.CreateFromDBObject(m_cache, originalMsa.OwnerHVO);
         dlg.SetDlgInfo(m_cache,
                        m_persistProvider,
                        m_mediator,
                        entry,
                        DummyGenericMSA.Create(originalMsa),
                        originalMsa.Hvo,
                        true,
                        String.Format(LexEdStrings.ksEditX, Slice.Label));
         if (dlg.ShowDialog(FindForm()) == DialogResult.OK)
         {
             DummyGenericMSA dummyMsa = dlg.DummyMSA;
             if (!originalMsa.EqualsMsa(dummyMsa))
             {
                 m_cache.BeginUndoTask(LexEdStrings.ksUndoEditFunction,
                                       LexEdStrings.ksRedoEditFunction);
                 // The UpdateOrReplace call may end up disposing this. So any variables we
                 // need after it must be copied to the stack.
                 FdoCache            cache  = m_cache;
                 Slice               parent = Slice;
                 IMoMorphSynAnalysis newMsa = originalMsa.UpdateOrReplace(dummyMsa);
                 cache.EndUndoTask();
             }
         }
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="hvo"></param>
        /// <param name="tag"></param>
        /// <param name="ws"></param>
        /// <param name="cda"></param>
        public override void Load(int hvo, int tag, int ws, IVwCacheDa cda)
        {
            IMoMorphSynAnalysis msa = MoMorphSynAnalysis.CreateFromDBObject(m_cache, hvo);
            ITsStrFactory       tsf = TsStrFactoryClass.Create();

            cda.CacheStringProp(hvo, tag, tsf.MakeString(msa.InterlinearName, m_cache.DefaultAnalWs));
        }
Esempio n. 3
0
        protected void ConvertMorphs(XmlDocument doc, string sNodeListToFind, bool fIdsInAttribute)
        {
            XmlNodeList nl = doc.SelectNodes(sNodeListToFind);

            if (nl != null)
            {
                foreach (XmlNode node in nl)
                {
                    XmlNode alloid;
                    if (fIdsInAttribute)
                    {
                        alloid = node.Attributes.GetNamedItem("alloid");
                    }
                    else
                    {
                        alloid = node.SelectSingleNode("MoForm/@DbRef");
                    }
                    int     hvo  = Convert.ToInt32(alloid.InnerText);
                    IMoForm form = MoForm.CreateFromDBObject(m_cache, hvo);
                    string  sLongName;
                    string  sForm;
                    string  sGloss;
                    string  sCitationForm;
                    if (form != null)
                    {
                        sLongName = form.LongName;
                        int iFirstSpace = sLongName.IndexOf(" (");
                        int iLastSpace  = sLongName.LastIndexOf("):") + 2;
                        sForm = sLongName.Substring(0, iFirstSpace);
                        XmlNode msaid;
                        if (fIdsInAttribute)
                        {
                            msaid = node.Attributes.GetNamedItem("morphname");
                        }
                        else
                        {
                            msaid = node.SelectSingleNode("MSI/@DbRef");
                        }
                        int hvoMsa = Convert.ToInt32(msaid.InnerText);
                        IMoMorphSynAnalysis msa = MoMorphSynAnalysis.CreateFromDBObject(m_cache, hvoMsa);
                        if (msa != null)
                        {
                            sGloss = msa.GetGlossOfFirstSense();
                        }
                        else
                        {
                            sGloss = sLongName.Substring(iFirstSpace, iLastSpace - iFirstSpace).Trim();
                        }
                        sCitationForm = sLongName.Substring(iLastSpace).Trim();
                        sLongName     = String.Format(ParserUIStrings.ksX_Y_Z, sForm, sGloss, sCitationForm);
                    }
                    else
                    {
                        sForm         = ParserUIStrings.ksUnknownMorpheme;                 // in case the user continues...
                        sGloss        = ParserUIStrings.ksUnknownGloss;
                        sCitationForm = ParserUIStrings.ksUnknownCitationForm;
                        sLongName     = String.Format(ParserUIStrings.ksX_Y_Z, sForm, sGloss, sCitationForm);
                        throw new ApplicationException(sLongName);
                    }
                    XmlNode tempNode = CreateXmlElement(doc, "shortName", node);
                    tempNode.InnerXml = CreateEntities(sLongName);
                    tempNode          = CreateXmlElement(doc, "alloform", node);
                    tempNode.InnerXml = CreateEntities(sForm);
                    switch (form.ClassID)
                    {
                    case MoStemAllomorph.kclsidMoStemAllomorph:
                        ConvertStemName(doc, node, form, tempNode);
                        break;

                    case MoAffixAllomorph.kclsidMoAffixAllomorph:
                        ConvertAffixAlloFeats(doc, node, form, tempNode);
                        ConvertStemNameAffix(doc, node, tempNode);
                        break;
                    }
                    tempNode          = CreateXmlElement(doc, "gloss", node);
                    tempNode.InnerXml = CreateEntities(sGloss);
                    tempNode          = CreateXmlElement(doc, "citationForm", node);
                    tempNode.InnerXml = CreateEntities(sCitationForm);
                }
            }
        }
Esempio n. 4
0
        // Make a string representing a WfiAnalysis, suitable for use in a combo box item.
        static internal ITsString MakeAnalysisStringRep(int hvoWa, FdoCache fdoCache, bool fUseStyleSheet, int wsVern)
        {
            //			ITsTextProps boldItalicAnalysis = BoldItalicAnalysis(fdoCache);
            //			ITsTextProps italicAnalysis = ItalicAnalysis(fdoCache, Sandbox.SandboxVc.krgbRed);
            ITsTextProps   posTextProperties   = PartOfSpeechTextProperties(fdoCache, true, fUseStyleSheet);
            ITsTextProps   formTextProperties  = FormTextProperties(fdoCache, fUseStyleSheet, wsVern);
            ITsTextProps   glossTextProperties = GlossTextProperties(fdoCache, true, fUseStyleSheet);
            ITsStrBldr     tsb    = TsStrBldrClass.Create();
            ISilDataAccess sda    = fdoCache.MainCacheAccessor;
            int            cmorph = fdoCache.GetVectorSize(hvoWa,
                                                           (int)WfiAnalysis.WfiAnalysisTags.kflidMorphBundles);

            if (cmorph == 0)
            {
                return(fdoCache.MakeUserTss(ITextStrings.ksNoMorphemes));
            }
            bool fRtl      = fdoCache.LanguageWritingSystemFactoryAccessor.get_EngineOrNull(wsVern).RightToLeft;
            int  start     = 0;
            int  lim       = cmorph;
            int  increment = 1;

            if (fRtl)
            {
                start     = cmorph - 1;
                lim       = -1;
                increment = -1;
            }
            for (int i = start; i != lim; i += increment)
            {
                int hvoMb = fdoCache.GetVectorItem(hvoWa,
                                                   (int)WfiAnalysis.WfiAnalysisTags.kflidMorphBundles, i);
                int hvoMf = fdoCache.GetObjProperty(hvoMb,
                                                    (int)WfiMorphBundle.WfiMorphBundleTags.kflidMorph);
                ITsString tssForm = null;
                if (hvoMf != 0)
                {
                    int hvoEntry      = fdoCache.GetOwnerOfObject(hvoMf);
                    int hvoLexemeForm = sda.get_ObjectProp(hvoEntry, (int)LexEntry.LexEntryTags.kflidLexemeForm);
                    if (hvoLexemeForm != 0)
                    {
                        tssForm = sda.get_MultiStringAlt(hvoLexemeForm, (int)MoForm.MoFormTags.kflidForm, wsVern);
                    }
                    if (tssForm == null || tssForm.Length == 0)
                    {
                        tssForm = fdoCache.MainCacheAccessor.get_MultiStringAlt(hvoEntry,
                                                                                (int)LexEntry.LexEntryTags.kflidCitationForm, wsVern);
                    }
                    if (tssForm.Length == 0)
                    {
                        // If there isn't a lexeme form OR citation form use the form of the morph.
                        tssForm = fdoCache.MainCacheAccessor.get_MultiStringAlt(hvoMf,
                                                                                (int)MoForm.MoFormTags.kflidForm, wsVern);
                    }
                }
                else                 // no MoForm linked to this bundle, use its own form.
                {
                    tssForm = fdoCache.MainCacheAccessor.get_MultiStringAlt(hvoMb,
                                                                            (int)WfiMorphBundle.WfiMorphBundleTags.kflidForm, wsVern);
                }
                int ichForm = tsb.Length;
                tsb.ReplaceTsString(ichForm, ichForm, tssForm);
                tsb.SetProperties(ichForm, tsb.Length, formTextProperties);

                // add category (part of speech)
                int hvoMsa = fdoCache.GetObjProperty(hvoMb,
                                                     (int)WfiMorphBundle.WfiMorphBundleTags.kflidMsa);
                tsb.Replace(tsb.Length, tsb.Length, " ", null);
                int    ichMinMsa    = tsb.Length;
                string interlinName = ksMissingString;
                if (hvoMsa != 0)
                {
                    IMoMorphSynAnalysis msa =
                        MoMorphSynAnalysis.CreateFromDBObject(fdoCache, hvoMsa);
                    interlinName = msa.InterlinearAbbr;
                }
                tsb.Replace(ichMinMsa, ichMinMsa, interlinName, posTextProperties);

                //add sense
                int hvoSense = fdoCache.GetObjProperty(hvoMb,
                                                       (int)WfiMorphBundle.WfiMorphBundleTags.kflidSense);
                tsb.Replace(tsb.Length, tsb.Length, " ", null);
                int ichMinSense = tsb.Length;
                if (hvoSense != 0)
                {
                    ITsString tssGloss = fdoCache.MainCacheAccessor.get_MultiStringAlt(hvoSense,
                                                                                       (int)LexSense.LexSenseTags.kflidGloss, fdoCache.DefaultAnalWs);
                    tsb.Replace(ichMinSense, ichMinSense, tssGloss.Text, glossTextProperties);
                }
                else
                {
                    tsb.Replace(ichMinSense, ichMinSense, ksMissingString, glossTextProperties);
                }

                // Enhance JohnT: use proper seps.
                tsb.Replace(tsb.Length, tsb.Length, ksPartSeparator, null);
            }
            // Delete the final separator. (Enhance JohnT: this needs to get smarter when we do
            // real seps.)
            int ichFrom = tsb.Length - ksPartSeparator.Length;

            if (ichFrom < 0)
            {
                ichFrom = 0;
            }
            tsb.Replace(ichFrom, tsb.Length, "", null);
            return(tsb.GetString());
        }