Пример #1
0
        private void Setup(int hvoPara)
        {
            int vernWs = StTxtPara.GetWsAtParaOffset(m_cache, hvoPara, 0);

            if (vernWs == m_vernWs)
            {
                return;                 // already setup.
            }
            m_vernWs = vernWs;
            string        sql = string.Format("select txt from WfiWordform_Form where ws={0}", vernWs);
            IOleDbCommand odc = DbOps.MakeRowSet(m_cache, sql, null);

            m_maxChars = 0;
            try
            {
                bool fMoreRows;
                odc.NextRow(out fMoreRows);
                while (fMoreRows)
                {
                    string word = DbOps.ReadString(odc, 0);
                    m_words.Add(word);
                    m_maxChars = Math.Max(m_maxChars, word.Length);
                    odc.NextRow(out fMoreRows);
                }
            }
            finally
            {
                DbOps.ShutdownODC(ref odc);
            }
        }
Пример #2
0
        /// <summary>
        /// Load the information about the domains of hvoEntry. Returns false
        /// if the entry has no associated domains or none of them are linked to any other entries.
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="hvoEntry"></param>
        /// <param name="domains"></param>
        /// <param name="cdaTemp"></param>
        /// <param name="fMoreRows"></param>
        /// <param name="owner"></param>
        /// <returns></returns>
        static private bool LoadDomainInfo(FdoCache cache, int hvoEntry, out int[] domainsOut, out IVwCacheDa cdaTemp, IWin32Window owner)
        {
            // This produces first the Semantic domains of the senses of the entry,
            // then restricts to those that occur on some other entry,
            // then looks up the vernacular (or, if none, analysis) name of the domains. The are sorted by
            // domain name.
            // We do left outer joins for the last two so we can distinguish the failure
            // modes "no SDs on senses of initial entry" versus "no other entries in those SDs"
            string sql1 = string.Format("select lssd2.dst, cn.txt, cn.ws from LexEntry le"
                                        + " join LexSense_ ls on ls.owner$ = le.id"
                                        + " join LexSense_SemanticDomains lssd on lssd.src = ls.id "
                                        + " left outer join LexSense_SemanticDomains lssd2 on lssd2.dst = lssd.dst"
                                        + " and exists (select * from CmObject lsother"
                                        + " join LexEntry leother on leother.id = lsother.owner$ and lsother.id = lssd2.src and leother.id != le.id)"
                                        + " left outer join CmPossibility_Name cn on lssd2.dst = cn.obj and cn.ws"
                                        + " in ({0}, {1}) where le.id = {2}"
                                        + " group by lssd2.dst, cn.txt, cn.ws"
                                        + " order by cn.txt", cache.DefaultVernWs, cache.DefaultAnalWs, hvoEntry);

            IOleDbCommand odc           = DbOps.MakeRowSet(cache, sql1, null);
            bool          fGotSrcDomain = false;    // true if we found a semantic domain on some sense of the source entry

            try
            {
                bool       fMoreRows;
                List <int> domains = new List <int>();
                cdaTemp = VwCacheDaClass.Create();
                for (odc.NextRow(out fMoreRows); fMoreRows; odc.NextRow(out fMoreRows))
                {
                    fGotSrcDomain = true;                     // any row indicates success here.
                    int hvoDomain = DbOps.ReadInt(odc, 0);
                    if (hvoDomain == 0)
                    {
                        continue;                         // null row, an SD that occurs on no other entry.
                    }
                    if (!((ISilDataAccess)cdaTemp).get_IsPropInCache(hvoDomain, RelatedWordsVc.ktagName,
                                                                     (int)CellarModuleDefns.kcptString, 0))
                    {
                        ITsString tss = DbOps.ReadTss2(odc, 1);
                        if (tss == null)
                        {
                            tss = FDO.Cellar.CmPossibility.BestAnalysisOrVernName(cache, hvoDomain);
                        }
                        cdaTemp.CacheStringProp(hvoDomain, RelatedWordsVc.ktagName,
                                                tss);
                        domains.Add(hvoDomain);
                    }
                }
                domainsOut = DbOps.ListToIntArray(domains);
            }
            finally
            {
                DbOps.ShutdownODC(ref odc);
            }
            return(fGotSrcDomain);
        }
