private void toggleTaskSuggestions(ProjectSuggestion projectSuggestion) { var grouping = Suggestions.FirstOrDefault(s => s.WorkspaceName == projectSuggestion.WorkspaceName); if (grouping == null) { return; } var suggestionIndex = grouping.IndexOf(projectSuggestion); if (suggestionIndex < 0) { return; } projectSuggestion.TasksVisible = !projectSuggestion.TasksVisible; var groupingIndex = Suggestions.IndexOf(grouping); Suggestions.Remove(grouping); Suggestions.Insert(groupingIndex, new WorkspaceGroupedCollection <AutocompleteSuggestion>( grouping.WorkspaceName, getSuggestionsWithTasks(grouping) ) ); }
/// <summary> /// Gets the suggestions based on the user input. Search is done by linq that loops through the list which gives O(n) complexity /// where n is the number of words /// </summary> /// <param name="userInput">User input</param> /// <returns>Suggestions including possible next letters and stations.</returns> public Suggestions GetSuggestions(string userInput) { userInput = userInput.ToUpper(); var suggestions = new Suggestions(); // Get all stations from stations list that start with the user input // If the user input is empty, get all stations if (string.IsNullOrEmpty(userInput)) { suggestions.Stations = this.stations; } else { suggestions.Stations = this.stations.Where(s => s.ToLower().StartsWith(userInput.ToLower())).ToList(); } // Get all possible next letters // Loop through on all suggested stations foreach (string station in suggestions.Stations) { string sub = station.Substring(userInput.Length); // If there are more letters after taking the prefix out of the station if (sub.Length > 0) { // Add the next letter (char) to the suggested next letters suggestions.NextLetters.Add(sub[0]); } } // Only need distinct characters suggestions.NextLetters = suggestions.NextLetters.Distinct().ToList(); // Order the list suggestions.NextLetters.Sort(); return(suggestions); }
public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { AutoCompleteTextField.Text = Suggestions.ElementAt(indexPath.Row); AutoCompleteTextField.AutoCompleteTableView.Hidden = true; RowSelectedEvent?.Invoke(this, EventArgs.Empty); }
/// <summary> /// The Get Proposal By Name Or ID method gets a proposal both from either its token, staff message ID or message ID. /// </summary> /// <param name="Tracker">The tracked variable of the proposal you would like to find.</param> /// <returns>A proposal object pertaining to the proposal that has been returned on the tracked token.</returns> public Proposal GetProposalByNameOrID(string Tracker) { Proposal TryTracked = Proposals.Find(Tracker); if (TryTracked != null) { return(TryTracked); } if (ulong.TryParse(Tracker, out ulong TrackerASULONG)) { Proposal TryMessageID = Proposals.AsQueryable().Where(Proposal => Proposal.MessageID == TrackerASULONG).FirstOrDefault(); if (TryMessageID != null) { return(TryMessageID); } Suggestion Suggestion = Suggestions.AsQueryable().Where(Suggestion => Suggestion.StaffMessageID == TrackerASULONG).FirstOrDefault(); if (Suggestion != null) { return(Proposals.Find(Suggestion.Tracker)); } } return(null); }
protected override void OnTextChanged(TextChangedEventArgs e) { _suggestions = _tokenCompleter.Run(this.Text); tooltipMethodSignatures.IsOpen = _suggestions.Signatures.Count > 0; string signatures = string.Empty; foreach (var item in _suggestions.Signatures) { if (_suggestions.Signatures.LastOrDefault().Equals(item)) { signatures += item; break; } signatures += item + Environment.NewLine; } tooltipMethodSignatures.Content = signatures; ItemList.Items.Clear(); foreach (string value in _suggestions.CompleteStructures) { ItemList.Items.Add("ω:" + value); } foreach (string value in _suggestions.CompleteVariables) { ItemList.Items.Add("ω:" + value); } foreach (string value in _suggestions.CompleteFunctions) { ItemList.Items.Add("ƒ:" + value + "("); } Popup.IsOpen = ItemList.Items.Count > 0; }
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 TestStationFinderLiverpool() { //Arrange var result = GetValidResult(); _dataAccess.Setup(x => x.GetStationList()).Returns(result); _dataAccess.Setup(x => x.GetName(It.IsAny <string>())).ReturnsAsync("testgetname"); //Act Suggestions response = _stationFinder.GetSuggestions("Liverpool").Result; _suggestions.NextLetters = new HashSet <string>() { "L" }; _suggestions.Stations = new HashSet <string>() { "LIVERPOOL LIME STREET" }; //Assert Assert.IsNotNull(response); Assert.AreEqual(response.NextLetters.Count, 1); Assert.AreEqual(response.Stations.Count, 1); Assert.AreEqual(response.NextLetters, _suggestions.NextLetters); Assert.AreEqual(response.Stations, _suggestions.Stations); }
public void TestStationFinderNullInput() { Suggestions response = _stationFinder.GetSuggestions(null).Result; Assert.IsNull(response.NextLetters); Assert.IsNull(response.Stations); }
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 virtual int _GetUniqueIdentifier() { var hashCode = 399326290; hashCode = hashCode * -1521134295 + (WayPointVisibilityID?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Waypoint?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (From?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (To?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (ConveyanceId?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (ConveyanceRef?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (ShippingAgent?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (TotalConsignments?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (DirectConsignments?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (TransshipmentConsignments?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (TotalCargos?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (FullCargos?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (EmptyCargos?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (TotalRiskDetected?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Consignment?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (CargoId?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (RiskType?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (RiskScore?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Severity?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Details?.GetHashCode() ?? 0); hashCode = hashCode * -1521134295 + (Suggestions?.GetHashCode() ?? 0); return(hashCode); }
public static List <Suggestions> GrammarSuggestionsService(string Paragraph) { List <Suggestions> _SuggestionsObj = new List <Suggestions>(); string line; System.IO.StreamReader file = new System.IO.StreamReader(ConfigurationManager.AppSettings["GrammarFile"] + "grammar.txt"); while ((line = file.ReadLine()) != null) { string prefix = line.Substring(0, line.IndexOf("|")); string suffix = line.Substring(line.IndexOf("|") + 1, line.Length - (prefix.Length + 1)); if (suffix.Contains("(")) { suffix = suffix.Substring(0, suffix.IndexOf("(")).TrimEnd(); } if (Paragraph.Contains(prefix)) { int index = _SuggestionsObj.FindIndex(item => item.Text == prefix); if (index >= 0) { _SuggestionsObj[index].SuggestedText.Add(suffix); } else { Suggestions TempSuggestions = new Suggestions(); List <string> TempSuggestedText = new List <string>(); TempSuggestions.Text = prefix; TempSuggestedText.Add(suffix); TempSuggestions.SuggestedText = TempSuggestedText; _SuggestionsObj.Add(TempSuggestions); } } } file.Close(); return(_SuggestionsObj); }
private void OnSearchTextChangerd() { if (string.IsNullOrEmpty(Search)) { if (Suggestions != null && Suggestions.Count > 0) { Suggestions.Clear(); } _messagingService.Send <HideUnhideViewAnimationMessage>(new HideUnhideViewAnimationMessage(true)); return; } if (Search.Length < 3) { if (Suggestions != null && Suggestions.Count > 0) { Suggestions.Clear(); } HasAnySuggestions = false; return; } // Add API Stuff here. Suggestions = new ObservableCollection <Suggestion>() { new Suggestion() { Content = "French Cuisine Restaurants", TapCommand = SuggestionTapCommand, RemoveCommand = SuggestionRemoveCommand } }; HasAnySuggestions = Suggestions.Count > 0; }
public ActionResult AddUserSuggestion([FromBody] AddSuggestionViewModel model) { try { string userId = User.GetUserIdToken(); if (ModelState.IsValid) { Suggestions newSuggestion = new Suggestions() { UserId = userId, SuggestedModel = model.SuggestedModel, Description = model.Description }; _suggestionRepository.Add(newSuggestion); _suggestionRepository.SaveAll(); return(Ok(new { message = "Suggestion Successfully Added." })); } return(BadRequest("Suggestion Model is not valid.")); } catch { return(BadRequest("An Error Has Occured.")); } }
public void SuggestionsStationsShouldReturnOnePerLine() { var suggestions = new Suggestions(_stations, _nextLetters); Assert.Contains("Abergavenny", suggestions.Stations); Assert.Equal(3, suggestions.Stations.Count()); }
public void SuggestionsNextLettersShouldReturnOnePerLine() { var suggestions = new Suggestions(_stations, _nextLetters); Assert.Contains('x', suggestions.NextLetters); Assert.Equal(2, suggestions.NextLetters.Count); }
public ActionResult updateTender(Suggestions t) { int num = findLastSuggest2(); Suggestions s2 = t; t.numSuggestion = num; t.dataSuggestion = DateTime.Now; using (DbtenderEntities1 DB1 = new DbtenderEntities1()) { DB1.Suggestions.Add(s2); try { DB1.SaveChanges(); } catch { } } try { using (DbtenderEntities1 DB = new DbtenderEntities1()) { var tender = DB.Tenders.Find(Convert.ToInt32(t.numTender)); tender.status = "סגור"; tender.winner = t.numCont; tender.till = t.dataSuggestion; tender.numSugestion = num; DB.SaveChanges(); } } catch (Exception) { } return(View()); }
/// <summary> /// Remove the default values that we don't actually need /// </summary> public void RemoveDefaultValues() { var defaultStorage = IsMapReduce ? FieldStorage.Yes : FieldStorage.No; foreach (var toRemove in Stores.Where(x => x.Value == defaultStorage).ToArray()) { Stores.Remove(toRemove); } foreach (var toRemove in Indexes.Where(x => x.Value == FieldIndexing.Default).ToArray()) { Indexes.Remove(toRemove); } foreach (var toRemove in SortOptions.Where(x => x.Value == Indexing.SortOptions.None).ToArray()) { SortOptions.Remove(toRemove); } foreach (var toRemove in Analyzers.Where(x => string.IsNullOrEmpty(x.Value)).ToArray()) { Analyzers.Remove(toRemove); } foreach (var toRemove in Suggestions.Where(x => x.Value.Distance == StringDistanceTypes.None).ToArray()) { Suggestions.Remove(toRemove); } foreach (var toRemove in TermVectors.Where(x => x.Value == FieldTermVector.No).ToArray()) { TermVectors.Remove(toRemove); } }
/// <summary> /// Gets the suggestions based on the user input /// </summary> /// <param name="userInput">User input</param> /// <returns>Suggestions including possible next letters and stations.</returns> public Suggestions GetSuggestions(string userInput) { userInput = userInput.ToUpper(); Suggestions suggestions = new Suggestions(); // get stations Node nodeWithUSerInputPrefix = SearchNodeByPrefix(userInput.ToUpper()); if (nodeWithUSerInputPrefix == null) { return(suggestions); } suggestions.Stations = GetStationsByNode(nodeWithUSerInputPrefix); suggestions.Stations.Sort(); // get next letters foreach (Node node in nodeWithUSerInputPrefix.children) { if (node.value != '*') { suggestions.NextLetters.Add(node.value); } } suggestions.NextLetters = suggestions.NextLetters.Distinct().ToList(); suggestions.NextLetters.Sort(); return(suggestions); }
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)); } }
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); } }
public void TestStationFinderDartford() { //Arrange var result = GetValidResult(); _dataAccess.Setup(x => x.GetStationList()).Returns(result); _dataAccess.Setup(x => x.GetName(It.IsAny <string>())).ReturnsAsync("testgetname"); //Act Suggestions response = _stationFinder.GetSuggestions("Dartford").Result; _suggestions.NextLetters = new HashSet <string>() { }; _suggestions.Stations = new HashSet <string>() { "DARTFORD" }; //Assert Assert.IsNotNull(response); Assert.AreEqual(response.NextLetters.Count, 0); Assert.AreEqual(response.Stations.Count, 1); Assert.AreEqual(response.NextLetters, _suggestions.NextLetters); Assert.AreEqual(response.Stations, _suggestions.Stations); }
public JsonResult saving(Suggestions s1) { bool status = false; var isValidModel = TryUpdateModel(s1); if (isValidModel) { using (DbtenderEntities1 DB = new DbtenderEntities1()) { DB.Suggestions.Add(s1); try { DB.SaveChanges(); } catch (Exception) { } status = true; } } return(new JsonResult { Data = new { status = status } }); }
protected void SpellChecker_MisspelledWord(object sender, SpellingEventArgs e) { // Ignore macro content if (IsInMacro(e.TextIndex)) { SpellChecker.IgnoreWord(); SpellChecker.SpellCheck(); return; } SaveValues(); CurrentWord.Text = SpellChecker.CurrentWord; SpellChecker.Suggest(); Suggestions.DataSource = SpellChecker.Suggestions; Suggestions.DataBind(); if (Suggestions.Items.Count > 0) { Suggestions.SelectedIndex = 0; } ReplacementWord.Text = Suggestions.SelectedValue; SpellMode.Value = "suggest"; StatusText.Text = string.Format(wordCounterString, SpellChecker.WordIndex + 1, SpellChecker.WordCount); }
public async Task <Suggestions> GetCompletionSuggestions(ParseResults <TSource> parse, int cursor) { var context = parse.Context; var nodeBeforeCursor = context.FindSuggestionContext(cursor); var parent = nodeBeforeCursor.Parent; var start = Math.Min(nodeBeforeCursor.StartPos, cursor); var fullInput = parse.Reader.String; var truncatedInput = fullInput.Substring(0, cursor); var truncatedInputLowerCase = truncatedInput.ToLowerInvariant(); var futures = new Task <Suggestions> [parent.Children.Count()]; var i = 0; foreach (var node in parent.Children) { var future = Suggestions.Empty(); try { future = node.ListSuggestions(context.Build(truncatedInput), new SuggestionsBuilder(truncatedInput, truncatedInputLowerCase, start)); } catch (CommandSyntaxException) { } futures[i++] = future; } await Task.WhenAll(futures); return(Suggestions.Merge(fullInput, futures.Select(s => s.Result).ToArray())); }
private void _input_TextChanged(object sender, TextChangedEventArgs e) { if (SuggestEngine != null) { Suggestions = SuggestEngine.GetSuggestionsFor(Input.Text); if (PrevText != Input.Text && IsKeyboardFocusWithin) { if (Suggestions.Count() > 0) { Popup.IsOpen = true; } else { Popup.IsOpen = false; } PrevText = Input.Text; if (Selected != null) { Selected = null; } } else { if (!IsKeyboardFocusWithin) { ChangedInBackground = true; Selected = null; } } } }
private void SelectTaskSuggestion(ListMoveDirection direction) { Device.BeginInvokeOnMainThread(() => { // lock for collection manupulation lock (_autoCompleteTasksLock) { bool isAnySelected = Suggestions.Any(t => t.IsSelected); if (!isAnySelected) { // select the last item in the list Suggestions[Suggestions.Count - 1].IsSelected = true; } else if (Suggestions.Count > 1) { var selectedItem = Suggestions.First(t => t.IsSelected); int index = Suggestions.IndexOf(selectedItem); index = direction == ListMoveDirection.Next ? index + 1 : index - 1; if (index < 0) { index = Suggestions.Count - 1; } if (index > Suggestions.Count - 1) { index = 0; } selectedItem.IsSelected = false; selectedItem = Suggestions[index]; selectedItem.IsSelected = true; } } }); }
private void OnKeyDown() { if (Suggestions?.Count() > 0) { var next = (SelectedSuggestionIndex + 1) % Suggestions.Count(); SelectedSuggestionIndex = next; } }
public void SuggestsNextLettersForDartford() { Suggestions suggestions = stationFinder.GetSuggestions("Dartfo"); IEnumerable <char> nextLetters = suggestions.NextLetters; Assert.AreEqual(1, nextLetters.Count()); Assert.AreEqual('r', nextLetters.First()); }
public void SetUp() { //Arrange _suggestions = new Suggestions(); _dataAccess = new Mock <IDataAccess>(); _stationFinder = new StationFinder(_dataAccess.Object); //Using Mock object }
public void SuggestsDartford() { Suggestions suggestions = stationFinder.GetSuggestions("Dartford"); IEnumerable <string> stations = suggestions.Stations; Assert.AreEqual(1, stations.Count()); Assert.AreEqual("Dartford", stations.First()); }
public Suggestions getSuggestions() { Suggestions s = new Suggestions(); s.put("Suggestion B"); s.put("Suggestion A"); s.put("Suggestion C"); return s; }
/// <summary> /// Suggests other potential options based on the entities passed /// </summary> /// <param name="rows">The rows being imported</param> /// <returns>Entites with suggestions</returns> public Suggestions SuggestEntites(ImportRow[] rows) { var rowSuggestionsConcurrentDictionary = new ConcurrentDictionary<int, RowSuggestions>(); var suggestionsToReturn = new Suggestions(); var clients = new ConcurrentDictionary<Guid, FoundOps.Api.Models.Client>(); var locations = new ConcurrentDictionary<Guid, FoundOps.Api.Models.Location>(); var contactInfoSets = new ConcurrentDictionary<Guid, FoundOps.Api.Models.ContactInfo>(); Parallel.For((long)0, rows.Count(), rowIndex => { var row = rows[rowIndex]; var rowSuggestions = new RowSuggestions(); #region Location if (row.Location != null) { //Find all the Locations to be suggested by finding all Locations for the Client of the row var locationSuggestions = row.Client != null ? _locations.Where(l => l.Value.ClientId == row.Client.Id).ToArray() : null; if (locationSuggestions != null) { //Add any of the suggestions to the rows suggestions rowSuggestions.LocationSuggestions.AddRange(locationSuggestions.Select(l => l.Key)); var convertedLocationSuggestions = locationSuggestions.Select(l => l.Value).Select(FoundOps.Api.Models.Location.ConvertModel); //Add all suggested Locations to the list of Locations to be returned foreach (var location in convertedLocationSuggestions) locations.GetOrAdd(location.Id, location); } //Add the matched/new location as the first suggestion rowSuggestions.LocationSuggestions.Add(row.Location.Id); //Add the location passed to the list of location entites locations.GetOrAdd(row.Location.Id, row.Location); } #endregion #region Client if (row.Client != null) { //Find all the Clients to be suggested by finding all Clients for the Location of the row var clientSuggestions = row.Location != null ? _clients.Where(c => c.Key == row.Location.ClientId).ToArray() : null; if (clientSuggestions != null) { //Add any of the suggestions to the rows suggestions rowSuggestions.ClientSuggestions.AddRange(clientSuggestions.Select(c => c.Key)); var convertedClientSuggestions = clientSuggestions.Select(c => c.Value).Select(FoundOps.Api.Models.Client.ConvertModel); //Add all suggested Clients to the list of Clients to be returned foreach (var client in convertedClientSuggestions) clients.GetOrAdd(client.Id, client); } //Add the matched/new client as the first suggestion rowSuggestions.ClientSuggestions.Add(row.Client.Id); //Add the Client passed to the list of client entites clients.GetOrAdd(row.Client.Id, row.Client); } #endregion //Repeat if (row.Repeat != null) rowSuggestions.Repeats.Add(row.Repeat); //Contact Info if (row.ContactInfoSet.Count != 0) { rowSuggestions.ContactInfoSuggestions.AddRange(row.ContactInfoSet.Select(ci => ci.Id)); foreach (var contactInfoSet in row.ContactInfoSet) contactInfoSets.GetOrAdd(contactInfoSet.Id, contactInfoSet); } //Add this row's suggestions to the list to be returned rowSuggestionsConcurrentDictionary.GetOrAdd((int)rowIndex, rowSuggestions); }); //Order the row suggestions by rowIndex suggestionsToReturn.RowSuggestions.AddRange(rowSuggestionsConcurrentDictionary.OrderBy(kvp => kvp.Key).Select(kvp => kvp.Value)); //Only add distinct Clients var distinctClients = clients.Distinct(); suggestionsToReturn.Clients.AddRange(distinctClients.Select(dc => dc.Value)); //Only add distinct Locations var distinctLocations = locations.Distinct(); suggestionsToReturn.Locations.AddRange(distinctLocations.Select(dl => dl.Value)); //Only add distinct ContactInfo var distinctContactInfo = contactInfoSets.Select(ci => ci.Value).Distinct(); suggestionsToReturn.ContactInfoSet.AddRange(distinctContactInfo); return suggestionsToReturn; }