Exemplo n.º 1
0
        /// <summary>
        /// Gets the lexicon items.
        /// </summary>
        /// <param name="termForm">The term form.</param>
        /// <param name="loger">The loger.</param>
        /// <returns></returns>
        private lexiconResponse _getLexiconItems(List <string> termForms, ILogBuilder loger = null, bool callWithAutoDiscovery = true)
        {
            lexiconResponse output = new lexiconResponse();

            //lock (getLexiconItemsLock)
            //{


            output.setType(lexiconResponse.responseType.lexicon);

            ILexiconItem tis_i = null;

            try
            {
                //var tis_is = lexiconContext.TermInstances.Where(x => x.Equals(termForm)); // x=>x.name == termForm
                var tis_is = lexiconContext.TermInstances.Where(x => termForms.Contains(x.name)).FirstOrDefault();     //
                if (tis_is != null)
                {
                    output.Add(tis_is);
                }
            }
            catch (Exception ex)
            {
                if (loger != null)
                {
                    loger.log("Lexicon query failed: " + termForms.toCsvInLine(",") + " (lemmas)");
                }
            }

            if (tis_i == null)
            {
                try
                {
                    var til_is = lexiconContext.TermLemmas.Where(x => termForms.Contains(x.name)).FirstOrDefault();     // var til_is = lexiconContext.TermLemmas.Where(x => x.Equals(termForm));

                    if (til_is != null)
                    {
                        output.Add(til_is);
                    }
                }
                catch (Exception ex)
                {
                    if (loger != null)
                    {
                        loger.log("Lexicon query failed: " + termForms.toCsvInLine(",") + " (instances)");
                    }
                }
            }
            //}

            return(output);
        }
        /// <summary>
        /// Adds the temporary term definition and performs save once enough temp terms were aded
        /// </summary>
        /// <param name="terms">The terms.</param>
        /// <param name="loger">The loger.</param>
        /// <param name="insert">if set to <c>true</c> [insert].</param>
        /// <returns></returns>
        public lexiconResponse AddTemp(IEnumerable <string> terms, ILogBuilder loger = null, bool insert = true, bool isFirstLoad = false)
        {
            lexiconResponse output = new lexiconResponse();

            output.setType(lexiconResponse.responseType.failedQueries);

            if (insert)
            {
                foreach (string term in terms)
                {
                    var tmp = makeTempLemma(term);
                    output.Add(tmp);
                    failed.Add(term, tmp);
                    if (!isFirstLoad)
                    {
                        failedQueries.AppendUnique(terms);
                    }
                    addTempToSave += 1;
                }
            }

            if (addTempToSave > ADDTEMPTOSAVE)
            {
                addTempToSave = 0;
                if (!isFirstLoad)
                {
                    SaveCacheFiles();
                }
            }

            return(output);
        }