MCPcopy Index your code
hub / github.com/huichen/sego / SegmentsToString

Function SegmentsToString

utils.go:17–29  ·  view source on GitHub ↗

输出分词结果为字符串 有两种输出模式,以"中华人民共和国"为例 普通模式(searchMode=false)输出一个分词"中华人民共和国/ns " 搜索模式(searchMode=true) 输出普通模式的再细致切分: "中华/nz 人民/n 共和/nz 共和国/ns 人民共和国/nt 中华人民共和国/ns " 搜索模式主要用于给搜索引擎提供尽可能多的关键字,详情请见Token结构体的注释。

(segs []Segment, searchMode bool)

Source from the content-addressed store, hash-verified

15//
16// 搜索模式主要用于给搜索引擎提供尽可能多的关键字,详情请见Token结构体的注释。
17func SegmentsToString(segs []Segment, searchMode bool) (output string) {
18 if searchMode {
19 for _, seg := range segs {
20 output += tokenToString(seg.token)
21 }
22 } else {
23 for _, seg := range segs {
24 output += fmt.Sprintf(
25 "%s/%s ", textSliceToString(seg.token.text), seg.token.pos)
26 }
27 }
28 return
29}
30
31func tokenToString(token *Token) (output string) {
32 hasOnlyTerminalToken := true

Callers 3

mainFunction · 0.92
TestSegmentFunction · 0.85
TestLargeDictionaryFunction · 0.85

Calls 2

tokenToStringFunction · 0.85
textSliceToStringFunction · 0.85

Tested by 2

TestSegmentFunction · 0.68
TestLargeDictionaryFunction · 0.68