Exemplo n.º 1
0
        /// <summary>
        /// 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
        /// </summary>
        /// <param name="prevWords">Previous words in the sentence</param>
        /// <param name="currentWord">current word (may be partially spelt out</param>
        /// <param name="success">true if the function was successsful</param>
        /// <returns>A list of predicted words</returns>
        protected virtual IEnumerable <String> predict(String prevWords, String currentWord, ref bool success)
        {
            Log.Debug("Predict for: " + prevWords + " " + currentWord);

            var retVal = new List <string>();

            success = true;

            try
            {
                prevWords   = UTF8EncodingToDefault(prevWords);
                currentWord = UTF8EncodingToDefault(currentWord);

                prevWords   = prevWords.Replace('\'', '´');
                currentWord = currentWord.Replace('\'', '´');

                string[] prediction = presage.predict(prevWords, currentWord);

                for (int ii = 0; ii < prediction.Length; ii++)
                {
                    prediction[ii] = defaultEncodingToUTF8(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);
        }
        /// <summary>
        /// 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
        /// </summary>
        /// <param name="prevWords">Previous words in the sentence</param>
        /// <param name="currentWord">current word (may be partially spelt out</param>
        /// <param name="success">true if the function was successsful</param>
        /// <returns>A list of predicted words</returns>
        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;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 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
        /// </summary>
        /// <param name="prevWords">Previous words in the sentence</param>
        /// <param name="currentWord">current word (may be partially spelt out</param>
        /// <returns>A list of predicted words</returns>
        public IEnumerable <String> Predict(String prevWords, String currentWord)
        {
            // update the internal buffer with prevWords + currentWord
            _inputText = prevWords + " " + currentWord;
            Log.Debug("[" + _inputText + "]");

            List <string> retVal;

            try
            {
                string[] prediction = _presage.predict(prevWords, currentWord);
                retVal = prediction.ToList();
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                retVal = new List <string>();
            }
            return(retVal);
        }