/// <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); }
/// <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> /// Gets the lexicon items from cached terms or failed queris /// </summary> /// <param name="termForm">The term form.</param> /// <returns></returns> public lexiconResponse getLexiconItems(string termForm, ILogBuilder loger = null) { lexiconResponse output = new lexiconResponse(); string termFormLat = termForm; if (semanticLexiconManager.manager.settings.doQueryPreprocess) { termForm = termForm.ToLower().Trim(); // termFormLat = termForm.transliterate(transliterateFlag.cyrilicToLatin); } termForm = termFormLat; output.setType(lexiconResponse.responseType.none); if (failed.ContainsKey(termForm)) { output = failed[termForm]; output.setType(lexiconResponse.responseType.failedQueries); } else if (lemmas.ContainsKey(termForm)) { output.AddRange(lemmas[termForm]); output.setType(lexiconResponse.responseType.cachedLexicon); } else if (instances.ContainsKey(termForm)) { output.AddRange(instances[termForm]); output.setType(lexiconResponse.responseType.cachedLexicon); } else { List <string> termForms = new List <string>(); termForms.Add(termForm); translationTextTableEntryEnum entry = twins.checkForEntry(termForm); switch (entry) { case translationTextTableEntryEnum.keyEntry: case translationTextTableEntryEnum.valueEntry: termForms.Add(twins.GetWord(termForm, out entry)); break; case translationTextTableEntryEnum.unknownEntry: if (termForm.isNonDosChars()) { termForms.Add(twins.GetWord(termForm, out entry)); } break; } if (doAllowLexiconQuery && !isLexiconPreloaded) { output.setType(lexiconResponse.responseType.askingLexiconContext); output = _getLexiconItems(termForms, loger); } if (output.Any()) { output.setType(lexiconResponse.responseType.lexicon); Add(output); } else { output = AddTemp(termForms, loger); output.setType(lexiconResponse.responseType.failedQueries); } } //} catch (Exception ex) //{ // aceGeneralException axe = new aceGeneralException("semanticLexiconCache.getLexiconItems error", ex, this, "lexCache.getLexiconItems() current state: " + output.type); // throw axe; //} return(output); }