How to Part-of-Speech Tag a String of Text in Go
Whether you’re creating a parse tree or simply interested in grammar, our Part-of-Speech (POS) tagger API can do the trick. You can include this iteration of our NLP API into your Golang project using the code snippets provided below directly from our API console (Cloudmersive API Console). Each word from your input text string will be returned with its corresponding part-of-speech tag below it in JSON format.
To take advantage of this API in Go, use the below code:
package mainimport (
"fmt"
"strings"
"net/http"
"io/ioutil"
)func main() {url := "https://api.cloudmersive.com/nlp-v2/pos/tag/sentence"
method := "POST"payload := strings.NewReader("InputText=%3Cstring%3E")client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
If this is your first time using a Cloudmersive API, head to our website to get your API key first. You can select whichever account option works best for you, including a free-tier option with a limit of 800 API calls per month (with zero financial commitments).