public async Task <IEnumerable <SwedishDictionaryWord> > GetDictionaryResult(string word) { _logger.Debug("Getting online dictionary page for word {word}", word); var serviceResult = await _http.GetStringAsync(dictionaryServiceLocation + word.ToLower()); var doc = new HtmlDocument(); doc.LoadHtml(serviceResult); var dictionaryResults = doc.DocumentNode.Descendants().Where(x => x.Name == "p") .Where(x => x.FirstChild.Name == "img" && x.FirstChild.Attributes.Any(a => a.Name == "src" && a.Value.EndsWith("sv.png"))); var dictionaryEntries = new List <SwedishDictionaryWord>(); foreach (var dictionaryResult in dictionaryResults) { try { var baseWord = GetBaseWord(dictionaryResult); var dictionaryWord = new SwedishDictionaryWord( baseWord.InnerText, GetWordClass(baseWord), GetPronunciation(dictionaryResult), GetInflictions(dictionaryResult), GetSynonyms(dictionaryResult), GetWordDefinition(dictionaryResult), GetWordExample(dictionaryResult), GetWordComposition(dictionaryResult), GetWordDepartment(dictionaryResult) ); dictionaryEntries.Add(dictionaryWord); } catch (InvalidOperationException e) { _logger.Information(e, "Failed to parse dictionary entry"); } } return(dictionaryEntries); }
public async Task AddWordToDictionary(string word) { var dictionaryEntry = new SwedishDictionaryWord(word, null, null, new List <SwedishWordInflection>(), new List <string>(), null, null, null, null); await _localDictionary.SaveWordResult(new[] { dictionaryEntry }, word); }