go_sdk

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2021 License: MIT Imports: 6 Imported by: 0

README

Go nocodeapi.net SDK

Installation

go get -u bitbucket.org/zeusakm/go_sdk

Key phrases

godotenv.Load()
client = NewClient(config.NewConfig(os.Getenv("DEV_JWT_TOKEN")))

res, err := client.GetKeyPhrases("Now, as a nation, we don't promise equal outcomes, but we were founded on the idea everybody should have an equal opportunity to succeed. No matter who you are, what you look like, where you come from, you can make it. That's an essential promise.", "en_US")

res.LanguageCode // en_US

res.KeyPhrases // slice of []KeyPhrase
/**
    []entity.KeyPhrase{
        {
            "Text": "promise equal outcomes",
            "Score": 8,
            "BeginOffset": 27,
            "EndOffset": 49
        },
        {
            "Text": "equal opportunity",
            "Score": 4.5,
            "BeginOffset": 108,
            "EndOffset": 125
        },
        {
            "Text": "essential promise",
            "Score": 4.5,
            "BeginOffset": 229,
            "EndOffset": 246
        },
        {
            "Text": "nation",
            "Score": 1,
            "BeginOffset": 10,
            "EndOffset": 16
        },
        {
            "Text": "founded",
            "Score": 1,
            "BeginOffset": 63,
            "EndOffset": 70
        },
        {
            "Text": "idea",
            "Score": 1,
            "BeginOffset": 78,
            "EndOffset": 82
        },
        {
            "Text": "succeed",
            "Score": 1,
            "BeginOffset": 129,
            "EndOffset": 136
        },
        {
            "Text": "matter",
            "Score": 1,
            "BeginOffset": 141,
            "EndOffset": 147
        },
        {
            "Text": "make",
            "Score": 1,
            "BeginOffset": 210,
            "EndOffset": 214
        },
        {
            "Text": "america",
            "Score": 1,
            "BeginOffset": false,
            "EndOffset": 7
        },
        {
            "Text": "start",
            "Score": 1,
            "BeginOffset": 269,
            "EndOffset": 274
        },
        {
            "Text": "determine",
            "Score": 1,
            "BeginOffset": 286,
            "EndOffset": 295
        },
        {
            "Text": "end",
            "Score": 1,
            "BeginOffset": 306,
            "EndOffset": 309
        },
        {
            "Text": "read",
            "Score": 1,
            "BeginOffset": false,
            "EndOffset": 4
        }
    }
**/

Language Detection

res, err := client.GetLanguageDetection("Policjanci otrzymali zgłoszenie w tej sprawie po godz 9. Do wypadku doszło na ul. Kolonia Krakowskie Przedmieście.")

res.LanguageCode // pl  
res.Language // Polish
res.Score // float64(1)

Sentiment Analysis

res, err := client.GetEmotions("Genuine leather is the best production for bags imho, but I would not recommend this particular product.")

res.Positive // 0.12
res.Negative // 0.14
res.Neutral // 9.74
res.Mixed // 9.97

Custom Classification

// creating classification
res, err := client.CreateClassification("anxious_customer", "I was horrified to see that little to no social distancing practices were being followed. American claims that they enforce a policy where customers are required to wear masks throughout their flight. The woman next to me was not wearing a mask throughout the duration of the flight. She was not eating or drinking, and was otherwise capable of wearing one. The flight attendant walked by multiple times and even had a conversation with the woman, but from what I could hear never told her to wear her mask. There were several other people in the rows around me not wearing masks either. I found this ironic because American kept announcing that they had a mask policy before we got on the flight. There were many people who were also wearing masks around their chins or in other improper fashions. My flight was also very close to full capacity. I know that other airlines are at least skipping seats between customers to try and stick to CDC recommendations, but almost everyone was shoulder to shoulder with someone else. I felt very unsafe and anxious during the whole flight, especially because I was in such close proximity to those people not wearing masks. I will not be flying American again.")

fmt.Println(res) // true

// getting classification
resClassification, err := client.GetClassification("My flight was also very close to full capacity. I know that other airlines are at least skipping seats between customers to try and stick to CDC recommendations, but almost everyone was shoulder to shoulder with someone else. I felt very unsafe and anxious during the whole flight, especially because I was in such close proximity to those people not wearing masks. I will not be flying American again.")

fmt.Println(resClassification.Label) // anxious_customer

// update
res, err = client.UpdateClassification("anxious_customer3", "I was horrified to see that little to no social distancing practices were being followed. American claims that they enforce a policy where customers are required to wear masks throughout their flight. The woman next to me was not wearing a mask throughout the duration of the flight. She was not eating or drinking, and was otherwise capable of wearing one. The flight attendant walked by multiple times and even had a conversation with the woman, but from what I could hear never told her to wear her mask. There were several other people in the rows around me not wearing masks either. I found this ironic because American kept announcing that they had a mask policy before we got on the flight. There were many people who were also wearing masks around their chins or in other improper fashions. My flight was also very close to full capacity. I know that other airlines are at least skipping seats between customers to try and stick to CDC recommendations, but almost everyone was shoulder to shoulder with someone else. I felt very unsafe and anxious during the whole flight, especially because I was in such close proximity to those people not wearing masks. I will not be flying American again. Foo Bar Baz")

fmt.Println(res) // true

// delete
res, err = client.DeleteClassification("anxious_customer") // true/false

Named Entity Recognition

res, err := client.GetNamedEntities("Linus Torvalds is one of the best programmers in USA, Finland Helsinki and in the world")

fmt.Println(res.EntitiesCount) // int64(3)

fmt.Println(res.Entities) 
/**
[]entity.Entity{{
		Text: "Linus Torvalds",
		Label: "PERSON",
	},
	{
		Text: "USA",
		Label: "GPE",
	},
	{
		Text: "Finland Helsinki",
		Label: "GPE",
	}}
**/

Documentation

Index

Constants

View Source
const (
	ApiKeyPhrases        = "key-phrases"
	ApiLanguageDetection = "language-detection"
	ApiEmotionsDetection = "emotions"
	ApiClassification    = "classification"
	ApiClassify          = "classify"
	ApiNamedEntity       = "named-entity-recognition"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Config     *config.Config
	HttpClient *http.Client
}

func NewClient

func NewClient(config *config.Config) *Client

func (*Client) Classify

func (c *Client) Classify(text string) (*entity.Classification, error)

Classify analyses the text and match it to previously created classification

func (*Client) CreateClassification

func (c *Client) CreateClassification(label, text string) (bool, error)

CreateClassification creates custom classification linked to label

func (*Client) DeleteClassification

func (c *Client) DeleteClassification(label string) (bool, error)

DeleteClassification deletes previously stored classification

func (*Client) Emotions

func (c *Client) Emotions(text string) (*entity.Emotions, error)

Emotions analyses 4 different types of emotions of a text

func (*Client) KeyPhrases

func (c *Client) KeyPhrases(text string, lang string) (*entity.KeyPhrases, error)

KeyPhrases splits the text into key-phrases

func (*Client) LanguageDetect

func (c *Client) LanguageDetect(text string) (*entity.Language, error)

LanguageDetect detects language by text and returns its code, name and score

func (*Client) NamedEntities

func (c *Client) NamedEntities(text string) (*entity.Ner, error)

NamedEntities gets named entities recognized in text provided to function as argument

func (*Client) UpdateClassification

func (c *Client) UpdateClassification(label, text string) (bool, error)

UpdateClassification updates previously created classification text by label

type Sender

type Sender interface {
	GetKeyPhrases() (*entity.KeyPhrases, error)
	GetLanguageDetection(text string) (*entity.Language, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL