-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
72 lines (56 loc) · 1.79 KB
/
main.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"encoding/json"
"fmt"
"log"
"time"
meaningcloudgo "github.com/henomis/meaningcloud-go"
"github.com/henomis/meaningcloud-go/pkg/request"
)
const Key = "YOUR_API_KEY"
func main() {
meaningCloudClient := meaningcloudgo.New(
meaningcloudgo.MeaningCloudEndpoint,
Key,
10*time.Second,
)
request := &request.Summarization{}
request.Text = `Robert Downey Jr has topped Forbes magazine's annual list of the highest paid actors for the second
year in a row. The 49-year-old star of the Iron Man and Avengers films made an estimated $75m over the past year,
beating rivals Dwayne Johnson, Bradley Cooper, Chris Hemsworth and Leonardo DiCaprio.`
request.Sentences = "5"
// Text analysis
response, err := meaningCloudClient.Summarization(request)
if err != nil {
log.Fatalf("error while performing analysis: %v", err)
}
if !response.Status.IsSuccess() {
log.Fatalf("error: %s", response.Status.Error())
}
bytes, _ := json.MarshalIndent(response, "", " ")
fmt.Println(string(bytes))
// URL analysis
request.Text = ""
request.URL = "https://en.wikipedia.org/wiki/Star_Trek"
response, err = meaningCloudClient.Summarization(request)
if err != nil {
log.Fatalf("error while performing analysis: %v", err)
}
if !response.Status.IsSuccess() {
log.Fatalf("error: %s", response.Status.Error())
}
bytes, _ = json.MarshalIndent(response, "", " ")
fmt.Println(string(bytes))
// File analysis
request.URL = ""
request.Document = "./examples/resources/file.txt"
response, err = meaningCloudClient.Summarization(request)
if err != nil {
log.Fatalf("error while performing analysis: %v", err)
}
if !response.Status.IsSuccess() {
log.Fatalf("error: %s", response.Status.Error())
}
bytes, _ = json.MarshalIndent(response, "", " ")
fmt.Println(string(bytes))
}