public void InitializeFuncStatsTable()
 {
     this.FunctionsStats = new FunctionStats[functionList.FunctionsList.Count];
     for (int i = 0; i < FunctionsStats.Length; i++)
     {
         FunctionsStats[i] = new FunctionStats(i);
         FunctionsStats[i].requiredWords = functionList.FunctionsList[i].FirstClassWords.ToList();
     }
 }
        public string SelectFunction(string[] words, string originalText)
        {
            InitializeFuncStatsTable();


            foreach (string word in words)
            {
                IEnumerable <string> matches = from n in functionList.wordsTable.Keys
                                               where Regex.IsMatch(word, "^" + n + "$")
                                               select n;
                if (matches.Count() > 0)
                {
                    foreach (string wordmatched in matches)
                    {
                        this.UpdateStats(functionList.wordsTable[wordmatched], wordmatched, word);
                    }
                }
            }


            //get statisfied functions;
            IEnumerable <FunctionStats> Appropriatefunctions = from n in FunctionsStats
                                                               where n.requiredWords.Count == 0
                                                               orderby n.Score
                                                               select n;

            if (Appropriatefunctions.Count() < 1)
            {
                throw new Exception("no function to select");
            }



            Appropriatefunctions = Appropriatefunctions.Reverse();
            int           max = Appropriatefunctions.ElementAt(0).Score;
            FunctionStats rightFunctionStats = Appropriatefunctions.ElementAt(0);
            int           i = 0;

            while ((rightFunctionStats = Appropriatefunctions.ElementAt(i)).Score == max)
            {
                string[]             keywords      = rightFunctionStats.words.ToArray();
                int                  functionIndex = rightFunctionStats.functionIndex;
                Funct                function      = functionList.FunctionsList[functionIndex];
                IEnumerable <string> data          = from n in words
                                                     where !keywords.Contains(n)
                                                     select n;
                try
                {
                    string resultat = function.executeFunction(keywords, data.ToArray(), originalText, words);
                    return(resultat);
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    i++;
                }
            }
            throw new Exception("no function can be executed");
        }
 public void InitializeFuncStatsTable()
 {
     this.FunctionsStats = new FunctionStats[functionList.FunctionsList.Count];
     for (int i = 0; i < FunctionsStats.Length; i++)
     {
         FunctionsStats[i] = new FunctionStats(i);
         FunctionsStats[i].requiredWords = functionList.FunctionsList[i].FirstClassWords.ToList();
     }
 }