Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="nodes"></param>
        /// <param name="hvoOwner"></param>
        /// <param name="flid"></param>
        /// <param name="flidSub">specify a subitems,
        /// other than CmPossibilityTags.kflidSubPossibilities</param>
        /// <param name="hvoTarget"></param>
        /// <param name="tagName"></param>
        /// <returns></returns>
        protected TreeNode AddNodes(TreeNodeCollection nodes, int hvoOwner,
                                    int flid, int flidSub, int hvoTarget, int tagName)
        {
            TreeNode result = null;
            int      chvo   = Cache.MainCacheAccessor.get_VecSize(hvoOwner, flid);

            for (int i = 0; i < chvo; i++)
            {
                int       hvoChild = Cache.MainCacheAccessor.get_VecItem(hvoOwner, flid, i);
                ITsString tssLabel = WritingSystemServices.GetMagicStringAlt(Cache,
                                                                             WritingSystemServices.kwsFirstAnalOrVern, hvoChild, tagName);
                if (tssLabel == null)
                {
                    tssLabel = TsStringUtils.MakeTss(LexTextControls.ksStars, Cache.WritingSystemFactory.UserWs);
                }
                HvoTreeNode node = new HvoTreeNode(tssLabel, hvoChild);
                nodes.Add(node);
                TreeNode temp = AddNodes(node.Nodes, hvoChild,
                                         flidSub, flidSub, hvoTarget, tagName);
                if (hvoChild == hvoTarget)
                {
                    result = node;
                }
                else if (temp != null)
                {
                    result = temp;
                }
            }
            return(result);
        }
Example #2
0
        public void GetMagicStringAlt_TestFirstPronunciation()
        {
            CoreWritingSystemDefinition mluWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "mlu", false, false, out mluWs);
            var mluId = mluWs.Handle;
            CoreWritingSystemDefinition senWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "sen", false, false, out senWs);
            var senId = senWs.Handle;

            Cache.LangProject.CurrentPronunciationWritingSystems.Clear();
            Cache.LangProject.CurrentPronunciationWritingSystems.Add(mluWs);
            Cache.LangProject.CurrentPronunciationWritingSystems.Add(senWs);
            var entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();

            entry.CitationForm.set_String(mluId, TsStringUtils.MakeString("To'abaita", mluId));
            entry.CitationForm.set_String(senId, TsStringUtils.MakeString("Sena", senId));
            int wsId;

            //SUT magic gets first pronuciation when there is one.
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstPronunciation, entry.Hvo, entry.CitationForm.Flid, false, out wsId);
            Assert.AreEqual(wsId, mluId, "Did not pull first pronuciation language first.");
            //SUT magic gets second pronuciation when the first is empty
            entry.CitationForm.set_String(mluId, TsStringUtils.EmptyString(mluId));             //wipe Sena
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstPronunciation, entry.Hvo, entry.CitationForm.Flid, false, out wsId);
            Assert.AreEqual(wsId, senId, "Did not pull second pronuciation language when first was empty.");
        }
Example #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Try GetAlternativeTss on the given 'wsPreferred', else return the BestAlternativeTss, giving
        /// preference to vernacular or analysis if 'wsPreferred' is vernacular or analysis.
        /// </summary>
        /// <param name="wsPreferred">The ws preferred.</param>
        /// <param name="wsActual">ws of the best found alternative</param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public ITsString GetAlternativeOrBestTss(int wsPreferred, out int wsActual)
        {
            ITsString tss;

            if (wsPreferred < 0)
            {
                // already magic, try for that.
                tss = WritingSystemServices.GetMagicStringAlt(m_object.Cache,
                                                              wsPreferred, m_object.Hvo, m_flid, true, out wsActual);
                if ((tss == null || tss.Length == 0) && wsPreferred != WritingSystemServices.kwsFirstAnalOrVern)
                {
                    tss = WritingSystemServices.GetMagicStringAlt(m_object.Cache, WritingSystemServices.kwsFirstAnalOrVern,
                                                                  m_object.Hvo, m_flid, true, out wsActual);
                }
                return(tss);
            }
            var pref = m_object.Services.WritingSystemManager.Get(wsPreferred);

            wsActual = pref.Handle;

            if (!TryGetValue(pref.Handle, out tss))
            {
                tss = WritingSystemServices.GetMagicStringAlt(m_object.Cache,
                                                              WritingSystemServices.kwsFirstVernOrAnal, m_object.Hvo, m_flid, true, out wsActual);
                if (tss == null || tss.Length == 0)
                {
                    tss = WritingSystemServices.GetMagicStringAlt(m_object.Cache, WritingSystemServices.kwsFirstAnalOrVern,
                                                                  m_object.Hvo, m_flid, true, out wsActual);
                }
            }

            return(tss);
        }
