Perform Sentiment Analysis and Classification on Text in Go

Sometimes our own biases & preconceived notions make it difficult to aptly judge content. Thank goodness there’s an API for that: you can find out if input text is positive, negative or neutral with the Sentiment Analysis & Classification iteration of our Natural Language Processing API. Use code examples below to integrate this API into your Go project, or head to the Cloudmersive API Console to find code in 13 different programming languages for your convenience.

Copy in the following if you’re working in Go, and include your API key (easily attainable by making a free account on www.cloudmersive.com) and text string where indicated:

package main
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/nlp-v2/analytics/sentiment"
method := "POST"
payload := strings.NewReader("TextToAnalyze=%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))
}

--

--

--

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

AWSIoT with Raspberry Pi using Paho MQTT

Rolling Under Obstacles

Encode x Internet Computer: Intro to Building on the IC in Rust [Video + Slides]

AWS Case Study_ McDonald’s Home Delivery

Creating a Homing Projectile for our 2D Galaxy Shooter in Unity-Part 02!

As developers, we also and foremost are users

2 Effective Methods to Batch Delete All Outlook Rules Performing a Specific Action

How to split a single PowerPoint presentation PPTX into separate slides in Python

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

More from Medium

Parse String to Syntax Tree (Penn Treebank) in Python

Email Spam Detection using NLP

OCR is Optical Character Recognition, which defines the process of converting scanned documents or…

Build A Custom NER Pipeline With Hugging Face