Пример #3
0
        public virtual void Init(Mediator mediator, XmlNode configurationParameters)
        {
            CheckDisposed();

            m_mediator = mediator;
            m_configurationParameters = configurationParameters;
            m_mediator.AddColleague(this);

            FdoCache cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache");
            List <ILgWritingSystem> usedWses = new List <ILgWritingSystem>();

            using (new SuppressSubTasks(cache))
            {
                foreach (IReversalIndex rev in cache.LangProject.LexDbOA.ReversalIndexesOC)
                {
                    // This benign looking check of the count appears to do nothing,
                    // but it is very important as it ensures the vector is cached. Without it,
                    // crashes turn up in bulk deletion, as no PropChanged is sent,
                    // as the vector is not in the cache.
                    int entryCount = 0;
                    entryCount = rev.EntriesOC.Count;
                    usedWses.Add(rev.WritingSystemRA);
                    if (rev.PartsOfSpeechOA == null)
                    {
                        (rev as ReversalIndex).InitNewInternal();
                    }
                    if (rev.PartsOfSpeechOA.ItemClsid != PartOfSpeech.kClassId)
                    {
                        rev.PartsOfSpeechOA.ItemClsid = PartOfSpeech.kClassId;
                    }
                }
                List <IReversalIndex> corruptReversalIndices = new List <IReversalIndex>();
                foreach (IReversalIndex rev in cache.LangProject.LexDbOA.ReversalIndexesOC)
                {
                    // Make sure each index has a name, if it is available from the writing system.
                    if (rev.WritingSystemRA == null)
                    {
                        // Delete a bogus ReversalIndex that has no writing system.
                        // But, for now only store them for later deletion,
                        // as immediate removal will wreck the looping.
                        corruptReversalIndices.Add(rev);
                        continue;
                    }
                    ILgWritingSystem revWs = rev.WritingSystemRA;
                    string           sql   = string.Format("SELECT Ws, Txt FROM LgWritingSystem_Name WHERE Obj = {0}", revWs.Hvo);
                    IOleDbCommand    odc   = DbOps.MakeRowSet(cache, sql, null);
                    try
                    {
                        bool fMoreRows;
                        odc.NextRow(out fMoreRows);
                        while (fMoreRows)
                        {
                            int    wsHvo   = DbOps.ReadInt(odc, 0);
                            string nameWs  = DbOps.ReadString(odc, 1);
                            string nameRev = rev.Name.GetAlternative(wsHvo);
                            if ((nameRev == null || nameRev == String.Empty) &&
                                (nameWs != null && nameWs.Length > 0))
                            {
                                rev.Name.SetAlternative(nameWs, wsHvo);
                            }
                            odc.NextRow(out fMoreRows);
                        }
                    }
                    finally
                    {
                        DbOps.ShutdownODC(ref odc);
                    }
                }
                // Delete any corrupt reversal indices.
                foreach (IReversalIndex rev in corruptReversalIndices)
                {
                    rev.DeleteUnderlyingObject();
                }
            }
            // Set up for the reversal index combo box or dropdown menu.
            int        firstId     = 0;
            List <int> reversalIds = cache.LangProject.LexDbOA.CurrentReversalIndices;

            if (reversalIds.Count > 0)
            {
                firstId = reversalIds[0];
            }
            else if (cache.LangProject.LexDbOA.ReversalIndexesOC.Count > 0)
            {
                firstId = cache.LangProject.LexDbOA.ReversalIndexesOC.HvoArray[0];
            }
            if (firstId > 0)
            {
                SetReversalIndexHvo(firstId);
            }
        }
