cognitiveservices

package
v0.0.0-...-57c00fc Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Example (CognitiveServicesSearch)

Example_cognitiveServicesSearch creates a resource group and a Cognitive Services account of type Search. Then it executes searches for web pages, images, videos, news and entities

accountName := randname.GenerateWithPrefix("azuresamplesgo", 10)

var groupName = config.GenerateGroupName("CognitiveServicesSearch")
config.SetGroupName(groupName)

ctx := context.Background()
defer resources.Cleanup(ctx)

_, err := resources.CreateGroup(ctx, config.GroupName())
if err != nil {
	util.LogAndPanic(err)
}

_, err = CreateCSAccount(accountName, "Bing.Search.v7")

if err != nil {
	util.LogAndPanic(err)
}

util.PrintAndLog("cognitive services search resource created")

searchWeb(accountName)
searchImages(accountName)
searchVideos(accountName)
searchNews(accountName)
searchEntities(accountName)
Output:

cognitive services search resource created
completed web search and got results
completed image search and got results
completed image search and got pivot suggestions
completed image search and got suggestions
completed image search and got query expansions
completed video search and got results
completed trending video search and got results
completed news search and got results
completed entity search and got results
Example (CognitiveServicesSpellCheck)

Example_cognitiveServicesSpellCheck creates a resource group and a Cognitive Services account of type spell check. Then it executes a spell check and inspects the corrections.

accountName := randname.GenerateWithPrefix("azuresamplesgo", 10)

var groupName = config.GenerateGroupName("CognitiveServicesSpellcheck")
config.SetGroupName(groupName)

ctx := context.Background()
defer resources.Cleanup(ctx)

_, err := resources.CreateGroup(ctx, config.GroupName())
if err != nil {
	util.LogAndPanic(err)
}

_, err = CreateCSAccount(accountName, "Bing.SpellCheck.v7")
if err != nil {
	util.LogAndPanic(err)
}
util.PrintAndLog("cognitive services spellcheck resource created")

spellCheckResult, err := SpellCheck(accountName)
if err != nil {
	util.LogAndPanic(err)
}

if len(*spellCheckResult.FlaggedTokens) > 0 {
	util.PrintAndLog("completed spell check and found corrections")

	firstFlaggedToken := (*spellCheckResult.FlaggedTokens)[0]
	log.Printf("Number of flagged tokens in the input: %v \n", len(*spellCheckResult.FlaggedTokens))
	log.Printf("First flagged token: %v \n", *firstFlaggedToken.Token)
	log.Printf("First flagged token error type: %v \n", firstFlaggedToken.Type)
	log.Printf("First flagged token suggestions count: %v \n", len(*firstFlaggedToken.Suggestions))
}
Output:

cognitive services spellcheck resource created
completed spell check and found corrections

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCSAccount

func CreateCSAccount(accountName string, accountKind string) (*cognitiveservices.Account, error)

CreateCSAccount creates a Cognitive Services account of the specified type

func CustomSearch

func CustomSearch(accountName string) (*customsearch.WebWebAnswer, error)

CustomSearch returns answers based on a custom search instance

func DetectLanguage

func DetectLanguage()

detects the language of a text document <languageDetection>

func ExtractEntities

func ExtractEntities()
identifies well-known entities in a text document

<entityRecognition>

func ExtractKeyPhrases

func ExtractKeyPhrases()

extracts key-phrases from a text document <keyPhrases>

func GetTextAnalyticsClient

func GetTextAnalyticsClient() textanalytics.BaseClient

<client>

func SearchEntities

func SearchEntities(accountName string) (*entitysearch.Entities, error)

SearchEntities retunrs a list of entities

func SearchImages

func SearchImages(accountName string) (imagesearch.Images, error)

SearchImages returns a list of images

func SearchNews

func SearchNews(accountName string) (newssearch.News, error)

SearchNews returns a list of news

func SearchVideos

func SearchVideos(accountName string) (videosearch.Videos, error)

SearchVideos returns a list of videos

func SearchWeb

func SearchWeb(accountName string) (*websearch.WebWebAnswer, error)

SearchWeb returns a web answer contains a list of web pages

func SentimentAnalysis

func SentimentAnalysis()

detects the sentiment of a set of text records <sentimentAnalysis>

func SpellCheck

func SpellCheck(accountName string) (spellcheck.SpellCheck, error)

SpellCheck spell checks the given input

func TrendingVideos

func TrendingVideos(accountName string) (videosearch.TrendingVideos, error)

TrendingVideos returns the videos that are trending

Types

This section is empty.

Jump to

Keyboard shortcuts

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