censor

package
v0.0.0-...-d0e669d Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AliyunTextCensor

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

func NewAliyunTextCensor

func NewAliyunTextCensor(accessKey, accessKeySecret string) *AliyunTextCensor

func (*AliyunTextCensor) Censor

Censor censors text with Aliyun API. https://developer.qiniu.com/censor/7260/api-text-censor

func (*AliyunTextCensor) String

func (*AliyunTextCensor) String() string

type AliyunTextCensorResponse

type AliyunTextCensorResponse struct {
	Code int `json:"code"`
	Data []struct {
		Code            int    `json:"code"`
		Content         string `json:"content"`
		FilteredContent string `json:"filteredContent"`
		Msg             string `json:"msg"`
		Results         []struct {
			Details []struct {
				Contexts []struct {
					Context   string `json:"context"`
					Positions []struct {
						EndPos   int `json:"endPos"`
						StartPos int `json:"startPos"`
					} `json:"positions"`
				} `json:"contexts"`
				Label string `json:"label"`
			} `json:"details"`
			Label      string  `json:"label"`
			Rate       float64 `json:"rate"`
			Scene      string  `json:"scene"`
			Suggestion string  `json:"suggestion"`
		} `json:"results"`
		TaskId string `json:"taskId"`
	} `json:"data"`
	Msg       string `json:"msg"`
	RequestId string `json:"requestId"`
}

func (*AliyunTextCensorResponse) IsPass

func (r *AliyunTextCensorResponse) IsPass() bool

type ForbiddenType

type ForbiddenType string
const (
	ForbiddenTypeSpam        ForbiddenType = "spam"
	ForbiddenTypeAd          ForbiddenType = "ad"
	ForbiddenTypePolitics    ForbiddenType = "politics"
	ForbiddenTypeTerrorism   ForbiddenType = "terrorism"
	ForbiddenTypeAbuse       ForbiddenType = "abuse"
	ForbiddenTypePorn        ForbiddenType = "porn"
	ForbiddenTypeFlood       ForbiddenType = "flood"
	ForbiddenTypeContraband  ForbiddenType = "contraband"
	ForbiddenTypeMeaningless ForbiddenType = "meaningless"
	ForbiddenTypeHarmful     ForbiddenType = "harmful"
)

func (ForbiddenType) String

func (f ForbiddenType) String() string

type QiniuTextCensor

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

func NewQiniuTextCensor

func NewQiniuTextCensor(accessKey, accessSecret string) *QiniuTextCensor

func (*QiniuTextCensor) Censor

func (c *QiniuTextCensor) Censor(ctx context.Context, text string) (*TextCensorResponse, error)

Censor censors text with Qiniu API. https://developer.qiniu.com/censor/7260/api-text-censor

func (*QiniuTextCensor) String

func (*QiniuTextCensor) String() string

type QiniuTextCensorResponse

type QiniuTextCensorResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Result  struct {
		Suggestion string `json:"suggestion"`
		Scenes     struct {
			Antispam struct {
				Suggestion string `json:"suggestion"`
				Details    []struct {
					Label    string  `json:"label"`
					Score    float64 `json:"score"`
					Contexts []struct {
						Context   string `json:"context"`
						Positions []struct {
							StartPos int `json:"startPos"`
							EndPos   int `json:"endPos"`
						} `json:"positions"`
					} `json:"contexts"`
				} `json:"details"`
			} `json:"antispam"`
		} `json:"scenes"`
	} `json:"result"`
}

func (*QiniuTextCensorResponse) IsPass

func (r *QiniuTextCensorResponse) IsPass() bool

type TextCensor

type TextCensor interface {
	Censor(ctx context.Context, text string) (*TextCensorResponse, error)
	String() string
}

type TextCensorResponse

type TextCensorResponse struct {
	SourceName    string          `json:"source_name"`
	Pass          bool            `json:"pass"`
	ForbiddenType ForbiddenType   `json:"forbidden_type"`
	Hint          string          `json:"hint"`
	Confidence    float64         `json:"confidence"`
	RawResponse   json.RawMessage `json:"raw_response"`
}

func AliyunTextCensorParser

func AliyunTextCensorParser(raw []byte) (*TextCensorResponse, error)

func QiniuTextCensorParser

func QiniuTextCensorParser(raw []byte) (*TextCensorResponse, error)

func Text

func Text(ctx context.Context, text string) (*TextCensorResponse, error)

Text checks the text for sensitive content. It will save the censor log to the database and invoke the callback function.

func (*TextCensorResponse) ErrorMessage

func (r *TextCensorResponse) ErrorMessage() string

func (*TextCensorResponse) ToJSON

func (r *TextCensorResponse) ToJSON() []byte

Jump to

Keyboard shortcuts

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