Example #4
0
        public void GetMagicStringAlt_TestFirstAnaly()
        {
            CoreWritingSystemDefinition frWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "fr", false, false, out frWs);
            var frId = frWs.Handle;
            CoreWritingSystemDefinition enWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en", false, false, out enWs);
            var enId = enWs.Handle;
            CoreWritingSystemDefinition ptWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "pt", false, false, out ptWs);
            var ptId = ptWs.Handle;

            Cache.LangProject.CurrentAnalysisWritingSystems.Clear();
            Cache.LangProject.AddToCurrentAnalysisWritingSystems(frWs);
            Cache.LangProject.AddToCurrentAnalysisWritingSystems(enWs);
            Cache.LangProject.AnalysisWritingSystems.Add(ptWs);
            var entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();
            var sense = Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create();

            entry.SensesOS.Add(sense);
            sense.Definition.set_String(frId, TsStringUtils.MakeString("fr", frId));
            sense.Definition.set_String(enId, TsStringUtils.MakeString("en", enId));
            sense.Definition.set_String(ptId, TsStringUtils.MakeString("pt", ptId));
            int wsId;

            //SUT magic gets first analysis when there is one.
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstAnal, sense.Hvo, sense.Definition.Flid, false, out wsId);
            Assert.AreEqual(wsId, frId, "Did not pull first analysis language first.");
            //SUT magic gets second analysis when the first is empty
            sense.Definition.set_String(frId, TsStringUtils.EmptyString(frId));             //wipe french
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstAnal, sense.Hvo, sense.Definition.Flid, false, out wsId);
            Assert.AreEqual(wsId, enId, "Did not pull second analysis language when first was empty.");
            //SUT magic gets non current analysis when all current analysis languages are empty
            sense.Definition.set_String(enId, TsStringUtils.EmptyString(enId));             //wipe english
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstAnal, sense.Hvo, sense.Definition.Flid, false, out wsId);
            Assert.AreEqual(wsId, ptId, "Did not pull from non current analysis language when all current languages were empty.");
        }
        public void GetMagicStringAlt_TestFirstVern()
        {
            IWritingSystem mluWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "mlu", false, false, out mluWs);
            var            mluId = mluWs.Handle;
            IWritingSystem senWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "sen", false, false, out senWs);
            var            senId = senWs.Handle;
            IWritingSystem sekWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "sek", false, false, out sekWs);
            var sekId = sekWs.Handle;

            Cache.LangProject.CurrentVernacularWritingSystems.Clear();
            Cache.LangProject.AddToCurrentVernacularWritingSystems(mluWs);
            Cache.LangProject.AddToCurrentVernacularWritingSystems(senWs);
            Cache.LangProject.VernacularWritingSystems.Add(sekWs);
            var entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create();

            entry.CitationForm.set_String(mluId, Cache.TsStrFactory.MakeString("To'abaita", mluId));
            entry.CitationForm.set_String(senId, Cache.TsStrFactory.MakeString("Sena", senId));
            entry.CitationForm.set_String(sekId, Cache.TsStrFactory.MakeString("Sekani", sekId));
            int wsId;

            //SUT magic gets first vernacular when there is one.
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstVern, entry.Hvo, entry.CitationForm.Flid, false, out wsId);
            Assert.AreEqual(wsId, mluId, "Did not pull first vernacular language first.");
            //SUT magic gets second vernacular when the first is empty
            entry.CitationForm.set_String(mluId, Cache.TsStrFactory.MakeString("", mluId));             //wipe Sena
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstVern, entry.Hvo, entry.CitationForm.Flid, false, out wsId);
            Assert.AreEqual(wsId, senId, "Did not pull second vernacular language when first was empty.");
            //SUT magic gets non current vernacular when all current vernacular languages are empty
            entry.CitationForm.set_String(senId, Cache.TsStrFactory.MakeString("", senId));             //wipe To'abaita
            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor,
                                                    WritingSystemServices.kwsFirstVernOrAnal, entry.Hvo, entry.CitationForm.Flid, false, out wsId);
            Assert.AreEqual(wsId, sekId, "Did not pull from non current vernacular language when all current languages were empty.");
        }
