まだまだありますAWSSDK のサンプルは以下にあります。AWSドキュメント SDK サンプル
翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
Amazon Comprehend を使用してドキュメントのセンチメントを検出するにはAWSSDK
以下のコード例は、Amazon Comprehend を使用してドキュメントのセンチメントを検出する方法を示しています。
アクション例は、より大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。次のコード例で、このアクションのコンテキストを確認できます。
- .NET
-
- AWS SDK for .NET
-
注記
にはまだまだありますGitHub。用例一覧を検索し、AWS コード例リポジトリ
での設定と実行の方法を確認してください。 using System; using System.Threading.Tasks; using Amazon.Comprehend; using Amazon.Comprehend.Model; /// <summary> /// This example shows how to detect the overall sentiment of the supplied /// text using the Amazon Comprehend service. The example was writing using /// the AWS SDK for .NET version 3.7 and .NET Core 5.0. /// </summary> public static class DetectSentiment { /// <summary> /// This method calls the DetetectSentimentAsync method to analyze the /// supplied text and determine the overal sentiment. /// </summary> public static async Task Main() { string text = "It is raining today in Seattle"; var comprehendClient = new AmazonComprehendClient(Amazon.RegionEndpoint.USWest2); // Call DetectKeyPhrases API Console.WriteLine("Calling DetectSentiment"); var detectSentimentRequest = new DetectSentimentRequest() { Text = text, LanguageCode = "en", }; var detectSentimentResponse = await comprehendClient.DetectSentimentAsync(detectSentimentRequest); Console.WriteLine($"Sentiment: {detectSentimentResponse.Sentiment}"); Console.WriteLine("Done"); } }
-
API の詳細については、を参照してください。DetectSentimentにAWS SDK for .NETAPI リファレンス。
-
- Java
-
- SDK for Java 2.x
-
注記
にはまだまだあります。GitHub。用例一覧を検索し、AWS コード例リポジトリ
での設定と実行の方法を確認してください。 public static void detectSentiments(ComprehendClient comClient, String text){ try { DetectSentimentRequest detectSentimentRequest = DetectSentimentRequest.builder() .text(text) .languageCode("en") .build(); DetectSentimentResponse detectSentimentResult = comClient.detectSentiment(detectSentimentRequest); System.out.println("The Neutral value is " +detectSentimentResult.sentimentScore().neutral() ); } catch (ComprehendException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
-
API の詳細については、を参照してください。DetectSentimentにAWS SDK for Java 2.xAPI リファレンス。
-
- Python
-
- SDK for Python (Boto3)
-
注記
にはまだまだありますGitHub。用例一覧を検索し、AWS コード例リポジトリ
での設定と実行の方法を確認してください。 class ComprehendDetect: """Encapsulates Comprehend detection functions.""" def __init__(self, comprehend_client): """ :param comprehend_client: A Boto3 Comprehend client. """ self.comprehend_client = comprehend_client def detect_sentiment(self, text, language_code): """ Detects the overall sentiment expressed in a document. Sentiment can be positive, negative, neutral, or a mixture. :param text: The document to inspect. :param language_code: The language of the document. :return: The sentiments along with their confidence scores. """ try: response = self.comprehend_client.detect_sentiment( Text=text, LanguageCode=language_code) logger.info("Detected primary sentiment %s.", response['Sentiment']) except ClientError: logger.exception("Couldn't detect sentiment.") raise else: return response
-
API の詳細については、を参照してください。DetectSentimentにAWSPython (ボト3) 用 SDK API リファレンス。
-
文書内の主要言語を検出
ドキュメント分類ジョブを一覧表示