public bool IsIndexVisible(int index) { var token = _source.GetIndexToken(index); var value = IsTokenVisible(token); return(value); }
private void CreateSuffixPredictions() { for (var compoundPredictionIndex = _nascents.Count - 1; 0 <= compoundPredictionIndex; compoundPredictionIndex--) { var compoundPrediction = _nascents[compoundPredictionIndex]._list; var longestPrediction = compoundPrediction[compoundPrediction.Count - 1]; var longestPredictionText = longestPrediction.Text; var includedPrefixIndex = longestPrediction.Index; var beyondPrefixIndex = includedPrefixIndex; var limitFound = false; for (var step = 1; !limitFound; step += 1) { includedPrefixIndex = beyondPrefixIndex; beyondPrefixIndex = includedPrefixIndex + step; if (_upperBound <= beyondPrefixIndex) { beyondPrefixIndex = _upperBound; limitFound = true; } else { var candidateLimitToken = _source.GetIndexToken(beyondPrefixIndex); var candidateLimitText = _tokens[candidateLimitToken]; if (!candidateLimitText.StartsWith(longestPredictionText, StringComparison.OrdinalIgnoreCase)) { limitFound = true; } } } var foundLimit = false; do { if (includedPrefixIndex + 1 == beyondPrefixIndex) { foundLimit = true; } else { var midIndex = (includedPrefixIndex + beyondPrefixIndex) / 2; var midToken = _source.GetIndexToken(midIndex); var midText = _tokens[midToken]; if (midText.StartsWith(longestPredictionText, StringComparison.OrdinalIgnoreCase)) { includedPrefixIndex = midIndex; } else { beyondPrefixIndex = midIndex; } } }while (!foundLimit); if (longestPrediction.Index + 1 < beyondPrefixIndex) { var capitalizer = GetEncaser(longestPrediction.IsFollowOnFirstWord); Debug.WriteLine($"Consider extending {longestPredictionText}:"); var followOn = _nascents[compoundPredictionIndex]._followOn; var minSuffixIndex = longestPrediction.Index + 1; var limSuffixIndex = beyondPrefixIndex; var extendedPredictionText = longestPredictionText; bool SuffixFilter(int token) { var index = _source.GetTokenIndex(token); var value = minSuffixIndex <= index && index < limSuffixIndex && !_predictedTokens.Contains(token); if (value) { var text = capitalizer(_tokens[token]); value = extendedPredictionText.StartsWith(text) || text.StartsWith(extendedPredictionText); } return(value); } var additionalScores = _maker.GetTopScores(SuffixFilter, true); using (var enumerator = additionalScores.GetEnumerator()) { var improved = true; for (var candidatePrediction = GetNextCorePrediction(enumerator, _startOnFirstWord); improved && candidatePrediction != null; candidatePrediction = GetNextCorePrediction(enumerator, _startOnFirstWord)) { if (candidatePrediction.Text.StartsWith(longestPredictionText)) { if (followOn != null && candidatePrediction.Score < followOn.Score) { Debug.WriteLine($"\t-{candidatePrediction} less likely than {followOn}"); improved = false; } else if (extendedPredictionText.StartsWith(candidatePrediction.Text)) { Debug.WriteLine($"\t+{candidatePrediction.Text}"); InsertPrediction(compoundPrediction, candidatePrediction); } else if (candidatePrediction.Text.StartsWith(extendedPredictionText)) { Debug.WriteLine($"\t*{candidatePrediction.Text}"); InsertPrediction(compoundPrediction, candidatePrediction); extendedPredictionText = candidatePrediction.Text; var followOnMaker = _maker.CreateNextPredictionMaker(candidatePrediction.Token, null); var followOnPrediction = GetTopPrediction(followOnMaker, longestPrediction.IsFollowOnFirstWord); _nascents[compoundPredictionIndex]._followOnMaker = followOnMaker; _nascents[compoundPredictionIndex]._followOn = followOnPrediction; } } } } } } }