1- using CrawlFeaturizer . Model ;
2- using CrawlFeaturizer . Util ;
1+ using Azure ;
2+ using Azure . AI . TextAnalytics ;
3+ using CrawlFeaturizer . Model ;
34using System . Collections . Generic ;
45using System . Linq ;
56using System . Threading . Tasks ;
@@ -13,11 +14,11 @@ namespace CrawlFeaturizer.ActionFeaturizer
1314 /// </summary>
1415 public class CognitiveTextAnalyticsFeaturizer : IActionFeaturizer
1516 {
16- private CognitiveTextAnalyzer cognitiveTextAnalyzer = null ;
17+ private readonly TextAnalyticsClient textAnalyticsClient = null ;
1718
18- internal CognitiveTextAnalyticsFeaturizer ( CognitiveTextAnalyzer cognitiveTextAnalyzer )
19+ internal CognitiveTextAnalyticsFeaturizer ( TextAnalyticsClient textAnalyticsClient )
1920 {
20- this . cognitiveTextAnalyzer = cognitiveTextAnalyzer ;
21+ this . textAnalyticsClient = textAnalyticsClient ;
2122 }
2223
2324 /// <summary>
@@ -32,15 +33,15 @@ await Task.WhenAll(actions.Select(async a =>
3233 string content = $ "{ metadata . Title ?? string . Empty } { metadata . Description ?? string . Empty } ";
3334
3435 // Get key phrases from the article title and description
35- IReadOnlyCollection < string > keyPhrases = await cognitiveTextAnalyzer . GetKeyPhrasesAsync ( content ) ;
36+ Response < KeyPhraseCollection > keyPhrases = await textAnalyticsClient . ExtractKeyPhrasesAsync ( content ) ;
3637
3738 // Create a dictionary of key phrases (with a constant values) since at this time we do not support list of strings features.
38- var keyPhrasesWithConstValues = keyPhrases . ToDictionary ( x => x , x => 1 ) ;
39+ var keyPhrasesWithConstValues = keyPhrases . Value . ToDictionary ( x => x , x => 1 ) ;
3940 a . Features . Add ( new { keyPhrases = keyPhrasesWithConstValues } ) ;
4041
4142 // Get sentiment score for the article
42- double ? sentiment = await cognitiveTextAnalyzer . GetSentimentAsync ( content ) ;
43- a . Features . Add ( new { sentiment } ) ;
43+ DocumentSentiment sentiment = await textAnalyticsClient . AnalyzeSentimentAsync ( content ) ;
44+ a . Features . Add ( new { sentiment . ConfidenceScores } ) ;
4445 }
4546 ) ) ;
4647 }
0 commit comments