public IList <string> GetAnagrams(string[] input) { var counter = 0; _maxResultAmount = MaxResultAmount(); var wordList = _wordRepository.GetDictionary(null); foreach (string splitWord in input) { var currentWord = string.Concat(splitWord.ToLower().OrderBy(c => c)); if (wordList.ContainsKey(currentWord)) { foreach (string s in wordList[currentWord]) { finalList.Add(s); // adds every anagram from the list } counter += wordList[currentWord].Count(); // counting how many words being output } else { Console.WriteLine("No such word(s) found."); return(finalList); } if (counter >= _maxResultAmount) { Console.WriteLine("Maximum result amount exceeded"); finalList.Add("MAXWORDSREACHED"); return(finalList); } } return(finalList); }
public async Task <IActionResult> Get(string language) { string accessToken = await HttpContext.GetToken(); var session = await sessionService.GetSession(accessToken); if (session == null) { return(Unauthorized(new { message = "Session expired. Please login again." })); } try { var res = await wordRepository.GetDictionary(language); return(Ok(res)); } catch (Exception ex) { await log.ErrorAsync("Error in wordRepository.GetDictionary()", ex); return(BadRequest(new { title = ex.GetType().ToString(), details = ex.StackTrace, message = ex.Message })); } }
public async Task <ILexicon> GetDictionary(string language) { return(await wordRepository.GetDictionary(language)); }