public TextualContextAreaViewModel( ITextualContextService textualContext, IPredictionTextAreaService predictionTextArea, ICommandTextualContextService commandTextualContextService )
 {
     _textualContext = textualContext;
     _predictionTextArea = predictionTextArea;
     _predictionTextArea.TextSent += OnPredictionAreaContentSent;
     _commandTextualContextService = commandTextualContextService;
 }
        /// <summary>
        /// Gets the prediction context (all the text that has been written since the last "Return")
        /// </summary>
        /// <param name="textualService"></param>
        /// <returns></returns>
        public string ObtainContext( ITextualContextService textualService )
        {
            if( textualService.Tokens.Count > 1 )
            {
                string tokenPhrase = String.Join( " ", textualService.Tokens.Take( textualService.CurrentTokenIndex ).Select( t => t.Value ) );
                tokenPhrase += " ";
                if( textualService.Tokens.Count >= textualService.CurrentTokenIndex )
                {
                    string value = textualService.Tokens[textualService.CurrentTokenIndex].Value;
                    if( value.Length >= textualService.CaretOffset )
                    {
                        tokenPhrase += ( value.Substring( 0, textualService.CaretOffset ) );
                    }
                }

                return tokenPhrase;
            }
            if( textualService.Tokens.Count == 1 )
            {
                return textualService.CurrentToken.Value.Substring( 0, textualService.CaretOffset );
            }
            return String.Empty;
        }
        public Task<IEnumerable<IWordPredicted>> PredictAsync( ITextualContextService textualContext, int maxSuggestedWords )
        {
            if( _currentlyRunningTaskCancellationToken == null )
                _currentlyRunningTaskCancellationToken = new CancellationToken( false );

            if( _currentlyRunningTask != null && _currentlyRunningTask.Status == TaskStatus.Running )
            {
                _cancellationSource.Cancel();
            }
            else
            {
                _currentlyRunningTask = Task.Factory.StartNew( () => Predict( textualContext, maxSuggestedWords ), _currentlyRunningTaskCancellationToken );
            }
            return _currentlyRunningTask;
        }
 public IEnumerable<IWordPredicted> Predict( ITextualContextService textualService, int maxSuggestedWords )
 {
     //This call can sometimes raise an ArgumentException
     //TODO : log it and catch it to go on.
     IEnumerable<WeightlessWordPredicted> result = null;
     try
     {
         result = _sybille
             .Predict( ObtainSybilleContext( textualService ), maxSuggestedWords )
             .Select( t => new WeightlessWordPredicted( t ) );
     }
     catch( ArgumentException )
     {
         return Enumerable.Empty<IWordPredicted>();
     }
     return result;
 }
 /// <summary>
 /// Calls <see cref="ObtainContext( ITextualContextService textualService )"/> and replaces all occurences of "'" (apostrophe) by "' " (apostrophe + space).
 /// Done so because Sybille doesn't understand the apostrophe character. therefor, in order to get a prediction for the word that follows this char, we flush Sybille's context thanks to the space char.
 /// </summary>
 public virtual string ObtainSybilleContext( ITextualContextService textualService )
 {
     return ObtainContext( textualService ).Replace( "'", "' " );
 }
 public string ObtainRawContext( ITextualContextService textualContextService )
 {
     throw new NotImplementedException();
 }
 public System.Threading.Tasks.Task<IEnumerable<IWordPredicted>> PredictAsync( ITextualContextService textualContext, int maxSuggestedWords )
 {
     throw new NotImplementedException();
 }
 public IEnumerable<IWordPredicted> Predict( ITextualContextService textualService, int maxSuggestedWord )
 {
     throw new NotImplementedException();
 }