File tree 1 file changed +16
-0
lines changed
1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 40
40
41
41
host = flag .String ("host" , "" , "HTTP服务器主机名" )
42
42
port = flag .Int ("port" , 8080 , "HTTP服务器端口" )
43
+ hmm = flag .Bool ("hmm" , false , "use hmm" )
43
44
dict = flag .String ("dict" , "../data/dict/dictionary.txt" , "词典文件" )
44
45
staticFolder = flag .String ("static_folder" , "static" , "静态页面存放的目录" )
45
46
)
@@ -55,6 +56,11 @@ type Segment struct {
55
56
Pos string `json:"pos"`
56
57
}
57
58
59
+ // JsonResp json response
60
+ type JsonResp struct {
61
+ Seg []string
62
+ }
63
+
58
64
// JsonRpcServer json rpc server
59
65
func JsonRpcServer (w http.ResponseWriter , req * http.Request ) {
60
66
// 得到要分词的文本
@@ -63,6 +69,16 @@ func JsonRpcServer(w http.ResponseWriter, req *http.Request) {
63
69
text = req .PostFormValue ("text" )
64
70
}
65
71
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
+
66
82
// 分词
67
83
segments := segmenter .Segment ([]byte (text ))
68
84
You can’t perform that action at this time.
0 commit comments