protected void GetRules(string prefixText) { Dawg <string> Dawg; var PrefixText = DictionaryHelper.RemoveStressMarks(prefixText).ToLowerInvariant().Reverse(); var fileBasedDictionary = new FileBasedDictionary(Context.Server); try { using (Stream ReverseDict = fileBasedDictionary.OpenReverseIndex()) { Dawg = Dawg <string> .Load(ReverseDict, Func => { string s = Func.ReadString(); return(s == String.Empty ? null : s); }); } int PrefixLen = Dawg.GetLongestCommonPrefixLength(PrefixText); WriteJSONToResponse(Dawg.MatchPrefix(PrefixText.Take(PrefixLen)) .GroupBy(kvp => kvp.Value, kvp => kvp) .SelectMany(g => g.Take(1)) .Select(kvp => kvp.Value + DictionaryHelper.RuleLineDelimiter + new string(kvp.Key.Reverse().ToArray())) .Take(10) .ToArray()); } catch (Exception e) { WriteJSONToResponse(new [] { "Доступ к словарю в данный момент отсутствует. Возможно происходит построение индексов." }); Email.SendAdminEmail("GetRules", e.ToString()); } }
protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { string NewLine = DictionaryHelper.RemoveStressMarks(lemma.Text) + " " + selectedRule.Text; int StressPos; string messageText; string messageStyle; if (String.IsNullOrEmpty(lemma.Text)) { messageText = "Введите слово."; messageStyle = "messageError"; } else if (!DictionaryHelper.CheckStressPosition(lemma.Text)) { messageText = "Укажите ударение. Например: приве*т."; messageStyle = "messageError"; } else if (!int.TryParse(selectedRule.Text.Substring(0, selectedRule.Text.IndexOfAny(" ,.".ToCharArray())), out StressPos) || StressPos > DictionaryHelper.RemoveStressMarks(lemma.Text).Length) { messageText = "Позиция ударения в правиле превышает длину слова."; messageStyle = "messageError"; } else { messageText = "Статья \"" + NewLine + "\" добавлена в словарь."; messageStyle = "messageSuccess"; lemma.Text = String.Empty; selectedRule.Text = String.Empty; var fileBasedDictionary = new FileBasedDictionary(Server); fileBasedDictionary.AddEntry(NewLine); if (!Debugger.IsAttached) { var mailinglist = "*****@*****.**"; new SmtpClient().Send(new MailMessage("*****@*****.**", mailinglist, "Новая статья: " + NewLine, string.Join(Environment.NewLine, FormGenerator.GetAccentedFormsWithCorrectCase(NewLine, delegate { }) .Select(wordForm => wordForm.AccentedForm)))); } } message.Text = messageText; messageContainer.CssClass = "divMessage " + messageStyle; } }
protected void GetLineForms(string lemma, string rule) { int StressPos = lemma.Trim().IndexOf(DictionaryHelper.StressMark); string GramInfo = rule.Substring(0, rule.IndexOf(DictionaryHelper.RuleLineDelimiter)); string Line = DictionaryHelper.RemoveStressMarks(lemma) + " " + (StressPos == -1 ? "?" : StressPos.ToString()) + GramInfo.Substring(GramInfo.IndexOf(' ')); WriteJSONToResponse(new LineForms { Line = Line, Forms = GetFormsByRule(Line) }); }
public string [] GetCompletionList(string prefixText, int count) { var fileBasedDictionary = new FileBasedDictionary(Server); try { using (Stream ForwardDict = fileBasedDictionary.OpenForwardIndex()) { var dict = DawgSharp.Dawg <bool> .Load(ForwardDict, r => r.ReadBoolean()); return(dict.MatchPrefix(DictionaryHelper.RemoveStressMarks(prefixText).ToLowerInvariant()).Take(10).Select(kvp => kvp.Key).ToArray()); } } catch (Exception exception) { Email.SendAdminEmail("GetCompletionList", exception.ToString()); return(new [] { "Доступ к словарю в данный момент отсутствует. Возможно происходит построение индексов." }); } }