internal CaseWordVocabularySource(ApplicationModel model, WordVocabularySource source, HeadWordItem target) : base(model) { _source = source; _target = target; var substitutes = new List <string>(); var tile = TileData.FromTokenString(target.Content); var content = tile.Content; var isPrefix = tile.IsPrefix; var isSuffix = tile.IsSuffix; var attributes = tile.Attributes; var included = new HashSet <string> { target.Content }; var map = WordCaseMap.Create(content); if (map.LetterCount != 0) { var position0 = map.Positions[0]; CheckedAdd(model.HeadItems[0].Culture.TextInfo.ToTitleCase(content)); CheckedAdd(content.ToLower()); CheckedAdd(content.ToUpper()); CheckedAdd(content.Substring(0, position0) + char.ToUpper(content[position0]) + content.Substring(position0 + 1)); for (var i = 0; i < map.Positions.Length; i++) { var position = map.Positions[i]; var ch = map.Uppers[i] ? char.ToLower(content[position]) : char.ToUpper(content[position]); var cased = content.Substring(0, position) + ch + content.Substring(position + 1); CheckedAdd(cased); } void CheckedAdd(string newContent) { var newTile = TileData.Create(content: newContent, isSuffix: isPrefix, isPrefix: isSuffix, attributes: attributes); var version = newTile.ToTokenString(); if (included.Add(version)) { substitutes.Add(version); } } } for (var i = 0; i < 4; i++) { var spacedTile = TileData.Create(content: content, isSuffix: (i & 1) != 0, isPrefix: (i & 2) != 0, attributes: attributes); var spacedContent = spacedTile.ToTokenString(); if (included.Add(spacedContent)) { substitutes.Add(spacedContent); } } _substitutes = substitutes.ToArray(); }
private SuggestedWordListsCreator(WordVocabularySource source, StringTokens tokens, ScoredTokenPredictionMaker maker, Func <int, bool> isTokenVisible, bool startOnFirstWord, int lowerBound, int upperBound, int maxListCount, int maxListItemCount) { _source = source; _tokens = tokens; _maker = maker; _isTokenVisible = isTokenVisible; _startOnFirstWord = startOnFirstWord; _lowerBound = lowerBound; _upperBound = upperBound; _maxListCount = maxListCount; _maxListItemCount = maxListItemCount; var settings = source.Model.Environment.Settings; _allowDuplicateStems = settings.AllowDuplicateStems; _findFollowOnPredictions = settings.FindFollowOnPredictions; _combineCorePredictions = settings.CombineCorePredictions; _findCorePredictionPrefixes = settings.FindCorePredictionPrefixes; _findCorePredictionSuffixes = settings.FindCorePredictionSuffixes; _nascents = new List <NascentWordPredictionList>(_maxListCount); _capitalizer = source.Model.Environment.TryCapitalizeFirstWord; }
/// <summary> /// Constructor. /// </summary> public ApplicationModel(IWriterEnvironment environment) { Environment = environment; _wordSource = new WordVocabularySource(this); SuggestionLists = new ReadOnlyObservableCollection <IReadOnlyList <ITile> >(_nextSuggestions); SuggestionInterstitials = new ReadOnlyObservableCollection <ITile>(_suggestionInterstitials); Source = _wordSource; _wordSource.SetSuggestionsView(); }
internal SpellingVocabularySource(ApplicationModel model, WordVocabularySource wordVocabularySource) : base(model: model, predictorWidth: 4) { _wordVocabularySource = wordVocabularySource; _characterSet = new SortedSet <string>(Environment); foreach (var word in _wordVocabularySource.Words) { var actualLength = word.Length; var effectiveLength = 0; while (effectiveLength < actualLength && word[effectiveLength] != 0) { effectiveLength++; } if (effectiveLength != 0) { var sequence = new int[effectiveLength + 2]; var index = 1; for (var i = 0; i < effectiveLength; i++) { sequence[index] = word[i]; index++; } Debug.Assert(sequence[0] == 0); Debug.Assert(sequence[effectiveLength + 2 - 1] == 0); PersistantPredictor.AddSequence(sequence, WordVocabularySource.SeedSequenceWeight); } } foreach (var symbol in model.Environment.GetAdditionalSymbols()) { var sequence = new int[] { symbol }; PersistantPredictor.AddSequence(sequence, WordVocabularySource.SeedSequenceWeight); } _unicodeVocabularySource = new UnicodeVocabularySource(model, this); PopulateVocabularyList(); }
internal static SortedList <int, IReadOnlyList <ITile> > CreateSuggestionLists(WordVocabularySource source, StringTokens tokens, TokenPredictor tokenPredictor, int[] context, ITokenTileFilter filter, bool isFirstWord, int lowerBound, int upperBound, int maxListCount, int maxListItemCount) { BreakOnProblemCase(tokens, context, "these", "are", "the", "voyages"); var maker = tokenPredictor.CreatePredictionMaker(source, filter.IsTokenVisible, context); var creator = new SuggestedWordListsCreator(source, tokens, maker, filter.IsTokenVisible, isFirstWord, lowerBound, upperBound, maxListCount, maxListItemCount); var list = creator.Run(); return(list); }
public WordTileFilter(WordVocabularySource source, StringTokens tokens, CultureInfo culture) { _source = source; _tokens = tokens; _compare = culture.CompareInfo; }
internal CodeVocabularySource(WordVocabularySource source) : base(source.Model) { _source = source; }