Using Golang to implement a sensitive vocabulary detection plugin based on DFA algorithm

Source: Internet
Author: User

Sensitivewords

Get

GitHub Address: Https://github.com/TomatoMr/SensitiveWords.git

Or

Go get github.com/tomatomr/sensitivewords

Introduction

Sensitivewords is a sensitive vocabulary detection plug-in based on the DFA algorithm, which can be deployed independently or integrated into the project.

Usage

Standalone deployment

1. Copy the configuration file

CD Config

CP Config.toml.example CONFIG.TOML

2. Building a binary package

Go Build

3. How to use

-restart

: Restart your HTTP server, just like this:-restart or-restart=true|false.

-start [-d]

: Up your HTTP server, just like this:-start Or-start=true|false [-D or-d=true|false].

-stop

:D own your HTTP server, just like this:-stop or-stop=true|false.

4. Api

4.1/check?content=xxx

Function: Returns the first sensitive word in the target text

Return value: Target: "",//first sensitive word

Result: "", whether or not a sensitive word is contained

4.2/all?content=xxx

Function: Returns the first sensitive word in the target text

return value: target:[

Word//sensitive words

Word_indexes//An array of indexes of the same sensitive words in the original text

Word_length//length of the sensitive word

]

Plug-in methods

Getmap ()

Get Sensitivemap Instance

Initdictionary ()

Initialize the sensitive dictionary and get an instance of it

Checksensitive (text string)

Accepts detected text and returns whether it contains sensitive words and first sensitive words

Findallsensitive (text string)

Accept the detected text and return all sensitive words

GetConfig ()

Return to configuration instance

Configuration file Description

Dictionarypath//Sensitive dictionary address, root directory is the address of this project

Port//http server listens for Web ports

Pidfilepath//pid file location, for command line end program and restart program, root directory is this project address

Help

Q: Overloaded dictionaries?

A: Modify config.toml-> Modify Dictionarypath->./sensitivewords-restart

Using the example

1.http://localhost:9981/check?content= "Dirty Words"

{"Result": true, "target": "Dirty word"}

2.http://localhost:9981/all?content= "Dirty Words"

{"Target": [{"word": "Dirty Language", "word_indexes": [0], "word_length": 2}]}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.