async Task AzureSuggestions(string text) { Suggestions.Clear(); var parameters = new SuggestParameters() { UseFuzzyMatching = true, HighlightPreTag = "[", HighlightPostTag = "]", MinimumCoverage = 100, Top = 10 }; var suggestionResults = await indexClient.Documents.SuggestAsync <Monkey>(text, "nameSuggester", parameters); foreach (var result in suggestionResults.Results) { Suggestions.Add(new Monkey { Name = result.Text, Location = result.Document.Location, Details = result.Document.Details, ImageUrl = result.Document.ImageUrl }); } }
public void CreateSuggestions(IEnumerable <BindingSuggestion> suggestions) { // Go through each suggestion that exists... foreach (var suggestion in suggestions) { var path = suggestion.FindValidSuggestionPath(); if (string.IsNullOrEmpty(path)) { continue; } // Create a VM for it. var newVm = new SuggestionViewModel(); newVm.FromModel(suggestion); newVm.HotKeyBinding = new HotKeyBinding { DisplayName = suggestion.DisplayName, HotKey = suggestion.HotKey, Action = new ExecuteProgramAction { Program = path } }; Suggestions.Add(newVm); } }
private void UpdateSuggestions(string words) { if (string.IsNullOrWhiteSpace(words)) { Suggestions?.Clear(); return; } string[] enteredWordList = words.Split(' ', StringSplitOptions.RemoveEmptyEntries); var lastWorld = enteredWordList.LastOrDefault().Replace("\t", ""); if (lastWorld.Length < 1) { Suggestions.Clear(); return; } var suggestedWords = EnglishWords.Where(w => w.StartsWith(lastWorld)).Except(enteredWordList).Take(7); Suggestions.Clear(); foreach (var suggestion in suggestedWords) { Suggestions.Add(new SuggestionViewModel(suggestion, OnAddWord)); } }
private void UpdateAutocomplete() { // There's an strange reason which causes TextChanged to fire indefinitely, although the text has not changed really. // To avoid this, if the text we stored is the same, just return. if (_text == _textbox.Text) { return; } _text = _textbox.Text; if (ShouldStopAutocompleting()) { IsAutocompleting = false; return; } written = GetTextWrittenByUser(); Suggestions.Clear(); foreach (var user in _provider.Usernames .Where(x => x.IndexOf(written, StringComparison.InvariantCultureIgnoreCase) != -1) .Take(20) .OrderBy(x => x)) { Suggestions.Add(user); } }
public void FillDictData(string[] namesArr, FieldStorage[] storesArr, string[] analArr, SuggestionOptions[] sugArr) { for (int i = 0; i < namesArr.Length; i++) { Fields.Add(namesArr[i]); Stores.Add(namesArr[i], storesArr[i]); Analyzers.Add(namesArr[i], analArr[i]); Suggestions.Add(namesArr[i], sugArr[i]); } }
public void LocationAutoSuggestTextChanged() { if (this._autoSuggestionBoxText.Length > 1) { this.GetSuggestionsAsync(this._autoSuggestionBoxText); } else { Suggestions.Clear(); Suggestions.Add("No suggestions..."); } }
private void GetSuggestionsAsync(string text) { Task t = Task.Run(async() => { locs = await HttpServiceSingleton.GetInstance.GetLocationAsync($"https://api.mapbox.com/geocoding/v5/mapbox.places/{text}.json?access_token=pk.eyJ1IjoiZGlldGVyZHMiLCJhIjoiY2tpMGRlMTVmMDBvMjMwa2JveWYwY3k3eSJ9.I9Y9bm0oMnQJyshyZTKMdQ&autocomplete=true&limit=5"); }); t.Wait(); Suggestions.Clear(); foreach (var item in locs) { Suggestions.Add(item.LocationNameLong); } }
public SearchQueryViewModel(MessageBus messageBus) { MessageBus = messageBus ?? throw new ArgumentNullException("messageBus"); MessageBus.Subscribe <ServerSettingsChangedMessage>(m => { if (m.ServiceModel == null) { QueryText = ""; StatusMessage = ""; } }); MessageBus.Subscribe <BuildSearchMessage>(m => { m.Query.QueryText = QueryText; }); MessageBus.Subscribe <BeginSearchMessage>(m => { if (m.ReturnOptions.HasFlag(ReturnOptions.Results) && !m.IsPaging) { StatusMessage = "Searching..."; IsSearching = true; } if (m.ReturnOptions.HasFlag(ReturnOptions.Suggest)) { Suggestions.Clear(); } }); MessageBus.Subscribe <EndSearchMessage>(m => { if (m.Results.ReturnOptions.HasFlag(ReturnOptions.Results) && !m.IsPaging) { StatusMessage = $"Matched {m.Results.Total,1:n0} documents and {m.Results.TotalObjects,1:n0} distinct objects."; IsSearching = false; } if (m.Results.ReturnOptions.HasFlag(ReturnOptions.Suggest)) { foreach (var suggestion in m.Results.QuerySuggestions) { Suggestions.Add(suggestion); } } }); MessageBus.Subscribe <SearchAbortedMessage>(m => { IsSearching = false; StatusMessage = "Search aborted."; }); }
private void AutoSuggestBoxTo_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args) { if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput) { var suggestions = new ObservableCollection <string>(Suggestions.ToList()); Suggestions.Clear(); foreach (var place in suggestions) { if (place.Contains(sender.Text)) { Suggestions.Add(place); } } sender.ItemsSource = Suggestions; } }
private void recurseSuggestions(Node <Char> c, String canidateSuggestion) { foreach (Node <Char> n in c.Children) { string toAdd = canidateSuggestion + n.Value; if (n.IsTerminal) { Suggestions.Add(toAdd); } if (n.Children.Count > 0 && Suggestions.Count < maxSuggestions) { recurseSuggestions(n, toAdd); } } }
public async Task GetPlacesByName(string placeText) { var places = await _googleMapsApi.GetPlaces(placeText); var placeResult = places?.AutoCompletePlaces; if (placeResult != null && placeResult.Count > 0) { Places = new ObservableCollection <GooglePlaceAutoCompletePrediction>(placeResult); } Suggestions?.Clear(); foreach (var place in Places) { Suggestions?.Add($"{place.StructuredFormatting.MainText} - {place.StructuredFormatting.SecondaryText}"); } }
private void SearchForPatientCandidates(string inputText) { Suggestions.Clear(); var candidates = _summaries.Select(s => new { s, IdDistance = Levenshtein.ComputeDistance(s.Id.ToUpper(), inputText.ToUpper()), LastNameDistance = Levenshtein.ComputeDistance(s.LastName.ToUpper(), inputText.ToUpper()), FullNameDistance = Levenshtein.ComputeDistance($"{s.LastName.ToUpper()}, {s.FirstName.ToUpper()}", inputText.ToUpper()), }) .Select(s => new { s.s, Distance = Math.Min(Math.Min(s.IdDistance, s.FullNameDistance), s.LastNameDistance) }) .OrderBy(s => s.Distance) .Where(s => s.Distance < 5) .OrderBy(s => s.Distance) .Take(5).ToList(); candidates.ForEach(c => Suggestions.Add(c.s)); }
private object MakeSuggestions(TagViewModel tag) { Contract.Requires(tag != null); var tagIndex = Tags.IndexOf(tag); // все сущности кроме сущности редактируемого тега var tagBlanksExceptEditing = Tags.Select((t, i) => i != tagIndex ? t.Blank : null); var results = sugMaker.SearchForSuggesstions( query: tag.Query, prevEntityBlank: tagIndex > 0 ? Tags[tagIndex - 1].Blank : null, exclude: null); Suggestions.Clear(); foreach (var item in results) { Suggestions.Add(new SuggestionViewModel(item, ShowAltSuggestion, item.IsTransient)); } SelectedSuggestion = Suggestions.FirstOrDefault(); return(Suggestions.FirstOrDefault()); }
private void UpdateSuggestions() { if (_selectedSuggestionChanged) { return; } Suggestions.Clear(); if (QueueManagerProvided || QueueManager != null) { App.ShellService.WithGlobalBusy(() => { try { var filter = QueueManager.NewObjectNameFilter(QueueName); var provider = QueueManager.NewObjectProvider(filter); var sysFilter = QueueManager.NewSystemObjectNameFilter(); var list = provider.GetQueueNames(); foreach (var s in list) { if (!IncludeSystemQueues && sysFilter.IsMatch(s)) { continue; } Suggestions.Add(s); } } catch (MqException) { } }); } CommandManager.InvalidateRequerySuggested(); }
void SetSuggestions() { if (!IsDropDownOpen) { return; } Suggestions.Clear(); var find = SelectedText == Text ? "" : SelectedText.CoalesceNullOrEmpty(Text) ?? ""; var ucFind = Regex.Replace(find, "[^A-Z]", ""); foreach (var suggestion in SuggestionList.Where(x => HasStr(x.Text, find))) { Suggestions.Add(suggestion); } if (!Suggestions.Any()) { Suggestions.Add(null); } SuggestedIndex = find == "" ? 0 : Suggestions.Indexes(str => str?.Text.StartsWith(Text, StringComparison.InvariantCultureIgnoreCase) ?? false).FirstOrDefault(); }
private void addSuggestion(Suggestion suggestion) { Suggestions.Add(suggestion); RaisePropertyChanged(); }
/// <summary> /// Populates the <see cref="Suggestions"/> property with word suggestions /// for the <see cref="CurrentWord"/> /// </summary> /// <remarks> /// <see cref="TestWord()"/> or <see cref="TestWord(string)"/> must have been called before calling this method /// </remarks> /// <seealso cref="CurrentWord"/> /// <seealso cref="Suggestions"/> /// <seealso cref="TestWord()"/> /// <seealso cref="TestWord(string)"/> public void Suggest() { // can't generate suggestions with out current word if (CurrentWord.Length == 0) { TraceWriter.TraceWarning("No current word"); return; } Initialize(); var tempSuggestion = new List <Word>(); if ((SuggestionMode == SuggestionEnum.PhoneticNearMiss || SuggestionMode == SuggestionEnum.Phonetic) && _dictionary.PhoneticRules.Count > 0) { // generate phonetic code for possible root word Dictionary <string, string> codes = new Dictionary <string, string>(); foreach (string tempWord in _dictionary.PossibleBaseWords) { string tempCode = _dictionary.PhoneticCode(tempWord); if (tempCode.Length > 0 && !codes.ContainsKey(tempCode)) { codes.Add(tempCode, tempCode); } } if (codes.Count > 0) { // search root words for phonetic codes foreach (Word word in _dictionary.BaseWords.Values) { if (codes.ContainsKey(word.PhoneticCode)) { List <string> words = _dictionary.ExpandWord(word); // add expanded words foreach (string expandedWord in words) { SuggestWord(expandedWord, tempSuggestion); } } } } TraceWriter.TraceVerbose("Suggestions Found with Phonetic Strategy: {0}", tempSuggestion.Count); } if (SuggestionMode == SuggestionEnum.PhoneticNearMiss || SuggestionMode == SuggestionEnum.NearMiss) { // suggestions for a typical fault of spelling, that // differs with more, than 1 letter from the right form. ReplaceChars(tempSuggestion); // swap out each char one by one and try all the tryme // chars in its place to see if that makes a good word BadChar(tempSuggestion); // try omitting one char of word at a time ExtraChar(tempSuggestion); // try inserting a tryme character before every letter ForgotChar(tempSuggestion); // split the string into two pieces after every char // if both pieces are good words make them a suggestion TwoWords(tempSuggestion); // try swapping adjacent chars one by one SwapChar(tempSuggestion); } TraceWriter.TraceVerbose("Total Suggestions Found: {0}", tempSuggestion.Count); tempSuggestion.Sort(); // sorts by edit score Suggestions.Clear(); foreach (var suggestion in tempSuggestion) { string word = suggestion.Text; // looking for duplicates if (!Suggestions.Contains(word)) { // populating the suggestion list Suggestions.Add(word); } if (Suggestions.Count >= MaxSuggestions && MaxSuggestions > 0) { break; } } }
private void addSuggestions(Suggestion suggestions) { Suggestions.Add(suggestions); RaisePropertyChanged(nameof(IsEmpty)); }