language

package
v0.138.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Overview

Package language provides access to the Cloud Natural Language API.

This package is DEPRECATED. Use package cloud.google.com/go/language/apiv1 instead.

For product documentation, see: https://cloud.google.com/natural-language/

Creating a client

Usage example:

import "google.golang.org/api/language/v2"
...
ctx := context.Background()
languageService, err := language.NewService(ctx)

In this example, Google Application Default Credentials are used for authentication.

For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.

Other authentication options

By default, all available scopes (see "Constants") are used to authenticate. To restrict scopes, use option.WithScopes:

languageService, err := language.NewService(ctx, option.WithScopes(language.CloudPlatformScope))

To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey:

languageService, err := language.NewService(ctx, option.WithAPIKey("AIza..."))

To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource:

config := &oauth2.Config{...}
// ...
token, err := config.Exchange(ctx, ...)
languageService, err := language.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))

See https://godoc.org/google.golang.org/api/option/ for details on options.

Index

Constants

View Source
const (
	// Apply machine learning models to reveal the structure and meaning of
	// text
	CloudLanguageScope = "https://www.googleapis.com/auth/cloud-language"

	// See, edit, configure, and delete your Google Cloud data and see the
	// email address for your Google Account.
	CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform"
)

OAuth2 scopes used by this API.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalyzeEntitiesRequest

