In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shows you how GO language uses K-nearest neighbor algorithm to realize porn detection in novels. The content is concise and easy to understand, which can definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Usuage:
Go run kNN.go-file= "data.txt"
The key is the selection of vector points and the determination of threshold.
Package main import ("bufio"flag"fmt"io"log"math"os"path"path/filepath") var debug bool = falsevar data_dir string = ". / moyan" / / File storage directory var limen float64 = 0.1159203888322267 / / threshold const (MIN_HANZI rune = 0x3400 MAX_HANZI rune = 0x9fbb) var labels [] rune = [] rune {0x817f, 0x80f8, 0x4e73, 0x81c0, 0x5c41, 0x80a1, 0x88f8, 0x6deb } func errHandle (err error) {if err! = nil {log.Fatal (err)}} func load (name string) (m map [rune] int, err error) {f, err: = os.Open (name) if err! = nil {return nil, err} defer f.Close () buf: = bufio.NewReader (f) m = make (map [rune] int) var r rune for {r, _ Err = buf.ReadRune () if err! = nil {if err = = io.EOF {break} return nil, err} if r > = MIN_HANZI & & r = limen: fmt.Println (fp, dis, "pornographic") case dis = = 1.0: fmt.Println (fp, dis, "are you cheating") case dis = = 0: fmt.Println (fp, dis) "check whether the file character encoding is in utf8 format") default: fmt.Println (fp, dis, "normal")}} func walkFunc (fp string, info os.FileInfo, err error) error {if path.Ext (fp) = = ".txt" {m, err: = load (fp) errHandle (err) _, dis: = classify (m) check (fp, dis)} return err} var file string func init () {_ Err: = os.Stat (data_dir) if err! = nil {err = os.Mkdir (data_dir, os.ModePerm) errHandle (err)} flag.StringVar (& file, "file", "", "file read in,if you don't give the file read in," + "it will create a data dictionary,just pust your files in it")} func main () {flag.Parse () if file = "" {filepath.Walk (data_dir) WalkFunc) return} m, err: = load (file) errHandle (err) _, dis: = classify (m) check (file, dis)} the above is how GO language uses K-nearest neighbor algorithm to realize novel porn detection. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.