Пример #4
0
        private void SetupLexRelsForEntry(int[] lexrels)
        {
            m_cdaTemp.CacheVecProp(m_hvoEntry, RelatedWordsVc.ktagLexRels,
                                   lexrels, lexrels.Length);
            // This query does not find subsenses.
            string sSql = String.Format(
                "SELECT tar.Src, tar.Dst, tar.Ord, tar2.Ord, lrt.MappingType, cf.Txt, mff.Txt, le.HomographNumber"
                + " FROM LexRefType lrt"
                + " JOIN LexRefType_Members mem ON mem.Src=lrt.Id"
                + " JOIN LexReference_Targets tar ON tar.Src=mem.Dst"
                + " JOIN LexReference_Targets tar2 ON tar2.Src=tar.Src AND (tar2.Dst={0} OR tar2.Dst IN (SELECT Dst FROM LexEntry_Senses WHERE Src={0}))"
                + " JOIN CmObject co ON co.Id=tar.Dst AND co.Id != {0} AND co.Id NOT IN (SELECT Dst FROM LexEntry_Senses WHERE Src={0})"
                + " JOIN LexEntry le ON le.Id IN (co.Id, co.Owner$)"
                + " LEFT OUTER JOIN LexEntry_CitationForm cf ON cf.Obj=le.Id"
                + " LEFT OUTER JOIN MoForm_ mf ON mf.Owner$=le.Id AND mf.OwnFlid$={1}"
                + " LEFT OUTER JOIN MoForm_Form mff ON mff.Obj=mf.Id AND mff.Ws={2}"
                + " ORDER BY tar.Src, tar.Ord",
                m_hvoEntry, (int)LexEntry.LexEntryTags.kflidLexemeForm, m_cache.DefaultVernWs);
            IOleDbCommand odc = DbOps.MakeRowSet(m_cache, sSql, null);

            try
            {
                bool       fMoreRows;
                int        hvoOldLexRef = 0;           // to trigger change of lexical relation on first iteration
                List <int> refs         = new List <int>();
                for (odc.NextRow(out fMoreRows); fMoreRows; odc.NextRow(out fMoreRows))
                {
                    int hvoLexRef = DbOps.ReadInt(odc, 0);
                    if (hvoLexRef != hvoOldLexRef)
                    {
                        if (hvoOldLexRef != 0)
                        {
                            m_cdaTemp.CacheVecProp(hvoOldLexRef, RelatedWordsVc.ktagWords,
                                                   refs.ToArray(), refs.Count);
                            refs.Clear();
                        }
                        hvoOldLexRef = hvoLexRef;
                    }
                    int hvoRef = DbOps.ReadInt(odc, 1);
                    if (refs.Contains(hvoRef))
                    {
                        continue;
                    }
                    refs.Add(hvoRef);
                    int ordRef   = DbOps.ReadInt(odc, 2);
                    int ordEntry = DbOps.ReadInt(odc, 3);
                    int type     = DbOps.ReadInt(odc, 4);
                    if (type == (int)LexRefType.MappingTypes.kmtEntryOrSenseTree ||
                        type == (int)LexRefType.MappingTypes.kmtEntryTree ||
                        type == (int)LexRefType.MappingTypes.kmtSenseTree)
                    {
                        if (ordRef != 0 && ordEntry != 0)
                        {
                            continue;                                           // one of them has to be the root of the tree!
                        }
                    }
                    if (type == (int)LexRefType.MappingTypes.kmtEntryOrSenseSequence ||
                        type == (int)LexRefType.MappingTypes.kmtEntrySequence ||
                        type == (int)LexRefType.MappingTypes.kmtSenseSequence)
                    {
                        // Do we need to include the word itself in a sequence type relation for
                        // this dialog?
                    }
                    ITsString tss = DbOps.ReadTss(odc, 5, m_cache.DefaultVernWs);
                    if (tss == null || tss.Length == 0)
                    {
                        tss = DbOps.ReadTss(odc, 6, m_cache.DefaultVernWs);
                    }
                    if (tss == null || tss.Length == 0)
                    {
                        continue;
                    }
                    int homograph = DbOps.ReadInt(odc, 7);
                    if (homograph > 0)
                    {
                        ITsIncStrBldr tisb = tss.GetIncBldr();
                        tisb.SetIntPropValues((int)FwTextPropType.ktptSuperscript,
                                              (int)FwTextPropVar.ktpvEnum, (int)FwSuperscriptVal.kssvSub);
                        tisb.SetIntPropValues((int)FwTextPropType.ktptBold,
                                              (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn);
                        tisb.SetIntPropValues((int)FwTextPropType.ktptWs,
                                              (int)FwTextPropVar.ktpvDefault, m_cache.DefaultUserWs);
                        tisb.Append(homograph.ToString());
                        tss = tisb.GetString();
                    }
                    m_cdaTemp.CacheStringProp(hvoRef, RelatedWordsVc.ktagName, tss);
                }
                if (hvoOldLexRef != 0)
                {
                    m_cdaTemp.CacheVecProp(hvoOldLexRef, RelatedWordsVc.ktagWords,
                                           refs.ToArray(), refs.Count);
                    refs.Clear();
                }
            }
            finally
            {
                DbOps.ShutdownODC(ref odc);
            }
        }
Пример #5
0
        void SetupDomainsForEntry(int[] domains)
        {
            m_cdaTemp.CacheVecProp(m_hvoEntry, RelatedWordsVc.ktagDomains,
                                   domains, domains.Length);

            // This produces first the Semantic domains of the senses of the entry,
            // then uses a backreference to find all senses linked to those domains.
            // Todo JohnT: this finds only entries that directly own senses linked to the relevant domains.
            // It will not find entries that only have senses with subsenses in the domain.
            // This is because we're specifically looking for MoForms with the same owner as the senses we found.
            // We'd have to do something tricky and recursive to get owning entry of a subsense.
            string sql2 = string.Format("select lscd.dst, cmls.owner$, mff.txt from LexSense ls"
                                        + " join CmObject cols on ls.id = cols.id and cols.owner$ = {0}"
                                        + " join LexSense_SemanticDomains lscd on lscd.src = ls.id"
                                        + " join LexSense_SemanticDomains lscd2 on lscd2.dst = lscd.dst and lscd2.src != ls.id"
                                        + " join CmObject cmls on lscd2.src = cmls.id and cmls.owner$ != {0}"
                                        + " join MoForm_ mf on mf.owner$ = cmls.owner$ and mf.OwnFlid$ = {1}"
                                        + " join MoForm_Form mff on mff.obj = mf.id and mff.ws = {2}"
                                        + " group by lscd.dst, cmls.owner$, mff.txt"
                                        + " order by lscd.dst, mff.txt",
                                        m_hvoEntry, (int)LexEntry.LexEntryTags.kflidLexemeForm, m_cache.DefaultVernWs);

            IOleDbCommand odc = DbOps.MakeRowSet(m_cache, sql2, null);

            try
            {
                bool       fMoreRows;
                List <int> words        = new List <int>();
                int        hvoOldDomain = 0;           // to trigger change of domain on first iteration
                for (odc.NextRow(out fMoreRows); fMoreRows; odc.NextRow(out fMoreRows))
                {
                    int hvoNewDomain = DbOps.ReadInt(odc, 0);
                    if (hvoNewDomain != hvoOldDomain)
                    {
                        if (hvoOldDomain != 0)
                        {
                            m_cdaTemp.CacheVecProp(hvoOldDomain, RelatedWordsVc.ktagWords,
                                                   DbOps.ListToIntArray(words), words.Count);
                            words.Clear();
                        }
                        hvoOldDomain = hvoNewDomain;
                    }
                    int hvoWord = DbOps.ReadInt(odc, 1);
                    // JohnT: if I was better at sql, I could no doubt figure out how to prevent
                    // duplicates in the query above, which are caused by having two or more senses of the
                    // same entry in the same domain. But it's easier to just eliminate them here (and maybe
                    // even faster).
                    if (!words.Contains(hvoWord))
                    {
                        m_cdaTemp.CacheStringProp(hvoWord, RelatedWordsVc.ktagName,
                                                  DbOps.ReadTss(odc, 2, m_cache.DefaultVernWs));
                        words.Add(hvoWord);
                    }
                }
                if (hvoOldDomain != 0)
                {
                    // Cache words of last domain.
                    m_cdaTemp.CacheVecProp(hvoOldDomain, RelatedWordsVc.ktagWords,
                                           DbOps.ListToIntArray(words), words.Count);
                }
                int hvoLf = m_cache.MainCacheAccessor.get_ObjectProp(m_hvoEntry, (int)LexEntry.LexEntryTags.kflidLexemeForm);
                if (hvoLf != 0)
                {
                    ITsString tssCf = m_cache.MainCacheAccessor.get_MultiStringAlt(hvoLf,
                                                                                   (int)MoForm.MoFormTags.kflidForm, m_cache.DefaultVernWs);
                    m_cdaTemp.CacheStringProp(m_hvoEntry, RelatedWordsVc.ktagCf, tssCf);
                }
            }
            finally
            {
                DbOps.ShutdownODC(ref odc);
            }
        }
Пример #6
0
        /// <summary>
        /// Load the information about the lexical relations that link to hvoEntry.
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="hvoEntry"></param>
        /// <param name="relsOut"></param>
        /// <param name="cdaTemp"></param>
        /// <param name="owner"></param>
        /// <returns>false if the entry has no associated lexical relations, or none of them are linked to any other entries.</returns>
        static private bool LoadLexicalRelationInfo(FdoCache cache, int hvoEntry, out int[] relsOut,
                                                    IVwCacheDa cdaTemp, IWin32Window owner)
        {
            string sql1 = string.Format("SELECT DISTINCT tar2.Src, lrt.MappingType, tar.Ord, cn.Txt, cn.Ws, rev.Txt, rev.Ws"
                                        + " FROM LexReference_Targets tar"
                                        + " LEFT OUTER JOIN LexReference_Targets tar2 ON tar2.Src=tar.Src AND EXISTS (SELECT * FROM CmObject other WHERE other.Id=tar2.Dst AND other.Id != tar.Dst)"
                                        + " LEFT OUTER JOIN LexRefType_Members mem ON mem.Dst=tar2.Src"
                                        + " LEFT OUTER JOIN LexRefType lrt ON lrt.Id=mem.Src"
                                        + " LEFT OUTER JOIN CmPossibility_Name cn ON cn.Obj=mem.Src AND cn.Ws IN ({0}, {1})"
                                        + " LEFT OUTER JOIN LexRefType_ReverseName rev ON rev.Obj=mem.Src AND rev.Ws IN ({0}, {1})"
                                        + " WHERE tar.Dst = {2} OR tar.Dst IN (SELECT Id FROM fnGetOwnedIds({2}, {3}, {4}))",
                                        cache.DefaultVernWs, cache.DefaultAnalWs, hvoEntry,
                                        (int)LexEntry.LexEntryTags.kflidSenses, (int)LexSense.LexSenseTags.kflidSenses);

            IOleDbCommand odc        = DbOps.MakeRowSet(cache, sql1, null);
            bool          fGotLexRef = false;    // true if we found a lexical relation for the entry or one of its senses

            try
            {
                bool       fMoreRows;
                List <int> rels = new List <int>();
                for (odc.NextRow(out fMoreRows); fMoreRows; odc.NextRow(out fMoreRows))
                {
                    fGotLexRef = true;
                    int hvoLexRef = DbOps.ReadInt(odc, 0);
                    if (hvoLexRef == 0)
                    {
                        continue;                               // null row.
                    }
                    if (!((ISilDataAccess)cdaTemp).get_IsPropInCache(hvoLexRef, RelatedWordsVc.ktagName,
                                                                     (int)CellarModuleDefns.kcptString, 0))
                    {
                        int       type       = DbOps.ReadInt(odc, 1);
                        int       ord        = DbOps.ReadInt(odc, 2);
                        ITsString tssName    = DbOps.ReadTss2(odc, 3);
                        ITsString tssRevName = DbOps.ReadTss2(odc, 5);
                        if (type == (int)LexRefType.MappingTypes.kmtEntryAsymmetricPair ||
                            type == (int)LexRefType.MappingTypes.kmtEntryOrSenseAsymmetricPair ||
                            type == (int)LexRefType.MappingTypes.kmtSenseAsymmetricPair)
                        {
                            if (ord != 0 && tssRevName != null && tssRevName.Length > 0)
                            {
                                tssName = tssRevName;
                            }
                        }
                        else if (type == (int)LexRefType.MappingTypes.kmtEntryTree ||
                                 type == (int)LexRefType.MappingTypes.kmtEntryOrSenseTree ||
                                 type == (int)LexRefType.MappingTypes.kmtSenseTree)
                        {
                            if (ord != 0 && tssRevName != null && tssRevName.Length > 0)
                            {
                                tssName = tssRevName;
                            }
                        }
                        cdaTemp.CacheStringProp(hvoLexRef, RelatedWordsVc.ktagName, tssName);
                        rels.Add(hvoLexRef);
                    }
                }
                relsOut = DbOps.ListToIntArray(rels);
            }
            finally
            {
                DbOps.ShutdownODC(ref odc);
            }
            return(fGotLexRef);
        }
Пример #7
0
        private CurrentContext WriteFieldStartTag(int flid)
        {
            CurrentContext ccOld = m_cc;
            string         sXml;

            try
            {
                int cpt = m_cache.MetaDataCacheAccessor.GetFieldType((uint)flid);
                switch (cpt)
                {
                case (int)CellarModuleDefns.kcptReferenceAtom:
                case (int)CellarModuleDefns.kcptReferenceCollection:
                case (int)CellarModuleDefns.kcptReferenceSequence:
                    m_cc = CurrentContext.insideLink;
                    break;

                default:
                    m_cc = CurrentContext.insideProperty;
                    break;
                }
                string sField = m_cache.MetaDataCacheAccessor.GetFieldName((uint)flid);
                sXml = GetFieldXmlElementName(sField, (uint)flid / 1000);
                if (sXml == "_" + sField && ccOld == CurrentContext.insideLink && m_cc == CurrentContext.insideProperty)
                {
                    AddMissingObjectLink();
                    sXml = GetFieldXmlElementName(sField, (uint)flid / 1000);
                }
                IndentLine();
                string sUserLabel = null;
                if (sField.StartsWith("custom"))
                {
                    if (!m_dictCustomUserLabels.TryGetValue(flid, out sUserLabel))
                    {
                        IOleDbCommand odc = null;
                        try
                        {
                            odc = DbOps.MakeRowSet(m_cache,
                                                   String.Format("SELECT UserLabel FROM Field$ WHERE Id={0}", flid), null);
                            bool fMoreRows;
                            odc.NextRow(out fMoreRows);
                            if (fMoreRows)
                            {
                                sUserLabel = XmlUtils.MakeSafeXmlAttribute(DbOps.ReadString(odc, 0));
                            }
                        }
                        finally
                        {
                            if (odc != null)
                            {
                                DbOps.ShutdownODC(ref odc);
                            }
                        }
                        m_dictCustomUserLabels.Add(flid, sUserLabel);
                    }
                }
                if (String.IsNullOrEmpty(sUserLabel))
                {
                    m_writer.WriteLine("<{0}>", sXml);
                }
                else
                {
                    m_writer.WriteLine("<{0} userlabel=\"{1}\">", sXml, sUserLabel);
                }
            }
            catch
            {
                sXml = String.Empty;
            }
            m_rgElementTags.Add(sXml);

            return(ccOld);
        }