/// <summary>
        /// Creates a new FactQuestion based on the specified input text.
        /// </summary>
        /// <param name="input">The input text to get a match for. For example, "blah blah blah. what what what?".</param>
        /// <returns>Returns the new FactQuestion, or null if a no matches were found for the specified input.</returns>
        public static FactQuestion Create(string input)
        {
            const string pattern = @"^(?<Fact>.*)\.\s+(?<Question>.*)\?";

            Regex           regex   = new Regex(pattern);
            MatchCollection matches = regex.Matches(input);

            if (matches.Count == 0)
            {
                return(null);
            }

            FactQuestion factQuestion = new FactQuestion();

            factQuestion.Fact     = RegexHelper.GetValue <string>(matches, "Fact");
            factQuestion.Question = RegexHelper.GetValue <string>(matches, "Question");
            return(factQuestion);
        }
Beispiel #2
0
        private void btnPaste_Click(object sender, RoutedEventArgs e)
        {
            if (Clipboard.ContainsText(TextDataFormat.Html))
            {
                string htmlText = Clipboard.GetText(TextDataFormat.Html);
                //System.Xml.Linq.XDocument xDocument = System.Xml.Linq.XDocument.Load(GenerateStreamFromString(htmlText));
            }

            string       text         = Clipboard.GetText();
            FactQuestion factQuestion = FactQuestion.Create(text);


            QuestionData questionData = QuestionData.Create(factQuestion.Question);

            ValueUnits data1, data2, question;
            double     data1Value, data2Value, questionValue;

            try
            {
                GetQuestionData(factQuestion.Fact, questionData.question, true, out data1, out data2, out question, out data1Value, out data2Value, out questionValue);
            }
            catch (Exception ex)
            {
                ShowError(ex);
                return;
            }
            NoErrors();
            changingInternally = true;
            try
            {
                tbxQuestion.Text = factQuestion.Question.Replace(question.value, questionValue.ToString()) + '?';
                tbxFact.Text     = factQuestion.Fact.Replace(data1.value, data1Value.ToString()).Replace(data2.value, data2Value.ToString()) + '.';
            }
            finally
            {
                changingInternally = false;
            }

            AnswerQuestion();
        }