Skip to content

Commit cad84f3

Browse files
committedMay 31, 2019
update server code, add hmm support
1 parent 27748c7 commit cad84f3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
 

‎server/server.go

+16
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var (
4040

4141
host = flag.String("host", "", "HTTP服务器主机名")
4242
port = flag.Int("port", 8080, "HTTP服务器端口")
43+
hmm = flag.Bool("hmm", false, "use hmm")
4344
dict = flag.String("dict", "../data/dict/dictionary.txt", "词典文件")
4445
staticFolder = flag.String("static_folder", "static", "静态页面存放的目录")
4546
)
@@ -55,6 +56,11 @@ type Segment struct {
5556
Pos string `json:"pos"`
5657
}
5758

59+
// JsonResp json response
60+
type JsonResp struct {
61+
Seg []string
62+
}
63+
5864
// JsonRpcServer json rpc server
5965
func JsonRpcServer(w http.ResponseWriter, req *http.Request) {
6066
// 得到要分词的文本
@@ -63,6 +69,16 @@ func JsonRpcServer(w http.ResponseWriter, req *http.Request) {
6369
text = req.PostFormValue("text")
6470
}
6571

72+
if *hmm {
73+
segs := segmenter.Cut(text, true)
74+
response, _ := json.Marshal(&JsonResp{Seg: segs})
75+
76+
w.Header().Set("Content-Type", "application/json")
77+
io.WriteString(w, string(response))
78+
79+
return
80+
}
81+
6682
// 分词
6783
segments := segmenter.Segment([]byte(text))
6884

0 commit comments

Comments
 (0)
Please sign in to comment.