Example #6
0
        public void GetMagicStringAlt_TestVernInPara()
        {
            // set up project writing systems
            Cache.LangProject.CurrentVernacularWritingSystems.Clear();
            Cache.LangProject.CurrentAnalysisWritingSystems.Clear();
            CoreWritingSystemDefinition mluWs, senWs, engWs;

            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "mlu", false, true, out mluWs);
            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "sen", false, true, out senWs);
            WritingSystemServices.FindOrCreateWritingSystem(Cache, null, "en", true, false, out engWs);
            Cache.LangProject.AddToCurrentVernacularWritingSystems(mluWs);
            Cache.LangProject.AddToCurrentVernacularWritingSystems(senWs);
            Cache.LangProject.AddToCurrentAnalysisWritingSystems(engWs);
            var mluId = mluWs.Handle;
            var senId = senWs.Handle;
            var engId = engWs.Handle;

            // set up a paragraph that starts with Anal and ends with Vern
            var tssf = new TsStrFactory();
            var tssb = tssf.GetBldr();

            tssb.Append(tssf.MakeString("Analysis ", engId));
            tssb.Append(tssf.MakeString("Vernacular ", senId));
            tssb.Append(tssf.MakeString("Other Vernacular ", mluId));
            var paraBldr = Cache.ServiceLocator.GetInstance <StTxtParaBldr>();
            var stText   = Cache.ServiceLocator.GetInstance <IStTextFactory>().Create();

            Cache.ServiceLocator.GetInstance <ITextFactory>().Create().ContentsOA = stText;            // needed to put a Cache in stText
            var para = paraBldr.CreateParagraph(stText);

            para.Contents = tssb.GetString();

            // SUT
            int wsId;

            WritingSystemServices.GetMagicStringAlt(Cache, Cache.MainCacheAccessor, WritingSystemServices.kwsVernInParagraph, para.Hvo, 0, false, out wsId);
            Assert.AreEqual(senId, wsId, "The first vernacular WS in the para is 'sen'");
        }
Example #7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Get the best alternative in the order of preference requested. If none of the
        /// preferred writing systems are available, arbitrarily select one from among the
        /// available alternatives. This ensures that this will not return null unless no
        /// alternatives exist.
        /// </summary>
        /// <param name="wsActual">ws of the best found alternative</param>
        /// <param name="preferences">Writing systems to consider in order of preference (can be
        /// real writing system IDs or magic numbers.</param>
        /// ------------------------------------------------------------------------------------
        public ITsString GetBestAlternative(out int wsActual, params int[] preferences)
        {
            foreach (int ws in preferences)
            {
                ITsString tss;
                if (ws < 0)
                {
                    tss = WritingSystemServices.GetMagicStringAlt(m_object.Cache,
                                                                  ws, m_object.Hvo, m_flid, true, out wsActual);
                }
                else
                {
                    wsActual = ws;
                    tss      = StringOrNull(ws);
                }

                if (tss != null && tss.Length > 0)
                {
                    return(tss);
                }
            }
            wsActual = AvailableWritingSystemIds.FirstOrDefault();
            return(wsActual > 0 ? StringOrNull(wsActual) : null);
        }
Example #8
0
        private bool TryMultiStringAlt(ISilDataAccess sda, int hvo, int flid, out int wsActual)
        {
            ITsString tss = WritingSystemServices.GetMagicStringAlt(m_cache, m_ws, hvo, flid, true, out wsActual);

            return(tss != null);
        }