예제 #1
0
func whiteSuffixWords(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {
		words := trie.WhiteSuffixTrie().ReadAll()
		str := strings.Join(words, "\n")
		w.Header().Set("Server", "goo")
		w.Header().Set("Content-Type", "text/html; charset=utf-8")
		w.WriteHeader(200)
		w.Write([]byte(str))

	} else if r.Method == "POST" {
		resp := make(map[string]interface{})
		q := r.FormValue("q")
		op := r.FormValue("type")
		if op == "init" {
			trie.NewWhiteSuffixTrie()
		}
		if q == "" {
			resp["code"] = 0
			resp["error"] = "参数q不能为空"
		} else {
			i := 0
			words := strings.Split(q, ",")
			for _, s := range words {
				trie.WhiteSuffixTrie().Add(strings.Trim(s, " "))
				i++
			}

			resp["code"] = 1
			resp["mess"] = fmt.Sprintf("共添加了%d个白名称后缀词", i)
		}

		serveJson(w, resp)
	}
}
예제 #2
0
// 从字典中装入敏感词库
func LoadDict() {
	trieHandle := trie.BlackTrie()
	load(trieHandle, "add", "./dictionary/black/default")
	load(trieHandle, "del", "./dictionary/black/exclude")

	trieHandle = trie.WhitePrefixTrie()
	load(trieHandle, "add", "./dictionary/white/prefix")

	trieHandle = trie.WhiteSuffixTrie()
	load(trieHandle, "add", "./dictionary/white/suffix")
}