public async Task <(AnnotatedText, Dictionary <string, WordInfo>)> AnnotateParagraph(string text)
        {
            var annotatedText = await _stanfordNLpClient.AnnotateTextAsync(text);

            var words = annotatedText.Sentences.SelectMany(s => s.Tokens.Select(t => t.lemma)).Distinct();

            var lemmaTasks = words.Select(lemma => (lemma, _wordsAPIClient.GetWordInfoAsync <Everything>(lemma))).ToList();

            await Task.WhenAll(lemmaTasks.Select(lt => lt.Item2));

            var dict = lemmaTasks.Select(lt => (lt.lemma, lt.Item2.Result)).ToDictionary(kv => kv.lemma, kv => WordInfoFromEverything(kv.Result));

            return(annotatedText, dict);
        }
示例#2
0
 public Task <AnnotatedText> AnnotateTextAsync(string text) =>
 client.AnnotateTextAsync(text);