1
0
mirror of https://github.com/fumiama/jieba.git synced 2026-06-30 00:50:30 +08:00

code refactor for RegexpSplit function, moved it to util.go, add return chan string

This commit is contained in:
Wang Bin
2015-03-24 14:40:06 +08:00
parent 323b6714fa
commit 0027927b6d
5 changed files with 178 additions and 55 deletions

View File

@@ -72,14 +72,13 @@ func cutDetail(sentence string) chan WordTag {
result := make(chan WordTag)
go func() {
blocks := jiebago.RegexpSplit(reHanDetail, sentence)
for _, blk := range blocks {
for blk := range jiebago.RegexpSplit(reHanDetail, sentence) {
if reHanDetail.MatchString(blk) {
for wordTag := range cutDetailInternal(blk) {
result <- wordTag
}
} else {
for _, x := range jiebago.RegexpSplit(reSkipDetail, blk) {
for x := range jiebago.RegexpSplit(reSkipDetail, blk) {
if len(x) == 0 {
continue
}
@@ -242,7 +241,6 @@ func Cut(sentence string, HMM bool) chan WordTag {
delete(jiebago.UserWordTagTab, key)
}
result := make(chan WordTag)
blocks := jiebago.RegexpSplit(reHanInternal, sentence)
var cut cutFunc
if HMM {
cut = cutDAG
@@ -250,13 +248,13 @@ func Cut(sentence string, HMM bool) chan WordTag {
cut = cutDAGNoHMM
}
go func() {
for _, blk := range blocks {
for blk := range jiebago.RegexpSplit(reHanInternal, sentence) {
if reHanInternal.MatchString(blk) {
for wordTag := range cut(blk) {
result <- wordTag
}
} else {
for _, x := range jiebago.RegexpSplit(reSkipInternal, blk) {
for x := range jiebago.RegexpSplit(reSkipInternal, blk) {
if reSkipInternal.MatchString(x) {
result <- WordTag{x, "x"}
} else {