Created
April 3, 2018 06:58
-
-
Save brydavis/ef5ea6e87a1c49902e27b7a7450162a9 to your computer and use it in GitHub Desktop.
Example of AWS Comprehend with Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/comprehend" | |
) | |
func main() { | |
// Create Session | |
// sess := session.Must(session.NewSession()) | |
// Create a Session with a custom region | |
sess := session.Must(session.NewSession(&aws.Config{ | |
Region: aws.String("us-east-1"), | |
})) | |
// Create a Comprehend client from just a session. | |
client := comprehend.New(sess) | |
// Create a Comprehend client with additional configuration | |
// client := comprehend.New(sess, aws.NewConfig().WithRegion("us-west-2")) | |
// Example sending a request using the DetectSentimentRequest method. | |
listTexts := []string{ | |
"Type something here... keep going", | |
"Type something here... keep going", | |
"Type something here... keep going", | |
"Type something here... keep going", | |
"Type something here... keep going", | |
} | |
for _, text := range listTexts { | |
fmt.Println("\n\n") | |
fmt.Println(text) | |
{ | |
params := comprehend.DetectSentimentInput{} | |
params.SetLanguageCode("en") | |
params.SetText(text) | |
req, resp := client.DetectSentimentRequest(¶ms) | |
err := req.Send() | |
if err == nil { // resp is now filled | |
// fmt.Println(*resp.Sentiment) | |
fmt.Println(*resp) | |
} else { | |
fmt.Println(err) | |
} | |
} | |
{ | |
params := comprehend.DetectEntitiesInput{} | |
params.SetLanguageCode("en") | |
params.SetText(text) | |
req, resp := client.DetectEntitiesRequest(¶ms) | |
err := req.Send() | |
if err == nil { // resp is now filled | |
// fmt.Println(*resp.Sentiment) | |
fmt.Println(*resp) | |
} else { | |
fmt.Println(err) | |
} | |
} | |
{ | |
params := comprehend.DetectKeyPhrasesInput{} | |
params.SetLanguageCode("en") | |
params.SetText(text) | |
req, resp := client.DetectKeyPhrasesRequest(¶ms) | |
err := req.Send() | |
if err == nil { // resp is now filled | |
// fmt.Println(*resp.Sentiment) | |
fmt.Println(*resp) | |
} else { | |
fmt.Println(err) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment