Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
        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)
            });
        }
Exemplo n.º 3
0
        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 [] { "Доступ к словарю в данный момент отсутствует. Возможно происходит построение индексов." });
            }
        }