forked from xinyunh0929/golang-samples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathentity_sentiment.go
34 lines (28 loc) · 889 Bytes
/
entity_sentiment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2017 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package main
import (
"log"
"golang.org/x/net/context"
language "cloud.google.com/go/language/apiv1beta2"
languagepb "google.golang.org/genproto/googleapis/cloud/language/v1beta2"
)
func betaClient() *language.Client {
ctx := context.Background()
client, err := language.NewClient(ctx)
if err != nil {
log.Fatal(err)
}
return client
}
func analyzeEntitySentiment(ctx context.Context, client *language.Client, text string) (*languagepb.AnalyzeEntitySentimentResponse, error) {
return client.AnalyzeEntitySentiment(ctx, &languagepb.AnalyzeEntitySentimentRequest{
Document: &languagepb.Document{
Source: &languagepb.Document_Content{
Content: text,
},
Type: languagepb.Document_PLAIN_TEXT,
},
})
}