public StringWordContextDescription getStringWordContextBeforeIndex(string sentence, int endIndex)
        {
            StringWordContextDescription contextDescription = new StringWordContextDescription();

            contextDescription.sentence = sentence;
            contextDescription.tail     = --endIndex;
            contextDescription.head     = endIndex;
            contextDescription.context  = "";

            for (int i = endIndex; i >= 0; i--)
            {
                char c = sentence.ElementAt(i);
                if (!isNumber(c) && c != '.' && c != '-')
                {
                    break; // terminal character reached
                }

                contextDescription.head = i;
            }

            try
            {
                contextDescription.context = contextDescription.sentence.Substring(contextDescription.head, contextDescription.tail - contextDescription.head + 1);
            }
            catch (System.ArgumentOutOfRangeException e)
            {
                contextDescription.context = "ERROR";
            }

            return(contextDescription);
        }
        public StringWordContextDescription getStringWordContextAfterIndex(string sentence, int startIndex)
        {
            StringWordContextDescription contextDescription = new StringWordContextDescription();

            contextDescription.sentence = sentence;
            contextDescription.tail     = ++startIndex;
            contextDescription.head     = startIndex;
            contextDescription.context  = ":";

            for (int i = startIndex; i < sentence.Length; i++)
            {
                char c = sentence.ElementAt(i);
                if (!isNumber(c) && c != '.' && c != '-')
                {
                    break; // terminal character reached
                }

                contextDescription.tail = i;
            }

            try
            {
                contextDescription.context = contextDescription.sentence.Substring(contextDescription.head, contextDescription.tail - contextDescription.head + 1);
            }
            catch (System.ArgumentOutOfRangeException e)
            {
                contextDescription.context = "ERROR";
            }

            return(contextDescription);
        }
        public string solvePercentages(string contextProblem)
        {
            while (contextProblem.Contains("%"))
            {
                System.Diagnostics.Debug.WriteLine("Solving Percentages for : " + contextProblem);

                StringWordContextDescription contextDescription = getStringWordContextBeforeIndex(contextProblem, contextProblem.IndexOf('%'));
                contextProblem = replaceSubString(contextProblem, percent(contextDescription.context), contextDescription.head, contextDescription.tail + 1);
            }

            return(contextProblem);
        }
        public string solveMultiplications(string contextProblem)
        {
            while (contextProblem.Contains("*"))
            {
                System.Diagnostics.Debug.WriteLine("Solving Multiplication for : " + contextProblem);

                StringWordContextDescription contextDescriptionA = getStringWordContextBeforeIndex(contextProblem, contextProblem.IndexOf('*') - 1);
                StringWordContextDescription contextDescriptionB = getStringWordContextAfterIndex(contextProblem, contextProblem.IndexOf('*') + 1);

                contextProblem = replaceSubString(contextProblem, mul(contextDescriptionA.context, contextDescriptionB.context), contextDescriptionA.head, contextDescriptionB.tail);
            }

            return(contextProblem);
        }
        public string solveSubtractions(string contextProblem)
        {
            while (contextProblem.Contains("—"))
            {
                System.Diagnostics.Debug.WriteLine("Solving Subtractions for : " + contextProblem);

                StringWordContextDescription contextDescriptionA = getStringWordContextBeforeIndex(contextProblem, contextProblem.IndexOf('—') - 1);
                StringWordContextDescription contextDescriptionB = getStringWordContextAfterIndex(contextProblem, contextProblem.IndexOf('—') + 1);

                contextProblem = replaceSubString(contextProblem, sub(contextDescriptionA.context, contextDescriptionB.context), contextDescriptionA.head, contextDescriptionB.tail);
            }

            //return mul(contextDescriptionA.context, contextDescriptionA.context) + contextDescriptionA.head.ToString() + ":" + contextDescriptionA.tail.ToString() + " vs " + contextDescriptionB.head.ToString() + ":" + contextDescriptionB.tail.ToString();
            return(contextProblem);
        }