type AnalyzeEntitiesRequest struct {
	// Document: Required. Input document.
	Document *Document `json:"document,omitempty"`

	// EncodingType: The encoding type used by the API to calculate offsets.
	//
	// Possible values:
	//   "NONE" - If `EncodingType` is not specified, encoding-dependent
	// information (such as `begin_offset`) will be set at `-1`.
	//   "UTF8" - Encoding-dependent information (such as `begin_offset`) is
	// calculated based on the UTF-8 encoding of the input. C++ and Go are
	// examples of languages that use this encoding natively.
	//   "UTF16" - Encoding-dependent information (such as `begin_offset`)
	// is calculated based on the UTF-16 encoding of the input. Java and
	// JavaScript are examples of languages that use this encoding natively.
	//   "UTF32" - Encoding-dependent information (such as `begin_offset`)
	// is calculated based on the UTF-32 encoding of the input. Python is an
	// example of a language that uses this encoding natively.
	EncodingType string `json:"encodingType,omitempty"`

	// ForceSendFields is a list of field names (e.g. "Document") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Document") to include in
	// API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

AnalyzeEntitiesRequest: The entity analysis request message.

func (*AnalyzeEntitiesRequest) MarshalJSON

func (s *AnalyzeEntitiesRequest) MarshalJSON() ([]byte, error)

type AnalyzeEntitiesResponse

type AnalyzeEntitiesResponse struct {
	// Entities: The recognized entities in the input document.
	Entities []*Entity `json:"entities,omitempty"`

	// LanguageCode: The language of the text, which will be the same as the
	// language specified in the request or, if not specified, the
	// automatically-detected language. See Document.language field for more
	// details.
	LanguageCode string `json:"languageCode,omitempty"`

	// LanguageSupported: Whether the language is officially supported. The
	// API may still return a response when the language is not supported,
	// but it is on a best effort basis.
	LanguageSupported bool `json:"languageSupported,omitempty"`

	// ServerResponse contains the HTTP response code and headers from the
	// server.
	googleapi.ServerResponse `json:"-"`

	// ForceSendFields is a list of field names (e.g. "Entities") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Entities") to include in
	// API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

AnalyzeEntitiesResponse: The entity analysis response message.

func (*AnalyzeEntitiesResponse) MarshalJSON

func (s *AnalyzeEntitiesResponse) MarshalJSON() ([]byte, error)

type AnalyzeSentimentRequest

type AnalyzeSentimentRequest struct {
	// Document: Required. Input document.
	Document *Document `json:"document,omitempty"`

	// EncodingType: The encoding type used by the API to calculate sentence
	// offsets.
	//
	// Possible values:
	//   "NONE" - If `EncodingType` is not specified, encoding-dependent
	// information (such as `begin_offset`) will be set at `-1`.
	//   "UTF8" - Encoding-dependent information (such as `begin_offset`) is
	// calculated based on the UTF-8 encoding of the input. C++ and Go are
	// examples of languages that use this encoding natively.
	//   "UTF16" - Encoding-dependent information (such as `begin_offset`)
	// is calculated based on the UTF-16 encoding of the input. Java and
	// JavaScript are examples of languages that use this encoding natively.
	//   "UTF32" - Encoding-dependent information (such as `begin_offset`)
	// is calculated based on the UTF-32 encoding of the input. Python is an
	// example of a language that uses this encoding natively.
	EncodingType string `json:"encodingType,omitempty"`

	// ForceSendFields is a list of field names (e.g. "Document") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Document") to include in
	// API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

AnalyzeSentimentRequest: The sentiment analysis request message.

func (*AnalyzeSentimentRequest) MarshalJSON

func (s *AnalyzeSentimentRequest) MarshalJSON() ([]byte, error)

type AnalyzeSentimentResponse

type AnalyzeSentimentResponse struct {
	// DocumentSentiment: The overall sentiment of the input document.
	DocumentSentiment *Sentiment `json:"documentSentiment,omitempty"`

	// LanguageCode: The language of the text, which will be the same as the
	// language specified in the request or, if not specified, the
	// automatically-detected language. See Document.language field for more
	// details.
	LanguageCode string `json:"languageCode,omitempty"`

	// LanguageSupported: Whether the language is officially supported. The
	// API may still return a response when the language is not supported,
	// but it is on a best effort basis.
	LanguageSupported bool `json:"languageSupported,omitempty"`

	// Sentences: The sentiment for all the sentences in the document.
	Sentences []*Sentence `json:"sentences,omitempty"`

	// ServerResponse contains the HTTP response code and headers from the
	// server.
	googleapi.ServerResponse `json:"-"`

	// ForceSendFields is a list of field names (e.g. "DocumentSentiment")
	// to unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "DocumentSentiment") to
	// include in API requests with the JSON null value. By default, fields
	// with empty values are omitted from API requests. However, any field
	// with an empty value appearing in NullFields will be sent to the
	// server as null. It is an error if a field in this list has a
	// non-empty value. This may be used to include null fields in Patch
	// requests.
	NullFields []string `json:"-"`
}

AnalyzeSentimentResponse: The sentiment analysis response message.

func (*AnalyzeSentimentResponse) MarshalJSON

func (s *AnalyzeSentimentResponse) MarshalJSON() ([]byte, error)

type AnnotateTextRequest

type AnnotateTextRequest struct {
	// Document: Required. Input document.
	Document *Document `json:"document,omitempty"`

	// EncodingType: The encoding type used by the API to calculate offsets.
	//
	// Possible values:
	//   "NONE" - If `EncodingType` is not specified, encoding-dependent
	// information (such as `begin_offset`) will be set at `-1`.
	//   "UTF8" - Encoding-dependent information (such as `begin_offset`) is
	// calculated based on the UTF-8 encoding of the input. C++ and Go are
	// examples of languages that use this encoding natively.
	//   "UTF16" - Encoding-dependent information (such as `begin_offset`)
	// is calculated based on the UTF-16 encoding of the input. Java and
	// JavaScript are examples of languages that use this encoding natively.
	//   "UTF32" - Encoding-dependent information (such as `begin_offset`)
	// is calculated based on the UTF-32 encoding of the input. Python is an
	// example of a language that uses this encoding natively.
	EncodingType string `json:"encodingType,omitempty"`

	// Features: Required. The enabled features.
	Features *Features `json:"features,omitempty"`

	// ForceSendFields is a list of field names (e.g. "Document") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Document") to include in
	// API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

AnnotateTextRequest: The request message for the text annotation API, which can perform multiple analysis types in one call.

func (*AnnotateTextRequest) MarshalJSON

func (s *AnnotateTextRequest) MarshalJSON() ([]byte, error)

type AnnotateTextResponse

type AnnotateTextResponse struct {
	// Categories: Categories identified in the input document.
	Categories []*ClassificationCategory `json:"categories,omitempty"`

	// DocumentSentiment: The overall sentiment for the document. Populated
	// if the user enables
	// AnnotateTextRequest.Features.extract_document_sentiment.
	DocumentSentiment *Sentiment `json:"documentSentiment,omitempty"`

	// Entities: Entities, along with their semantic information, in the
	// input document. Populated if the user enables
	// AnnotateTextRequest.Features.extract_entities or
	// AnnotateTextRequest.Features.extract_entity_sentiment.
	Entities []*Entity `json:"entities,omitempty"`

	// LanguageCode: The language of the text, which will be the same as the
	// language specified in the request or, if not specified, the
	// automatically-detected language. See Document.language field for more
	// details.
	LanguageCode string `json:"languageCode,omitempty"`

	// LanguageSupported: Whether the language is officially supported by
	// all requested features. The API may still return a response when the
	// language is not supported, but it is on a best effort basis.
	LanguageSupported bool `json:"languageSupported,omitempty"`

	// ModerationCategories: Harmful and sensitive categories identified in
	// the input document.
	ModerationCategories []*ClassificationCategory `json:"moderationCategories,omitempty"`

	// Sentences: Sentences in the input document. Populated if the user
	// enables AnnotateTextRequest.Features.extract_document_sentiment.
	Sentences []*Sentence `json:"sentences,omitempty"`

	// ServerResponse contains the HTTP response code and headers from the
	// server.
	googleapi.ServerResponse `json:"-"`

	// ForceSendFields is a list of field names (e.g. "Categories") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Categories") to include in
	// API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

AnnotateTextResponse: The text annotations response message.

func (*AnnotateTextResponse) MarshalJSON

func (s *AnnotateTextResponse) MarshalJSON() ([]byte, error)

type ClassificationCategory

type ClassificationCategory struct {
	// Confidence: The classifier's confidence of the category. Number
	// represents how certain the classifier is that this category
	// represents the given text.
	Confidence float64 `json:"confidence,omitempty"`

	// Name: The name of the category representing the document.
	Name string `json:"name,omitempty"`

	// ForceSendFields is a list of field names (e.g. "Confidence") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Confidence") to include in
	// API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

ClassificationCategory: Represents a category returned from the text classifier.

func (*ClassificationCategory) MarshalJSON

func (s *ClassificationCategory) MarshalJSON() ([]byte, error)

func (*ClassificationCategory) UnmarshalJSON

func (s *ClassificationCategory) UnmarshalJSON(data []byte) error

type ClassifyTextRequest

type ClassifyTextRequest struct {
	// Document: Required. Input document.
	Document *Document `json:"document,omitempty"`

	// ForceSendFields is a list of field names (e.g. "Document") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Document") to include in
	// API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

ClassifyTextRequest: The document classification request message.

func (*ClassifyTextRequest) MarshalJSON

func (s *ClassifyTextRequest) MarshalJSON() ([]byte, error)

type ClassifyTextResponse

type ClassifyTextResponse struct {
	// Categories: Categories representing the input document.
	Categories []*ClassificationCategory `json:"categories,omitempty"`

	// LanguageCode: The language of the text, which will be the same as the
	// language specified in the request or, if not specified, the
	// automatically-detected language. See Document.language field for more
	// details.
	LanguageCode string `json:"languageCode,omitempty"`

	// LanguageSupported: Whether the language is officially supported. The
	// API may still return a response when the language is not supported,
	// but it is on a best effort basis.
	LanguageSupported bool `json:"languageSupported,omitempty"`

	// ServerResponse contains the HTTP response code and headers from the
	// server.
	googleapi.ServerResponse `json:"-"`

	// ForceSendFields is a list of field names (e.g. "Categories") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Categories") to include in
	// API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

ClassifyTextResponse: The document classification response message.

func (*ClassifyTextResponse) MarshalJSON

func (s *ClassifyTextResponse) MarshalJSON() ([]byte, error)

type Document

type Document struct {
	// Content: The content of the input in string format. Cloud audit
	// logging exempt since it is based on user data.
	Content string `json:"content,omitempty"`

	// GcsContentUri: The Google Cloud Storage URI where the file content is
	// located. This URI must be of the form: gs://bucket_name/object_name.
	// For more details, see
	// https://cloud.google.com/storage/docs/reference-uris. NOTE: Cloud
	// Storage object versioning is not supported.
	GcsContentUri string `json:"gcsContentUri,omitempty"`

	// LanguageCode: Optional. The language of the document (if not
	// specified, the language is automatically detected). Both ISO and
	// BCP-47 language codes are accepted. Language Support
	// (https://cloud.google.com/natural-language/docs/languages) lists
	// currently supported languages for each API method. If the language
	// (either specified by the caller or automatically detected) is not
	// supported by the called API method, an `INVALID_ARGUMENT` error is
	// returned.
	LanguageCode string `json:"languageCode,omitempty"`

	// Type: Required. If the type is not set or is `TYPE_UNSPECIFIED`,
	// returns an `INVALID_ARGUMENT` error.
	//
	// Possible values:
	//   "TYPE_UNSPECIFIED" - The content type is not specified.
	//   "PLAIN_TEXT" - Plain text
	//   "HTML" - HTML
	Type string `json:"type,omitempty"`

	// ForceSendFields is a list of field names (e.g. "Content") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Content") to include in
	// API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

Document: Represents the input to API methods.

func (*Document) MarshalJSON

func (s *Document) MarshalJSON() ([]byte, error)

type DocumentsAnalyzeEntitiesCall

type DocumentsAnalyzeEntitiesCall struct {
	// contains filtered or unexported fields
}

func (*DocumentsAnalyzeEntitiesCall) Context

Context sets the context to be used in this call's Do method. Any pending HTTP request will be aborted if the provided context is canceled.

func (*DocumentsAnalyzeEntitiesCall) Do

Do executes the "language.documents.analyzeEntities" call. Exactly one of *AnalyzeEntitiesResponse or error will be non-nil. Any non-2xx status code is an error. Response headers are in either *AnalyzeEntitiesResponse.ServerResponse.Header or (if a response was returned at all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check whether the returned error was because http.StatusNotModified was returned.

func (*DocumentsAnalyzeEntitiesCall) Fields

Fields allows partial responses to be retrieved. See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more information.

func (*DocumentsAnalyzeEntitiesCall) Header

Header returns an http.Header that can be modified by the caller to add HTTP headers to the request.

type DocumentsAnalyzeSentimentCall

type DocumentsAnalyzeSentimentCall struct {
	// contains filtered or unexported fields
}

func (*DocumentsAnalyzeSentimentCall) Context

Context sets the context to be used in this call's Do method. Any pending HTTP request will be aborted if the provided context is canceled.

func (*DocumentsAnalyzeSentimentCall) Do

Do executes the "language.documents.analyzeSentiment" call. Exactly one of *AnalyzeSentimentResponse or error will be non-nil. Any non-2xx status code is an error. Response headers are in either *AnalyzeSentimentResponse.ServerResponse.Header or (if a response was returned at all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check whether the returned error was because http.StatusNotModified was returned.

func (*DocumentsAnalyzeSentimentCall) Fields

Fields allows partial responses to be retrieved. See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more information.

func (*DocumentsAnalyzeSentimentCall) Header

Header returns an http.Header that can be modified by the caller to add HTTP headers to the request.

type DocumentsAnnotateTextCall

type DocumentsAnnotateTextCall struct {
	// contains filtered or unexported fields
}

func (*DocumentsAnnotateTextCall) Context

Context sets the context to be used in this call's Do method. Any pending HTTP request will be aborted if the provided context is canceled.

func (*DocumentsAnnotateTextCall) Do

Do executes the "language.documents.annotateText" call. Exactly one of *AnnotateTextResponse or error will be non-nil. Any non-2xx status code is an error. Response headers are in either *AnnotateTextResponse.ServerResponse.Header or (if a response was returned at all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check whether the returned error was because http.StatusNotModified was returned.

func (*DocumentsAnnotateTextCall) Fields

Fields allows partial responses to be retrieved. See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more information.

func (*DocumentsAnnotateTextCall) Header

Header returns an http.Header that can be modified by the caller to add HTTP headers to the request.

type DocumentsClassifyTextCall

type DocumentsClassifyTextCall struct {
	// contains filtered or unexported fields
}

func (*DocumentsClassifyTextCall) Context

Context sets the context to be used in this call's Do method. Any pending HTTP request will be aborted if the provided context is canceled.

func (*DocumentsClassifyTextCall) Do

Do executes the "language.documents.classifyText" call. Exactly one of *ClassifyTextResponse or error will be non-nil. Any non-2xx status code is an error. Response headers are in either *ClassifyTextResponse.ServerResponse.Header or (if a response was returned at all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check whether the returned error was because http.StatusNotModified was returned.

func (*DocumentsClassifyTextCall) Fields

Fields allows partial responses to be retrieved. See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more information.

func (*DocumentsClassifyTextCall) Header

Header returns an http.Header that can be modified by the caller to add HTTP headers to the request.

type DocumentsModerateTextCall

type DocumentsModerateTextCall struct {
	// contains filtered or unexported fields
}

func (*DocumentsModerateTextCall) Context

Context sets the context to be used in this call's Do method. Any pending HTTP request will be aborted if the provided context is canceled.

func (*DocumentsModerateTextCall) Do

Do executes the "language.documents.moderateText" call. Exactly one of *ModerateTextResponse or error will be non-nil. Any non-2xx status code is an error. Response headers are in either *ModerateTextResponse.ServerResponse.Header or (if a response was returned at all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check whether the returned error was because http.StatusNotModified was returned.

func (*DocumentsModerateTextCall) Fields

Fields allows partial responses to be retrieved. See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more information.

func (*DocumentsModerateTextCall) Header

Header returns an http.Header that can be modified by the caller to add HTTP headers to the request.

type DocumentsService

type DocumentsService struct {
	// contains filtered or unexported fields
}

func NewDocumentsService

func NewDocumentsService(s *Service) *DocumentsService

func (*DocumentsService) AnalyzeEntities

func (r *DocumentsService) AnalyzeEntities(analyzeentitiesrequest *AnalyzeEntitiesRequest) *DocumentsAnalyzeEntitiesCall

AnalyzeEntities: Finds named entities (currently proper names and common nouns) in the text along with entity types, probability, mentions for each entity, and other properties.

func (*DocumentsService) AnalyzeSentiment

func (r *DocumentsService) AnalyzeSentiment(analyzesentimentrequest *AnalyzeSentimentRequest) *DocumentsAnalyzeSentimentCall

AnalyzeSentiment: Analyzes the sentiment of the provided text.

func (*DocumentsService) AnnotateText

func (r *DocumentsService) AnnotateText(annotatetextrequest *AnnotateTextRequest) *DocumentsAnnotateTextCall

AnnotateText: A convenience method that provides all features in one call.

func (*DocumentsService) ClassifyText

func (r *DocumentsService) ClassifyText(classifytextrequest *ClassifyTextRequest) *DocumentsClassifyTextCall

ClassifyText: Classifies a document into categories.

func (*DocumentsService) ModerateText

func (r *DocumentsService) ModerateText(moderatetextrequest *ModerateTextRequest) *DocumentsModerateTextCall

ModerateText: Moderates a document for harmful and sensitive categories.

type Entity

type Entity struct {
	// Mentions: The mentions of this entity in the input document. The API
	// currently supports proper noun mentions.
	Mentions []*EntityMention `json:"mentions,omitempty"`

	// Metadata: Metadata associated with the entity. For most entity types,
	// the metadata is a Wikipedia URL (`wikipedia_url`) and Knowledge Graph
	// MID (`mid`), if they are available. For the metadata associated with
	// other entity types, see the Type table below.
	Metadata map[string]string `json:"metadata,omitempty"`

	// Name: The representative name for the entity.
	Name string `json:"name,omitempty"`

	// Sentiment: For calls to AnalyzeEntitySentiment or if
	// AnnotateTextRequest.Features.extract_entity_sentiment is set to true,
	// this field will contain the aggregate sentiment expressed for this
	// entity in the provided document.
	Sentiment *Sentiment `json:"sentiment,omitempty"`

	// Type: The entity type.
	//
	// Possible values:
	//   "UNKNOWN" - Unknown
	//   "PERSON" - Person
	//   "LOCATION" - Location
	//   "ORGANIZATION" - Organization
	//   "EVENT" - Event
	//   "WORK_OF_ART" - Artwork
	//   "CONSUMER_GOOD" - Consumer product
	//   "OTHER" - Other types of entities
	//   "PHONE_NUMBER" - Phone number The metadata lists the phone number,
	// formatted according to local convention, plus whichever additional
	// elements appear in the text: * `number` - the actual number, broken
	// down into sections as per local convention * `national_prefix` -
	// country code, if detected * `area_code` - region or area code, if
	// detected * `extension` - phone extension (to be dialed after
	// connection), if detected
	//   "ADDRESS" - Address The metadata identifies the street number and
	// locality plus whichever additional elements appear in the text: *
	// `street_number` - street number * `locality` - city or town *
	// `street_name` - street/route name, if detected * `postal_code` -
	// postal code, if detected * `country` - country, if detected< *
	// `broad_region` - administrative area, such as the state, if detected
	// * `narrow_region` - smaller administrative area, such as county, if
	// detected * `sublocality` - used in Asian addresses to demark a
	// district within a city, if detected
	//   "DATE" - Date The metadata identifies the components of the date: *
	// `year` - four digit year, if detected * `month` - two digit month
	// number, if detected * `day` - two digit day number, if detected
	//   "NUMBER" - Number The metadata is the number itself.
	//   "PRICE" - Price The metadata identifies the `value` and `currency`.
	Type string `json:"type,omitempty"`

	// ForceSendFields is a list of field names (e.g. "Mentions") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Mentions") to include in
	// API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

Entity: Represents a phrase in the text that is a known entity, such as a person, an organization, or location. The API associates information, such as probability and mentions, with entities.

func (*Entity) MarshalJSON

func (s *Entity) MarshalJSON() ([]byte, error)

type EntityMention

type EntityMention struct {
	// Probability: Probability score associated with the entity. The score
	// shows the probability of the entity mention being the entity type.
	// The score is in (0, 1] range.
	Probability float64 `json:"probability,omitempty"`

	// Sentiment: For calls to AnalyzeEntitySentiment or if
	// AnnotateTextRequest.Features.extract_entity_sentiment is set to true,
	// this field will contain the sentiment expressed for this mention of
	// the entity in the provided document.
	Sentiment *Sentiment `json:"sentiment,omitempty"`

	// Text: The mention text.
	Text *TextSpan `json:"text,omitempty"`

	// Type: The type of the entity mention.
	//
	// Possible values:
	//   "TYPE_UNKNOWN" - Unknown
	//   "PROPER" - Proper name
	//   "COMMON" - Common noun (or noun compound)
	Type string `json:"type,omitempty"`

	// ForceSendFields is a list of field names (e.g. "Probability") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Probability") to include
	// in API requests with the JSON null value. By default, fields with
	// empty values are omitted from API requests. However, any field with
	// an empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

EntityMention: Represents a mention for an entity in the text. Currently, proper noun mentions are supported.

func (*EntityMention) MarshalJSON

func (s *EntityMention) MarshalJSON() ([]byte, error)

func (*EntityMention) UnmarshalJSON

func (s *EntityMention) UnmarshalJSON(data []byte) error

type Features

type Features struct {
	// ClassifyText: Optional. Classify the full document into categories.
	ClassifyText bool `json:"classifyText,omitempty"`

	// ExtractDocumentSentiment: Optional. Extract document-level sentiment.
	ExtractDocumentSentiment bool `json:"extractDocumentSentiment,omitempty"`

	// ExtractEntities: Optional. Extract entities.
	ExtractEntities bool `json:"extractEntities,omitempty"`

	// ModerateText: Optional. Moderate the document for harmful and
	// sensitive categories.
	ModerateText bool `json:"moderateText,omitempty"`

	// ForceSendFields is a list of field names (e.g. "ClassifyText") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "ClassifyText") to include
	// in API requests with the JSON null value. By default, fields with
	// empty values are omitted from API requests. However, any field with
	// an empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

Features: All available features. Setting each one to true will enable that specific analysis for the input.

func (*Features) MarshalJSON

func (s *Features) MarshalJSON() ([]byte, error)

type ModerateTextRequest

type ModerateTextRequest struct {
	// Document: Required. Input document.
	Document *Document `json:"document,omitempty"`

	// ForceSendFields is a list of field names (e.g. "Document") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Document") to include in
	// API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

ModerateTextRequest: The document moderation request message.

func (*ModerateTextRequest) MarshalJSON

func (s *ModerateTextRequest) MarshalJSON() ([]byte, error)

type ModerateTextResponse

type ModerateTextResponse struct {
	// LanguageCode: The language of the text, which will be the same as the
	// language specified in the request or, if not specified, the
	// automatically-detected language. See Document.language field for more
	// details.
	LanguageCode string `json:"languageCode,omitempty"`

	// LanguageSupported: Whether the language is officially supported. The
	// API may still return a response when the language is not supported,
	// but it is on a best effort basis.
	LanguageSupported bool `json:"languageSupported,omitempty"`

	// ModerationCategories: Harmful and sensitive categories representing
	// the input document.
	ModerationCategories []*ClassificationCategory `json:"moderationCategories,omitempty"`

	// ServerResponse contains the HTTP response code and headers from the
	// server.
	googleapi.ServerResponse `json:"-"`

	// ForceSendFields is a list of field names (e.g. "LanguageCode") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "LanguageCode") to include
	// in API requests with the JSON null value. By default, fields with
	// empty values are omitted from API requests. However, any field with
	// an empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

ModerateTextResponse: The document moderation response message.

func (*ModerateTextResponse) MarshalJSON

func (s *ModerateTextResponse) MarshalJSON() ([]byte, error)

type Sentence

type Sentence struct {
	// Sentiment: For calls to AnalyzeSentiment or if
	// AnnotateTextRequest.Features.extract_document_sentiment is set to
	// true, this field will contain the sentiment for the sentence.
	Sentiment *Sentiment `json:"sentiment,omitempty"`

	// Text: The sentence text.
	Text *TextSpan `json:"text,omitempty"`

	// ForceSendFields is a list of field names (e.g. "Sentiment") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Sentiment") to include in
	// API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

Sentence: Represents a sentence in the input document.

func (*Sentence) MarshalJSON

func (s *Sentence) MarshalJSON() ([]byte, error)

type Sentiment

type Sentiment struct {
	// Magnitude: A non-negative number in the [0, +inf) range, which
	// represents the absolute magnitude of sentiment regardless of score
	// (positive or negative).
	Magnitude float64 `json:"magnitude,omitempty"`

	// Score: Sentiment score between -1.0 (negative sentiment) and 1.0
	// (positive sentiment).
	Score float64 `json:"score,omitempty"`

	// ForceSendFields is a list of field names (e.g. "Magnitude") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Magnitude") to include in
	// API requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

Sentiment: Represents the feeling associated with the entire text or entities in the text.

func (*Sentiment) MarshalJSON

func (s *Sentiment) MarshalJSON() ([]byte, error)

func (*Sentiment) UnmarshalJSON

func (s *Sentiment) UnmarshalJSON(data []byte) error

type Service

type Service struct {
	BasePath  string // API endpoint base URL
	UserAgent string // optional additional User-Agent fragment

	Documents *DocumentsService
	// contains filtered or unexported fields
}

func New deprecated

func New(client *http.Client) (*Service, error)

New creates a new Service. It uses the provided http.Client for requests.

Deprecated: please use NewService instead. To provide a custom HTTP client, use option.WithHTTPClient. If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.

func NewService

func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error)

NewService creates a new Service.

type Status

type Status struct {
	// Code: The status code, which should be an enum value of
	// google.rpc.Code.
	Code int64 `json:"code,omitempty"`

	// Details: A list of messages that carry the error details. There is a
	// common set of message types for APIs to use.
	Details []googleapi.RawMessage `json:"details,omitempty"`

	// Message: A developer-facing error message, which should be in
	// English. Any user-facing error message should be localized and sent
	// in the google.rpc.Status.details field, or localized by the client.
	Message string `json:"message,omitempty"`

	// ForceSendFields is a list of field names (e.g. "Code") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "Code") to include in API
	// requests with the JSON null value. By default, fields with empty
	// values are omitted from API requests. However, any field with an
	// empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

Status: The `Status` type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by gRPC (https://github.com/grpc). Each `Status` message contains three pieces of data: error code, error message, and error details. You can find out more about this error model and how to work with it in the API Design Guide (https://cloud.google.com/apis/design/errors).

func (*Status) MarshalJSON

func (s *Status) MarshalJSON() ([]byte, error)

type TextSpan

type TextSpan struct {
	// BeginOffset: The API calculates the beginning offset of the content
	// in the original document according to the EncodingType specified in
	// the API request.
	BeginOffset int64 `json:"beginOffset,omitempty"`

	// Content: The content of the text span, which is a substring of the
	// document.
	Content string `json:"content,omitempty"`

	// ForceSendFields is a list of field names (e.g. "BeginOffset") to
	// unconditionally include in API requests. By default, fields with
	// empty or default values are omitted from API requests. However, any
	// non-pointer, non-interface field appearing in ForceSendFields will be
	// sent to the server regardless of whether the field is empty or not.
	// This may be used to include empty fields in Patch requests.
	ForceSendFields []string `json:"-"`

	// NullFields is a list of field names (e.g. "BeginOffset") to include
	// in API requests with the JSON null value. By default, fields with
	// empty values are omitted from API requests. However, any field with
	// an empty value appearing in NullFields will be sent to the server as
	// null. It is an error if a field in this list has a non-empty value.
	// This may be used to include null fields in Patch requests.
	NullFields []string `json:"-"`
}

TextSpan: Represents a text span in the input document.

func (*TextSpan) MarshalJSON

func (s *TextSpan) MarshalJSON() ([]byte, error)

Jump to

Keyboard shortcuts

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