Getting Started with AYLIEN Text Analysis SDK for Go

Getting Started with AYLIEN Text Analysis SDK for Go

Last week’s getting started blog focused on the Python SDK. This week we’re going to focus on using the API with Go. This is the third in our series of blogs on getting started with AYLIEN’s various SDKs. You can access all our SDK repositories on here

If you are new to our API and Text Analysis in general and you don’t have an account you can go directly to the Getting Started page on the website which will take you through how to open an account. You can choose a free plan to get started, which allows you to make up to 1,000 calls per day to the API for free.

Downloading and Installing the Go SDK

The simplest way to install the repository is with “go get”. Simply type the following from a command line tool.

$ go get

Utilizing the SDK with your AYLIEN credentials

Once you’ve subscribed to our API and have downloaded the SDK you can start making calls by adding the following code to your go program.

import (
textapi ""
auth := textapi.Auth{"YOUR_APP_ID ", "YOUT_APP_KEY"}
client, err := textapi.NewClient(auth, true)
if err != nil {

When calling the API you can specify whether you wish to analyze a piece of text directly for a URL linking to the text or article you wish to analyze.

Language Detection

We’re going to first showcase the Language Detection endpoint by analyzing the following sentence “What language is this sentence written in?“ By using the following piece of code.

languageParams := &textapi.LanguageParams{Text: "What language is this sentence written in?"}
lang, err := client.Language(languageParams)
if err != nil {
fmt.Printf("nLanguage Detection Resultsn")
fmt.Printf("Text            :   %sn", lang.Text)
fmt.Printf("Language        :   %sn", lang.Language)
fmt.Printf("Confidence      :   %fnn", lang.Confidence)

You should receive an output very similar to the one shown below, which shows, the language detected was English and the confidence that it was detected correctly (a number between 0 and 1) is very close to 1 which means you can be pretty sure it is correct.

Language Detection Results

Text            :   What language is this sentence written in?
Language        :   en
Confidence      :   0.999997

Sentiment Analysis

Next we’ll look at analyzing the following short piece of text “John is a very good football player” to determine it’s sentiment i.e. if it’s positive, neutral or negative.

sentimentParams := &textapi.SentimentParams{Text: "John is a very good football player!"}
sentiment, err := client.Sentiment(sentimentParams)
if err != nil {
fmt.Printf("Sentiment Analysis Resultsn")
fmt.Printf("Text            :   %sn", sentiment.Text)
fmt.Printf("Sentiment Polarity  :   %sn", sentiment.Polarity)
fmt.Printf("Polarity Confidence  :   %fn", sentiment.PolarityConfidence)
fmt.Printf("Subjectivity  : %sn", sentiment.Subjectivity)
fmt.Printf("Subjectivity Confidence  :   %fnn", sentiment.SubjectivityConfidence)

You should receive an output similar to the one shown below which indicates that the sentence is objective and is positive, both with a high degree of confidence.

Sentiment Analysis Results

Text            :   John is a very good football player!
Sentiment Polarity  :   positive
Polarity Confidence  :   0.999999
Subjectivity  : objective
Subjectivity Confidence  :   0.989682

Article Classification

AYLIEN’s Classification endpoint automatically assigns an article or piece of text to one or more categories, making it easier to manage and sort. The classification is based on IPTC International Subject News Codes and can identify up to 500 categories. The code below analyses a BBC news article about a one ton pumpkin ;).

classifyParams := &textapi.ClassifyParams{URL: ""}
class, err := client.Classify(classifyParams)
if err != nil {
fmt.Printf("Classification Analysis Resultsn")
for _, v := range class.Categories {
fmt.Printf("Classification Label        :   %sn", v.Label)
fmt.Printf("Classification Code         :   %sn", v.Code)
fmt.Printf("Classification Confidence   :   %fnn", v.Confidence)

When you run this code you should receive an output similar to that shown below which assigns the article an IPTC label of “natural science – biology” with an IPTC code of 13004008.

Classification Results

Classification Label        :   natural science - biology
Classification Code         :   13004008
Classification Confidence   :   0.929754

Hashtag Suggestion

Next, we’ll have a look at analyzing the same BBC article and extracting hashtag suggestions for it.

hashtagsParams := &textapi.HashtagsParams{URL:
hashtags, err := client.Hashtags(hashtagsParams)
if err != nil {
fmt.Printf("Hashtag Suggestion Resultsn")
for _, v := range hashtags.Hashtags {
fmt.Printf("%sn", v)

You should receive an output similar to the one below.


Hashtag Suggestion Results

If Go isn’t your weapon of choice then check out our SDKs for node.js, Ruby, PHP, Python, Java and .Net (C#). For more information regarding our API go to the documentation section of our website.

We will be publishing ‘getting started’ blogs for the remaining languages over the coming weeks so keep an eye out for them.

Let's Talk