예제 #1
0
        private void GetQuestionData(string fact, string question, bool fromKahnAcademy, out ValueUnits data1, out ValueUnits data2, out ValueUnits questionValueUnit, out double data1Value, out double data2Value, out double questionValue)
        {
            FactData factData = FactData.Create(fact);

            data1             = ValueUnits.Create(factData.data1);
            data2             = ValueUnits.Create(factData.data2);
            questionValueUnit = ValueUnits.Create(question);
            data1Value        = GetDataValueFrom(data1.value, fromKahnAcademy);
            data2Value        = GetDataValueFrom(data2.value, fromKahnAcademy);
            questionValue     = GetDataValueFrom(questionValueUnit.value, fromKahnAcademy);
        }
예제 #2
0
        /// <summary>
        /// Creates a new FactData based on the specified input text.
        /// </summary>
        /// <param name="input">The input text to get a match for. For example, "Brenda can deliver 644 newspapers in 7 hours".</param>
        /// <returns>Returns the new FactData, or null if a no matches were found for the specified input.</returns>
        public static FactData Create(string input)
        {
            const string pattern = @"(?<data1>[+-]?((\d+(\.\d+)?))\s*\w+).*\s(?<data2>[+-]?((\d+(\.\d+)?))\s*\w+)";

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

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

            FactData factData = new FactData();

            factData.data1 = RegexHelper.GetValue <string>(matches, "data1");
            factData.data2 = RegexHelper.GetValue <string>(matches, "data2");
            return(factData);
        }