Exemplo n.º 1
0
        private static bool UnitsMatch(ValueUnits data1, ValueUnits data2)
        {
            string unit1 = data1.units.ToLower().TrimEnd('s');
            string unit2 = data2.units.ToLower().TrimEnd('s');

            return(unit1 == unit2);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new ValueUnits based on the specified input text.
        /// </summary>
        /// <param name="input">The input text to get a match for. For example, "9 hours".</param>
        /// <returns>Returns the new ValueUnits, or null if a no matches were found for the specified input.</returns>
        public static ValueUnits Create(string input)
        {
            const string pattern = @"(?<value>[+-]?((\d+(\.\d+)?)))\s*(?<units>\w+)";

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

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

            ValueUnits valueUnits = new ValueUnits();

            valueUnits.value = RegexHelper.GetValue <string>(matches, "value");
            valueUnits.units = RegexHelper.GetValue <string>(matches, "units");
            return(valueUnits);
        }