Skip to content

Commit 57bd557

Browse files
author
Alex P
committed
Added analyzers_example.go
1 parent 3951735 commit 57bd557

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ A very simple Go package for utilizing Microsoft Azure's Text Analysis Cognitive
1010
1. Dynamic intake and hashing of document(s) supported by error feedback
1111
2. Each API call required structures in documentation
1212
3. Each API call passing back errors instead of breaking on `log.Fatal`
13-
4. Add analyzers_example.go
13+
4. ~~Add analyzers_example.go~~

analyzers_example.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package main
2+
3+
import (
4+
"azuretextanalysis"
5+
"html/template"
6+
"net/http"
7+
)
8+
9+
var (
10+
api string = ""
11+
resource string = ""
12+
documents = []map[string]string{
13+
{"id": "1", "language": "en", "text": "This is a super cool test for my super cool package."},
14+
{"id": "2", "language": "en", "text": "This is a stupid test for my stupid package."},
15+
{"id": "3", "language": "en", "text": "The DoD is a very big operation compared to Banner Health."},
16+
{"id": "4", "language": "en", "text": "I really like CostCo chicken nuggets and German beer."},
17+
}
18+
)
19+
20+
// tmpl is the HTML template that drives the user interface.
21+
var tmpl = template.Must(template.New("tmpl").Parse(`
22+
<!DOCTYPE html>
23+
<html>
24+
<body>
25+
<center>
26+
<h1>Analyze</h1>
27+
<h2>{{.}}</h2>
28+
</center></body></html>
29+
`))
30+
31+
func main() {
32+
33+
// Run Entities at `localhost:8080/entities`
34+
http.HandleFunc("/entities", func(w http.ResponseWriter, r *http.Request) {
35+
data := azuretextanalysis.Entities(api, resource, documents)
36+
37+
err := tmpl.Execute(w, data)
38+
if err != nil {
39+
http.Error(w, err.Error(), http.StatusInternalServerError)
40+
}
41+
})
42+
43+
// Run Phrases at `localhost:8080/phrases`
44+
http.HandleFunc("/phrases", func(w http.ResponseWriter, r *http.Request) {
45+
data := azuretextanalysis.Phrases(api, resource, documents)
46+
47+
err := tmpl.Execute(w, data)
48+
if err != nil {
49+
http.Error(w, err.Error(), http.StatusInternalServerError)
50+
}
51+
})
52+
53+
// Run Language at `localhost:8080/language`
54+
http.HandleFunc("/language", func(w http.ResponseWriter, r *http.Request) {
55+
data := azuretextanalysis.Language(api, resource, documents)
56+
57+
err := tmpl.Execute(w, data)
58+
if err != nil {
59+
http.Error(w, err.Error(), http.StatusInternalServerError)
60+
}
61+
})
62+
63+
// Run Sentiment at `localhost:8080/sentiment`
64+
http.HandleFunc("/sentiment", func(w http.ResponseWriter, r *http.Request) {
65+
data := azuretextanalysis.Sentiment(api, resource, documents)
66+
67+
err := tmpl.Execute(w, data)
68+
if err != nil {
69+
http.Error(w, err.Error(), http.StatusInternalServerError)
70+
}
71+
})
72+
73+
// Start listener
74+
http.ListenAndServe(":8080", nil)
75+
}

0 commit comments

Comments
 (0)