ACAT.Extensions.Default.WordPredictors.PresageWCF.PresageWordPredictor.predict C# (CSharp) Method

predict() private method

Returns a list of next word predictions based on the context from the previous words in the sentence. The number of words returned is set by the PredictionWordCount property
private predict ( String prevWords, String currentWord, bool &success ) : IEnumerable
prevWords String Previous words in the sentence
currentWord String current word (may be partially spelt out
success bool true if the function was successsful
return IEnumerable
        private IEnumerable<String> predict(String prevWords, String currentWord, ref bool success)
        {
            // update the internal buffer with prevWords + currentWord
            _inputText = prevWords + " " + currentWord;
            Log.Debug("[" + _inputText + "]");

            var retVal = new List<string>();

            success = true;

            try
            {
                string[] prediction = _presage.predict(prevWords, currentWord);
                // The code below was removing diacritics from the suggested words
                // Commented out to enable localization
                //for (int ii = 0; ii < prediction.Length; ii++)
                //{
                //    // remove non-ascii characters
                //    prediction[ii] = Regex.Replace(prediction[ii], "[^ -~]", "");
                //}

                var predictionList = prediction.ToList();

                for (int count = 0, ii = 0; count < PredictionWordCount && ii < predictionList.Count(); ii++)
                {
                    if (matchPrefix(currentWord, predictionList[ii]))
                    {
                        //LogDebug(String.Format("Prediction["+ ii + "] = " + predictions[ii].Term));
                        retVal.Add(predictionList[ii]);
                        count++;
                    }
                }
            }
            catch (Exception ex)
            {
                success = false;
                Log.Debug("Presage Predict Exception " + ex);
                retVal = new List<string>();
            }

            return retVal;
        }