...

Source file src/google.golang.org/api/commentanalyzer/v1alpha1/commentanalyzer-gen.go

Documentation: google.golang.org/api/commentanalyzer/v1alpha1

     1  // Copyright 2020 Google LLC.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Code generated file. DO NOT EDIT.
     6  
     7  // Package commentanalyzer provides access to the Perspective Comment Analyzer API.
     8  //
     9  // For product documentation, see: https://github.com/conversationai/perspectiveapi/blob/master/README.md
    10  //
    11  // # Creating a client
    12  //
    13  // Usage example:
    14  //
    15  //	import "google.golang.org/api/commentanalyzer/v1alpha1"
    16  //	...
    17  //	ctx := context.Background()
    18  //	commentanalyzerService, err := commentanalyzer.NewService(ctx)
    19  //
    20  // In this example, Google Application Default Credentials are used for authentication.
    21  //
    22  // For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials.
    23  //
    24  // # Other authentication options
    25  //
    26  // To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey:
    27  //
    28  //	commentanalyzerService, err := commentanalyzer.NewService(ctx, option.WithAPIKey("AIza..."))
    29  //
    30  // To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource:
    31  //
    32  //	config := &oauth2.Config{...}
    33  //	// ...
    34  //	token, err := config.Exchange(ctx, ...)
    35  //	commentanalyzerService, err := commentanalyzer.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token)))
    36  //
    37  // See https://godoc.org/google.golang.org/api/option/ for details on options.
    38  package commentanalyzer // import "google.golang.org/api/commentanalyzer/v1alpha1"
    39  
    40  import (
    41  	"bytes"
    42  	"context"
    43  	"encoding/json"
    44  	"errors"
    45  	"fmt"
    46  	"io"
    47  	"net/http"
    48  	"net/url"
    49  	"strconv"
    50  	"strings"
    51  
    52  	googleapi "google.golang.org/api/googleapi"
    53  	gensupport "google.golang.org/api/internal/gensupport"
    54  	option "google.golang.org/api/option"
    55  	internaloption "google.golang.org/api/option/internaloption"
    56  	htransport "google.golang.org/api/transport/http"
    57  )
    58  
    59  // Always reference these packages, just in case the auto-generated code
    60  // below doesn't.
    61  var _ = bytes.NewBuffer
    62  var _ = strconv.Itoa
    63  var _ = fmt.Sprintf
    64  var _ = json.NewDecoder
    65  var _ = io.Copy
    66  var _ = url.Parse
    67  var _ = gensupport.MarshalJSON
    68  var _ = googleapi.Version
    69  var _ = errors.New
    70  var _ = strings.Replace
    71  var _ = context.Canceled
    72  var _ = internaloption.WithDefaultEndpoint
    73  
    74  const apiId = "commentanalyzer:v1alpha1"
    75  const apiName = "commentanalyzer"
    76  const apiVersion = "v1alpha1"
    77  const basePath = "https://commentanalyzer.googleapis.com/"
    78  
    79  // OAuth2 scopes used by this API.
    80  const (
    81  	// View your email address
    82  	UserinfoEmailScope = "https://www.googleapis.com/auth/userinfo.email"
    83  )
    84  
    85  // NewService creates a new Service.
    86  func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) {
    87  	scopesOption := option.WithScopes(
    88  		"https://www.googleapis.com/auth/userinfo.email",
    89  	)
    90  	// NOTE: prepend, so we don't override user-specified scopes.
    91  	opts = append([]option.ClientOption{scopesOption}, opts...)
    92  	opts = append(opts, internaloption.WithDefaultEndpoint(basePath))
    93  	client, endpoint, err := htransport.NewClient(ctx, opts...)
    94  	if err != nil {
    95  		return nil, err
    96  	}
    97  	s, err := New(client)
    98  	if err != nil {
    99  		return nil, err
   100  	}
   101  	if endpoint != "" {
   102  		s.BasePath = endpoint
   103  	}
   104  	return s, nil
   105  }
   106  
   107  // New creates a new Service. It uses the provided http.Client for requests.
   108  //
   109  // Deprecated: please use NewService instead.
   110  // To provide a custom HTTP client, use option.WithHTTPClient.
   111  // If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead.
   112  func New(client *http.Client) (*Service, error) {
   113  	if client == nil {
   114  		return nil, errors.New("client is nil")
   115  	}
   116  	s := &Service{client: client, BasePath: basePath}
   117  	s.Comments = NewCommentsService(s)
   118  	return s, nil
   119  }
   120  
   121  type Service struct {
   122  	client    *http.Client
   123  	BasePath  string // API endpoint base URL
   124  	UserAgent string // optional additional User-Agent fragment
   125  
   126  	Comments *CommentsService
   127  }
   128  
   129  func (s *Service) userAgent() string {
   130  	if s.UserAgent == "" {
   131  		return googleapi.UserAgent
   132  	}
   133  	return googleapi.UserAgent + " " + s.UserAgent
   134  }
   135  
   136  func NewCommentsService(s *Service) *CommentsService {
   137  	rs := &CommentsService{s: s}
   138  	return rs
   139  }
   140  
   141  type CommentsService struct {
   142  	s *Service
   143  }
   144  
   145  // AnalyzeCommentRequest: The comment analysis request
   146  // message.
   147  // LINT.IfChange
   148  type AnalyzeCommentRequest struct {
   149  	// ClientToken: Opaque token that is echoed from the request to the
   150  	// response.
   151  	ClientToken string `json:"clientToken,omitempty"`
   152  
   153  	// Comment: The comment to analyze.
   154  	Comment *TextEntry `json:"comment,omitempty"`
   155  
   156  	// CommunityId: Optional identifier associating this
   157  	// AnalyzeCommentRequest with a
   158  	// particular client's community. Different communities may have
   159  	// different
   160  	// norms and rules. Specifying this value enables us to explore
   161  	// building
   162  	// community-specific models for clients.
   163  	CommunityId string `json:"communityId,omitempty"`
   164  
   165  	// Context: The context of the comment.
   166  	Context *Context `json:"context,omitempty"`
   167  
   168  	// DoNotStore: Do not store the comment or context sent in this request.
   169  	// By default, the
   170  	// service may store comments/context for debugging purposes.
   171  	DoNotStore bool `json:"doNotStore,omitempty"`
   172  
   173  	// Languages: The language(s) of the comment and context. If none are
   174  	// specified, we
   175  	// attempt to automatically detect the language. Specifying multiple
   176  	// languages
   177  	// means the text contains multiple lanugages. Both ISO and BCP-47
   178  	// language
   179  	// codes are accepted.
   180  	//
   181  	// The server returns an error if no language was specified and
   182  	// language
   183  	// detection fails. The server also returns an error if the languages
   184  	// (either
   185  	// specified by the caller, or auto-detected) are not *all* supported by
   186  	// the
   187  	// service.
   188  	Languages []string `json:"languages,omitempty"`
   189  
   190  	// RequestedAttributes: Specification of requested attributes. The
   191  	// AttributeParameters serve as
   192  	// configuration for each associated attribute. The map keys are
   193  	// attribute
   194  	// names. The available attributes may be different on each RFE
   195  	// installation,
   196  	// and can be seen by calling ListAttributes (see above).
   197  	// For the prod installation, known as Perspective API,
   198  	// at
   199  	// blade:commentanalyzer-esf and commentanalyzer.googleapis.com,
   200  	// see
   201  	// go/checker-models (internal)
   202  	// and
   203  	// https://github.com/conversationai/perspectiveapi/blob/master/2-api
   204  	// /models.md#all-attribute-types.
   205  	RequestedAttributes map[string]AttributeParameters `json:"requestedAttributes,omitempty"`
   206  
   207  	// SessionId: Session ID. Used to join related RPCs into a single
   208  	// session. For example,
   209  	// an interactive tool that calls both the AnalyzeComment
   210  	// and
   211  	// SuggestCommentScore RPCs should set all invocations of both RPCs to
   212  	// the
   213  	// same Session ID, typically a random 64-bit integer.
   214  	SessionId string `json:"sessionId,omitempty"`
   215  
   216  	// SpanAnnotations: An advisory parameter that will return span
   217  	// annotations if the model
   218  	// is capable of providing scores with sub-comment resolution. This
   219  	// will
   220  	// likely increase the size of the returned message.
   221  	SpanAnnotations bool `json:"spanAnnotations,omitempty"`
   222  
   223  	// ForceSendFields is a list of field names (e.g. "ClientToken") to
   224  	// unconditionally include in API requests. By default, fields with
   225  	// empty values are omitted from API requests. However, any non-pointer,
   226  	// non-interface field appearing in ForceSendFields will be sent to the
   227  	// server regardless of whether the field is empty or not. This may be
   228  	// used to include empty fields in Patch requests.
   229  	ForceSendFields []string `json:"-"`
   230  
   231  	// NullFields is a list of field names (e.g. "ClientToken") to include
   232  	// in API requests with the JSON null value. By default, fields with
   233  	// empty values are omitted from API requests. However, any field with
   234  	// an empty value appearing in NullFields will be sent to the server as
   235  	// null. It is an error if a field in this list has a non-empty value.
   236  	// This may be used to include null fields in Patch requests.
   237  	NullFields []string `json:"-"`
   238  }
   239  
   240  func (s *AnalyzeCommentRequest) MarshalJSON() ([]byte, error) {
   241  	type NoMethod AnalyzeCommentRequest
   242  	raw := NoMethod(*s)
   243  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   244  }
   245  
   246  // AnalyzeCommentResponse: The comment analysis response message.
   247  type AnalyzeCommentResponse struct {
   248  	// AttributeScores: Scores for the requested attributes. The map keys
   249  	// are attribute names (same
   250  	// as the requested_attribute field in AnalyzeCommentRequest, for
   251  	// example
   252  	// "ATTACK_ON_AUTHOR", "INFLAMMATORY", etc).
   253  	AttributeScores map[string]AttributeScores `json:"attributeScores,omitempty"`
   254  
   255  	// ClientToken: Same token from the original AnalyzeCommentRequest.
   256  	ClientToken string `json:"clientToken,omitempty"`
   257  
   258  	// DetectedLanguages: Contains the languages detected from the text
   259  	// content, sorted in order of
   260  	// likelihood.
   261  	DetectedLanguages []string `json:"detectedLanguages,omitempty"`
   262  
   263  	// Languages: The language(s) used by CommentAnalyzer service to choose
   264  	// which Model to
   265  	// use when analyzing the comment. Might better be
   266  	// called
   267  	// "effective_languages". The logic used to make the choice is as
   268  	// follows:
   269  	//   if !Request.languages.empty()
   270  	//     effective_languages = Request.languages
   271  	//   else
   272  	//     effective_languages = detected_languages[0]
   273  	Languages []string `json:"languages,omitempty"`
   274  
   275  	// ServerResponse contains the HTTP response code and headers from the
   276  	// server.
   277  	googleapi.ServerResponse `json:"-"`
   278  
   279  	// ForceSendFields is a list of field names (e.g. "AttributeScores") to
   280  	// unconditionally include in API requests. By default, fields with
   281  	// empty values are omitted from API requests. However, any non-pointer,
   282  	// non-interface field appearing in ForceSendFields will be sent to the
   283  	// server regardless of whether the field is empty or not. This may be
   284  	// used to include empty fields in Patch requests.
   285  	ForceSendFields []string `json:"-"`
   286  
   287  	// NullFields is a list of field names (e.g. "AttributeScores") to
   288  	// include in API requests with the JSON null value. By default, fields
   289  	// with empty values are omitted from API requests. However, any field
   290  	// with an empty value appearing in NullFields will be sent to the
   291  	// server as null. It is an error if a field in this list has a
   292  	// non-empty value. This may be used to include null fields in Patch
   293  	// requests.
   294  	NullFields []string `json:"-"`
   295  }
   296  
   297  func (s *AnalyzeCommentResponse) MarshalJSON() ([]byte, error) {
   298  	type NoMethod AnalyzeCommentResponse
   299  	raw := NoMethod(*s)
   300  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   301  }
   302  
   303  // ArticleAndParentComment: A type of context specific to a comment left
   304  // on a single-threaded comment
   305  // message board, where comments are either a top level comment or the
   306  // child of
   307  // a top level comment.
   308  type ArticleAndParentComment struct {
   309  	// Article: The source content about which the comment was made (article
   310  	// text, article
   311  	// summary, video transcript, etc).
   312  	Article *TextEntry `json:"article,omitempty"`
   313  
   314  	// ParentComment: Refers to text that is a direct parent of the source
   315  	// comment, such as in a
   316  	// one-deep threaded message board. This field will only be present
   317  	// for
   318  	// comments that are replies to other comments and will not be populated
   319  	// for
   320  	// direct comments on the article_text.
   321  	ParentComment *TextEntry `json:"parentComment,omitempty"`
   322  
   323  	// ForceSendFields is a list of field names (e.g. "Article") to
   324  	// unconditionally include in API requests. By default, fields with
   325  	// empty values are omitted from API requests. However, any non-pointer,
   326  	// non-interface field appearing in ForceSendFields will be sent to the
   327  	// server regardless of whether the field is empty or not. This may be
   328  	// used to include empty fields in Patch requests.
   329  	ForceSendFields []string `json:"-"`
   330  
   331  	// NullFields is a list of field names (e.g. "Article") to include in
   332  	// API requests with the JSON null value. By default, fields with empty
   333  	// values are omitted from API requests. However, any field with an
   334  	// empty value appearing in NullFields will be sent to the server as
   335  	// null. It is an error if a field in this list has a non-empty value.
   336  	// This may be used to include null fields in Patch requests.
   337  	NullFields []string `json:"-"`
   338  }
   339  
   340  func (s *ArticleAndParentComment) MarshalJSON() ([]byte, error) {
   341  	type NoMethod ArticleAndParentComment
   342  	raw := NoMethod(*s)
   343  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   344  }
   345  
   346  // AttributeParameters: Configurable parameters for attribute scoring.
   347  type AttributeParameters struct {
   348  	// ScoreThreshold: Don't return scores for this attribute that are below
   349  	// this threshold. If
   350  	// unset, a default threshold will be applied. A FloatValue wrapper is
   351  	// used to
   352  	// distinguish between 0 vs. default/unset.
   353  	ScoreThreshold float64 `json:"scoreThreshold,omitempty"`
   354  
   355  	// ScoreType: What type of scores to return. If unset, defaults to
   356  	// probability scores.
   357  	//
   358  	// Possible values:
   359  	//   "SCORE_TYPE_UNSPECIFIED" - Unspecified. Defaults to PROBABILITY
   360  	// scores if available, and otherwise
   361  	// RAW. Every model has a RAW score.
   362  	//   "PROBABILITY" - Probability scores are in the range [0, 1] and
   363  	// indicate level of confidence
   364  	// in the attribute label.
   365  	//   "STD_DEV_SCORE" - Standard deviation scores are in the range (-inf,
   366  	// +inf).
   367  	//   "PERCENTILE" - Percentile scores are in the range [0, 1] and
   368  	// indicate the percentile of
   369  	// the raw score, normalized with a test dataset. This is not
   370  	// generally
   371  	// recommended, as the normalization is dependent on the dataset used,
   372  	// which
   373  	// may not match other usecases.
   374  	//   "RAW" - Raw scores are the raw values from the model, and may take
   375  	// any value. This
   376  	// is primarily for debugging/testing, and not generally recommended.
   377  	ScoreType string `json:"scoreType,omitempty"`
   378  
   379  	// ForceSendFields is a list of field names (e.g. "ScoreThreshold") to
   380  	// unconditionally include in API requests. By default, fields with
   381  	// empty values are omitted from API requests. However, any non-pointer,
   382  	// non-interface field appearing in ForceSendFields will be sent to the
   383  	// server regardless of whether the field is empty or not. This may be
   384  	// used to include empty fields in Patch requests.
   385  	ForceSendFields []string `json:"-"`
   386  
   387  	// NullFields is a list of field names (e.g. "ScoreThreshold") to
   388  	// include in API requests with the JSON null value. By default, fields
   389  	// with empty values are omitted from API requests. However, any field
   390  	// with an empty value appearing in NullFields will be sent to the
   391  	// server as null. It is an error if a field in this list has a
   392  	// non-empty value. This may be used to include null fields in Patch
   393  	// requests.
   394  	NullFields []string `json:"-"`
   395  }
   396  
   397  func (s *AttributeParameters) MarshalJSON() ([]byte, error) {
   398  	type NoMethod AttributeParameters
   399  	raw := NoMethod(*s)
   400  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   401  }
   402  
   403  func (s *AttributeParameters) UnmarshalJSON(data []byte) error {
   404  	type NoMethod AttributeParameters
   405  	var s1 struct {
   406  		ScoreThreshold gensupport.JSONFloat64 `json:"scoreThreshold"`
   407  		*NoMethod
   408  	}
   409  	s1.NoMethod = (*NoMethod)(s)
   410  	if err := json.Unmarshal(data, &s1); err != nil {
   411  		return err
   412  	}
   413  	s.ScoreThreshold = float64(s1.ScoreThreshold)
   414  	return nil
   415  }
   416  
   417  // AttributeScores: This holds score values for a single attribute. It
   418  // contains both per-span
   419  // scores as well as an overall summary score..
   420  type AttributeScores struct {
   421  	// SpanScores: Per-span scores.
   422  	SpanScores []*SpanScore `json:"spanScores,omitempty"`
   423  
   424  	// SummaryScore: Overall score for comment as a whole.
   425  	SummaryScore *Score `json:"summaryScore,omitempty"`
   426  
   427  	// ForceSendFields is a list of field names (e.g. "SpanScores") to
   428  	// unconditionally include in API requests. By default, fields with
   429  	// empty values are omitted from API requests. However, any non-pointer,
   430  	// non-interface field appearing in ForceSendFields will be sent to the
   431  	// server regardless of whether the field is empty or not. This may be
   432  	// used to include empty fields in Patch requests.
   433  	ForceSendFields []string `json:"-"`
   434  
   435  	// NullFields is a list of field names (e.g. "SpanScores") to include in
   436  	// API requests with the JSON null value. By default, fields with empty
   437  	// values are omitted from API requests. However, any field with an
   438  	// empty value appearing in NullFields will be sent to the server as
   439  	// null. It is an error if a field in this list has a non-empty value.
   440  	// This may be used to include null fields in Patch requests.
   441  	NullFields []string `json:"-"`
   442  }
   443  
   444  func (s *AttributeScores) MarshalJSON() ([]byte, error) {
   445  	type NoMethod AttributeScores
   446  	raw := NoMethod(*s)
   447  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   448  }
   449  
   450  // Context: Context is typically something that a Comment is referencing
   451  // or replying to
   452  // (such as an article, or previous comment).
   453  // Note: Populate only ONE OF the following fields. The oneof syntax
   454  // cannot be
   455  // used because that would require nesting entries inside another
   456  // message and
   457  // breaking backwards compatibility. The server will return an error if
   458  // more
   459  // than one of the following fields is present.
   460  type Context struct {
   461  	// ArticleAndParentComment: Information about the source for which the
   462  	// original comment was made, and
   463  	// any parent comment info.
   464  	ArticleAndParentComment *ArticleAndParentComment `json:"articleAndParentComment,omitempty"`
   465  
   466  	// Entries: A list of messages. For example, a linear comments section
   467  	// or forum thread.
   468  	Entries []*TextEntry `json:"entries,omitempty"`
   469  
   470  	// ForceSendFields is a list of field names (e.g.
   471  	// "ArticleAndParentComment") to unconditionally include in API
   472  	// requests. By default, fields with empty values are omitted from API
   473  	// requests. However, any non-pointer, non-interface field appearing in
   474  	// ForceSendFields will be sent to the server regardless of whether the
   475  	// field is empty or not. This may be used to include empty fields in
   476  	// Patch requests.
   477  	ForceSendFields []string `json:"-"`
   478  
   479  	// NullFields is a list of field names (e.g. "ArticleAndParentComment")
   480  	// to include in API requests with the JSON null value. By default,
   481  	// fields with empty values are omitted from API requests. However, any
   482  	// field with an empty value appearing in NullFields will be sent to the
   483  	// server as null. It is an error if a field in this list has a
   484  	// non-empty value. This may be used to include null fields in Patch
   485  	// requests.
   486  	NullFields []string `json:"-"`
   487  }
   488  
   489  func (s *Context) MarshalJSON() ([]byte, error) {
   490  	type NoMethod Context
   491  	raw := NoMethod(*s)
   492  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   493  }
   494  
   495  // Score: Analysis scores are described by a value and a ScoreType.
   496  type Score struct {
   497  	// Type: The type of the above value.
   498  	//
   499  	// Possible values:
   500  	//   "SCORE_TYPE_UNSPECIFIED" - Unspecified. Defaults to PROBABILITY
   501  	// scores if available, and otherwise
   502  	// RAW. Every model has a RAW score.
   503  	//   "PROBABILITY" - Probability scores are in the range [0, 1] and
   504  	// indicate level of confidence
   505  	// in the attribute label.
   506  	//   "STD_DEV_SCORE" - Standard deviation scores are in the range (-inf,
   507  	// +inf).
   508  	//   "PERCENTILE" - Percentile scores are in the range [0, 1] and
   509  	// indicate the percentile of
   510  	// the raw score, normalized with a test dataset. This is not
   511  	// generally
   512  	// recommended, as the normalization is dependent on the dataset used,
   513  	// which
   514  	// may not match other usecases.
   515  	//   "RAW" - Raw scores are the raw values from the model, and may take
   516  	// any value. This
   517  	// is primarily for debugging/testing, and not generally recommended.
   518  	Type string `json:"type,omitempty"`
   519  
   520  	// Value: Score value. Semantics described by type below.
   521  	Value float64 `json:"value,omitempty"`
   522  
   523  	// ForceSendFields is a list of field names (e.g. "Type") to
   524  	// unconditionally include in API requests. By default, fields with
   525  	// empty values are omitted from API requests. However, any non-pointer,
   526  	// non-interface field appearing in ForceSendFields will be sent to the
   527  	// server regardless of whether the field is empty or not. This may be
   528  	// used to include empty fields in Patch requests.
   529  	ForceSendFields []string `json:"-"`
   530  
   531  	// NullFields is a list of field names (e.g. "Type") to include in API
   532  	// requests with the JSON null value. By default, fields with empty
   533  	// values are omitted from API requests. However, any field with an
   534  	// empty value appearing in NullFields will be sent to the server as
   535  	// null. It is an error if a field in this list has a non-empty value.
   536  	// This may be used to include null fields in Patch requests.
   537  	NullFields []string `json:"-"`
   538  }
   539  
   540  func (s *Score) MarshalJSON() ([]byte, error) {
   541  	type NoMethod Score
   542  	raw := NoMethod(*s)
   543  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   544  }
   545  
   546  func (s *Score) UnmarshalJSON(data []byte) error {
   547  	type NoMethod Score
   548  	var s1 struct {
   549  		Value gensupport.JSONFloat64 `json:"value"`
   550  		*NoMethod
   551  	}
   552  	s1.NoMethod = (*NoMethod)(s)
   553  	if err := json.Unmarshal(data, &s1); err != nil {
   554  		return err
   555  	}
   556  	s.Value = float64(s1.Value)
   557  	return nil
   558  }
   559  
   560  // SpanScore: This is a single score for a given span of text.
   561  type SpanScore struct {
   562  	// Begin: "begin" and "end" describe the span of the original text that
   563  	// the attribute
   564  	// score applies to. The values are the UTF-16 codepoint range. "end"
   565  	// is
   566  	// exclusive. For example, with the text "Hi there", the begin/end pair
   567  	// (0,2)
   568  	// describes the text "Hi".
   569  	//
   570  	// If "begin" and "end" are unset, the score applies to the full text.
   571  	Begin int64 `json:"begin,omitempty"`
   572  
   573  	End int64 `json:"end,omitempty"`
   574  
   575  	// Score: The score value.
   576  	Score *Score `json:"score,omitempty"`
   577  
   578  	// ForceSendFields is a list of field names (e.g. "Begin") to
   579  	// unconditionally include in API requests. By default, fields with
   580  	// empty values are omitted from API requests. However, any non-pointer,
   581  	// non-interface field appearing in ForceSendFields will be sent to the
   582  	// server regardless of whether the field is empty or not. This may be
   583  	// used to include empty fields in Patch requests.
   584  	ForceSendFields []string `json:"-"`
   585  
   586  	// NullFields is a list of field names (e.g. "Begin") to include in API
   587  	// requests with the JSON null value. By default, fields with empty
   588  	// values are omitted from API requests. However, any field with an
   589  	// empty value appearing in NullFields will be sent to the server as
   590  	// null. It is an error if a field in this list has a non-empty value.
   591  	// This may be used to include null fields in Patch requests.
   592  	NullFields []string `json:"-"`
   593  }
   594  
   595  func (s *SpanScore) MarshalJSON() ([]byte, error) {
   596  	type NoMethod SpanScore
   597  	raw := NoMethod(*s)
   598  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   599  }
   600  
   601  // SuggestCommentScoreRequest: The comment score suggestion request
   602  // message.
   603  type SuggestCommentScoreRequest struct {
   604  	// AttributeScores: Attribute scores for the comment. The map keys are
   605  	// attribute names, same as
   606  	// the requested_attribute field in AnalyzeCommentRequest (for
   607  	// example
   608  	// "ATTACK_ON_AUTHOR", "INFLAMMATORY", etc.). This field has the same
   609  	// type as
   610  	// the `attribute_scores` field in AnalyzeCommentResponse.
   611  	//
   612  	// To specify an overall attribute score for the entire comment as a
   613  	// whole,
   614  	// use the `summary_score` field of the mapped AttributeScores object.
   615  	// To
   616  	// specify scores on specific subparts of the comment, use the
   617  	// `span_scores`
   618  	// field. All SpanScore objects must have begin and end fields set.
   619  	//
   620  	// All Score objects must be explicitly set (for binary classification,
   621  	// use
   622  	// the score values 0 and 1). If Score objects don't include a
   623  	// ScoreType,
   624  	// `PROBABILITY` is assumed.
   625  	//
   626  	// `attribute_scores` must not be empty. The mapped AttributeScores
   627  	// objects
   628  	// also must not be empty. An `INVALID_ARGUMENT` error is returned for
   629  	// all
   630  	// malformed requests.
   631  	AttributeScores map[string]AttributeScores `json:"attributeScores,omitempty"`
   632  
   633  	// ClientToken: Opaque token that is echoed from the request to the
   634  	// response.
   635  	ClientToken string `json:"clientToken,omitempty"`
   636  
   637  	// Comment: The comment being scored.
   638  	Comment *TextEntry `json:"comment,omitempty"`
   639  
   640  	// CommunityId: Optional identifier associating this comment score
   641  	// suggestion with a
   642  	// particular sub-community. Different communities may have different
   643  	// norms
   644  	// and rules. Specifying this value enables training
   645  	// community-specific
   646  	// models.
   647  	CommunityId string `json:"communityId,omitempty"`
   648  
   649  	// Context: The context of the comment.
   650  	Context *Context `json:"context,omitempty"`
   651  
   652  	// Languages: The language(s) of the comment and context. If none are
   653  	// specified, we
   654  	// attempt to automatically detect the language. Both ISO and BCP-47
   655  	// language
   656  	// codes are accepted.
   657  	Languages []string `json:"languages,omitempty"`
   658  
   659  	// SessionId: Session ID. Used to join related RPCs into a single
   660  	// session. For example,
   661  	// an interactive tool that calls both the AnalyzeComment
   662  	// and
   663  	// SuggestCommentScore RPCs should set all invocations of both RPCs to
   664  	// the
   665  	// same Session ID, typically a random 64-bit integer.
   666  	SessionId string `json:"sessionId,omitempty"`
   667  
   668  	// ForceSendFields is a list of field names (e.g. "AttributeScores") to
   669  	// unconditionally include in API requests. By default, fields with
   670  	// empty values are omitted from API requests. However, any non-pointer,
   671  	// non-interface field appearing in ForceSendFields will be sent to the
   672  	// server regardless of whether the field is empty or not. This may be
   673  	// used to include empty fields in Patch requests.
   674  	ForceSendFields []string `json:"-"`
   675  
   676  	// NullFields is a list of field names (e.g. "AttributeScores") to
   677  	// include in API requests with the JSON null value. By default, fields
   678  	// with empty values are omitted from API requests. However, any field
   679  	// with an empty value appearing in NullFields will be sent to the
   680  	// server as null. It is an error if a field in this list has a
   681  	// non-empty value. This may be used to include null fields in Patch
   682  	// requests.
   683  	NullFields []string `json:"-"`
   684  }
   685  
   686  func (s *SuggestCommentScoreRequest) MarshalJSON() ([]byte, error) {
   687  	type NoMethod SuggestCommentScoreRequest
   688  	raw := NoMethod(*s)
   689  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   690  }
   691  
   692  // SuggestCommentScoreResponse: The comment score suggestion response
   693  // message.
   694  type SuggestCommentScoreResponse struct {
   695  	// ClientToken: Same token from the original SuggestCommentScoreRequest.
   696  	ClientToken string `json:"clientToken,omitempty"`
   697  
   698  	// DetectedLanguages: The list of languages detected from the comment
   699  	// text.
   700  	DetectedLanguages []string `json:"detectedLanguages,omitempty"`
   701  
   702  	// RequestedLanguages: The list of languages provided in the request.
   703  	RequestedLanguages []string `json:"requestedLanguages,omitempty"`
   704  
   705  	// ServerResponse contains the HTTP response code and headers from the
   706  	// server.
   707  	googleapi.ServerResponse `json:"-"`
   708  
   709  	// ForceSendFields is a list of field names (e.g. "ClientToken") to
   710  	// unconditionally include in API requests. By default, fields with
   711  	// empty values are omitted from API requests. However, any non-pointer,
   712  	// non-interface field appearing in ForceSendFields will be sent to the
   713  	// server regardless of whether the field is empty or not. This may be
   714  	// used to include empty fields in Patch requests.
   715  	ForceSendFields []string `json:"-"`
   716  
   717  	// NullFields is a list of field names (e.g. "ClientToken") to include
   718  	// in API requests with the JSON null value. By default, fields with
   719  	// empty values are omitted from API requests. However, any field with
   720  	// an empty value appearing in NullFields will be sent to the server as
   721  	// null. It is an error if a field in this list has a non-empty value.
   722  	// This may be used to include null fields in Patch requests.
   723  	NullFields []string `json:"-"`
   724  }
   725  
   726  func (s *SuggestCommentScoreResponse) MarshalJSON() ([]byte, error) {
   727  	type NoMethod SuggestCommentScoreResponse
   728  	raw := NoMethod(*s)
   729  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   730  }
   731  
   732  // TextEntry: Represents a body of text.
   733  type TextEntry struct {
   734  	// Text: UTF-8 encoded text.
   735  	Text string `json:"text,omitempty"`
   736  
   737  	// Type: Type of the text field.
   738  	//
   739  	// Possible values:
   740  	//   "TEXT_TYPE_UNSPECIFIED" - The content type is not specified. Text
   741  	// will be interpreted as plain text
   742  	// by default.
   743  	//   "PLAIN_TEXT" - Plain text.
   744  	//   "HTML" - HTML.
   745  	Type string `json:"type,omitempty"`
   746  
   747  	// ForceSendFields is a list of field names (e.g. "Text") to
   748  	// unconditionally include in API requests. By default, fields with
   749  	// empty values are omitted from API requests. However, any non-pointer,
   750  	// non-interface field appearing in ForceSendFields will be sent to the
   751  	// server regardless of whether the field is empty or not. This may be
   752  	// used to include empty fields in Patch requests.
   753  	ForceSendFields []string `json:"-"`
   754  
   755  	// NullFields is a list of field names (e.g. "Text") to include in API
   756  	// requests with the JSON null value. By default, fields with empty
   757  	// values are omitted from API requests. However, any field with an
   758  	// empty value appearing in NullFields will be sent to the server as
   759  	// null. It is an error if a field in this list has a non-empty value.
   760  	// This may be used to include null fields in Patch requests.
   761  	NullFields []string `json:"-"`
   762  }
   763  
   764  func (s *TextEntry) MarshalJSON() ([]byte, error) {
   765  	type NoMethod TextEntry
   766  	raw := NoMethod(*s)
   767  	return gensupport.MarshalJSON(raw, s.ForceSendFields, s.NullFields)
   768  }
   769  
   770  // method id "commentanalyzer.comments.analyze":
   771  
   772  type CommentsAnalyzeCall struct {
   773  	s                     *Service
   774  	analyzecommentrequest *AnalyzeCommentRequest
   775  	urlParams_            gensupport.URLParams
   776  	ctx_                  context.Context
   777  	header_               http.Header
   778  }
   779  
   780  // Analyze: Analyzes the provided text and returns scores for requested
   781  // attributes.
   782  func (r *CommentsService) Analyze(analyzecommentrequest *AnalyzeCommentRequest) *CommentsAnalyzeCall {
   783  	c := &CommentsAnalyzeCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   784  	c.analyzecommentrequest = analyzecommentrequest
   785  	return c
   786  }
   787  
   788  // Fields allows partial responses to be retrieved. See
   789  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
   790  // for more information.
   791  func (c *CommentsAnalyzeCall) Fields(s ...googleapi.Field) *CommentsAnalyzeCall {
   792  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   793  	return c
   794  }
   795  
   796  // Context sets the context to be used in this call's Do method. Any
   797  // pending HTTP request will be aborted if the provided context is
   798  // canceled.
   799  func (c *CommentsAnalyzeCall) Context(ctx context.Context) *CommentsAnalyzeCall {
   800  	c.ctx_ = ctx
   801  	return c
   802  }
   803  
   804  // Header returns an http.Header that can be modified by the caller to
   805  // add HTTP headers to the request.
   806  func (c *CommentsAnalyzeCall) Header() http.Header {
   807  	if c.header_ == nil {
   808  		c.header_ = make(http.Header)
   809  	}
   810  	return c.header_
   811  }
   812  
   813  func (c *CommentsAnalyzeCall) doRequest(alt string) (*http.Response, error) {
   814  	reqHeaders := make(http.Header)
   815  	reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/20200506")
   816  	for k, v := range c.header_ {
   817  		reqHeaders[k] = v
   818  	}
   819  	reqHeaders.Set("User-Agent", c.s.userAgent())
   820  	var body io.Reader = nil
   821  	body, err := googleapi.WithoutDataWrapper.JSONReader(c.analyzecommentrequest)
   822  	if err != nil {
   823  		return nil, err
   824  	}
   825  	reqHeaders.Set("Content-Type", "application/json")
   826  	c.urlParams_.Set("alt", alt)
   827  	c.urlParams_.Set("prettyPrint", "false")
   828  	urls := googleapi.ResolveRelative(c.s.BasePath, "v1alpha1/comments:analyze")
   829  	urls += "?" + c.urlParams_.Encode()
   830  	req, err := http.NewRequest("POST", urls, body)
   831  	if err != nil {
   832  		return nil, err
   833  	}
   834  	req.Header = reqHeaders
   835  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   836  }
   837  
   838  // Do executes the "commentanalyzer.comments.analyze" call.
   839  // Exactly one of *AnalyzeCommentResponse or error will be non-nil. Any
   840  // non-2xx status code is an error. Response headers are in either
   841  // *AnalyzeCommentResponse.ServerResponse.Header or (if a response was
   842  // returned at all) in error.(*googleapi.Error).Header. Use
   843  // googleapi.IsNotModified to check whether the returned error was
   844  // because http.StatusNotModified was returned.
   845  func (c *CommentsAnalyzeCall) Do(opts ...googleapi.CallOption) (*AnalyzeCommentResponse, error) {
   846  	gensupport.SetOptions(c.urlParams_, opts...)
   847  	res, err := c.doRequest("json")
   848  	if res != nil && res.StatusCode == http.StatusNotModified {
   849  		if res.Body != nil {
   850  			res.Body.Close()
   851  		}
   852  		return nil, &googleapi.Error{
   853  			Code:   res.StatusCode,
   854  			Header: res.Header,
   855  		}
   856  	}
   857  	if err != nil {
   858  		return nil, err
   859  	}
   860  	defer googleapi.CloseBody(res)
   861  	if err := googleapi.CheckResponse(res); err != nil {
   862  		return nil, err
   863  	}
   864  	ret := &AnalyzeCommentResponse{
   865  		ServerResponse: googleapi.ServerResponse{
   866  			Header:         res.Header,
   867  			HTTPStatusCode: res.StatusCode,
   868  		},
   869  	}
   870  	target := &ret
   871  	if err := gensupport.DecodeResponse(target, res); err != nil {
   872  		return nil, err
   873  	}
   874  	return ret, nil
   875  	// {
   876  	//   "description": "Analyzes the provided text and returns scores for requested attributes.",
   877  	//   "flatPath": "v1alpha1/comments:analyze",
   878  	//   "httpMethod": "POST",
   879  	//   "id": "commentanalyzer.comments.analyze",
   880  	//   "parameterOrder": [],
   881  	//   "parameters": {},
   882  	//   "path": "v1alpha1/comments:analyze",
   883  	//   "request": {
   884  	//     "$ref": "AnalyzeCommentRequest"
   885  	//   },
   886  	//   "response": {
   887  	//     "$ref": "AnalyzeCommentResponse"
   888  	//   },
   889  	//   "scopes": [
   890  	//     "https://www.googleapis.com/auth/userinfo.email"
   891  	//   ]
   892  	// }
   893  
   894  }
   895  
   896  // method id "commentanalyzer.comments.suggestscore":
   897  
   898  type CommentsSuggestscoreCall struct {
   899  	s                          *Service
   900  	suggestcommentscorerequest *SuggestCommentScoreRequest
   901  	urlParams_                 gensupport.URLParams
   902  	ctx_                       context.Context
   903  	header_                    http.Header
   904  }
   905  
   906  // Suggestscore: Suggest comment scores as training data.
   907  func (r *CommentsService) Suggestscore(suggestcommentscorerequest *SuggestCommentScoreRequest) *CommentsSuggestscoreCall {
   908  	c := &CommentsSuggestscoreCall{s: r.s, urlParams_: make(gensupport.URLParams)}
   909  	c.suggestcommentscorerequest = suggestcommentscorerequest
   910  	return c
   911  }
   912  
   913  // Fields allows partial responses to be retrieved. See
   914  // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
   915  // for more information.
   916  func (c *CommentsSuggestscoreCall) Fields(s ...googleapi.Field) *CommentsSuggestscoreCall {
   917  	c.urlParams_.Set("fields", googleapi.CombineFields(s))
   918  	return c
   919  }
   920  
   921  // Context sets the context to be used in this call's Do method. Any
   922  // pending HTTP request will be aborted if the provided context is
   923  // canceled.
   924  func (c *CommentsSuggestscoreCall) Context(ctx context.Context) *CommentsSuggestscoreCall {
   925  	c.ctx_ = ctx
   926  	return c
   927  }
   928  
   929  // Header returns an http.Header that can be modified by the caller to
   930  // add HTTP headers to the request.
   931  func (c *CommentsSuggestscoreCall) Header() http.Header {
   932  	if c.header_ == nil {
   933  		c.header_ = make(http.Header)
   934  	}
   935  	return c.header_
   936  }
   937  
   938  func (c *CommentsSuggestscoreCall) doRequest(alt string) (*http.Response, error) {
   939  	reqHeaders := make(http.Header)
   940  	reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/20200506")
   941  	for k, v := range c.header_ {
   942  		reqHeaders[k] = v
   943  	}
   944  	reqHeaders.Set("User-Agent", c.s.userAgent())
   945  	var body io.Reader = nil
   946  	body, err := googleapi.WithoutDataWrapper.JSONReader(c.suggestcommentscorerequest)
   947  	if err != nil {
   948  		return nil, err
   949  	}
   950  	reqHeaders.Set("Content-Type", "application/json")
   951  	c.urlParams_.Set("alt", alt)
   952  	c.urlParams_.Set("prettyPrint", "false")
   953  	urls := googleapi.ResolveRelative(c.s.BasePath, "v1alpha1/comments:suggestscore")
   954  	urls += "?" + c.urlParams_.Encode()
   955  	req, err := http.NewRequest("POST", urls, body)
   956  	if err != nil {
   957  		return nil, err
   958  	}
   959  	req.Header = reqHeaders
   960  	return gensupport.SendRequest(c.ctx_, c.s.client, req)
   961  }
   962  
   963  // Do executes the "commentanalyzer.comments.suggestscore" call.
   964  // Exactly one of *SuggestCommentScoreResponse or error will be non-nil.
   965  // Any non-2xx status code is an error. Response headers are in either
   966  // *SuggestCommentScoreResponse.ServerResponse.Header or (if a response
   967  // was returned at all) in error.(*googleapi.Error).Header. Use
   968  // googleapi.IsNotModified to check whether the returned error was
   969  // because http.StatusNotModified was returned.
   970  func (c *CommentsSuggestscoreCall) Do(opts ...googleapi.CallOption) (*SuggestCommentScoreResponse, error) {
   971  	gensupport.SetOptions(c.urlParams_, opts...)
   972  	res, err := c.doRequest("json")
   973  	if res != nil && res.StatusCode == http.StatusNotModified {
   974  		if res.Body != nil {
   975  			res.Body.Close()
   976  		}
   977  		return nil, &googleapi.Error{
   978  			Code:   res.StatusCode,
   979  			Header: res.Header,
   980  		}
   981  	}
   982  	if err != nil {
   983  		return nil, err
   984  	}
   985  	defer googleapi.CloseBody(res)
   986  	if err := googleapi.CheckResponse(res); err != nil {
   987  		return nil, err
   988  	}
   989  	ret := &SuggestCommentScoreResponse{
   990  		ServerResponse: googleapi.ServerResponse{
   991  			Header:         res.Header,
   992  			HTTPStatusCode: res.StatusCode,
   993  		},
   994  	}
   995  	target := &ret
   996  	if err := gensupport.DecodeResponse(target, res); err != nil {
   997  		return nil, err
   998  	}
   999  	return ret, nil
  1000  	// {
  1001  	//   "description": "Suggest comment scores as training data.",
  1002  	//   "flatPath": "v1alpha1/comments:suggestscore",
  1003  	//   "httpMethod": "POST",
  1004  	//   "id": "commentanalyzer.comments.suggestscore",
  1005  	//   "parameterOrder": [],
  1006  	//   "parameters": {},
  1007  	//   "path": "v1alpha1/comments:suggestscore",
  1008  	//   "request": {
  1009  	//     "$ref": "SuggestCommentScoreRequest"
  1010  	//   },
  1011  	//   "response": {
  1012  	//     "$ref": "SuggestCommentScoreResponse"
  1013  	//   },
  1014  	//   "scopes": [
  1015  	//     "https://www.googleapis.com/auth/userinfo.email"
  1016  	//   ]
  1017  	// }
  1018  
  1019  }
  1020  

View as plain text