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

small refactor for function names

This commit is contained in:
Wang Bin
2015-02-26 17:38:26 +08:00
parent 2bda0be7c5
commit f6c298fc65
3 changed files with 21 additions and 25 deletions

View File

@@ -129,7 +129,7 @@ func Calc(sentence string, dag map[int][]int) map[int]*Route {
type cutFunc func(sentence string) []string type cutFunc func(sentence string) []string
func cut_DAG(sentence string) []string { func cutDAG(sentence string) []string {
dag := DAG(sentence) dag := DAG(sentence)
routes := Calc(sentence, dag) routes := Calc(sentence, dag)
x := 0 x := 0
@@ -191,7 +191,7 @@ func cut_DAG(sentence string) []string {
return result return result
} }
func cut_DAG_NO_HMM(sentence string) []string { func cutDAGNoHMM(sentence string) []string {
result := make([]string, 0) result := make([]string, 0)
dag := DAG(sentence) dag := DAG(sentence)
@@ -264,21 +264,21 @@ func Cut(sentence string, isCutAll bool, HMM bool) []string {
reSkip = reSkipDefault reSkip = reSkipDefault
} }
blocks := RegexpSplit(reHan, sentence) blocks := RegexpSplit(reHan, sentence)
var cut_block cutFunc var cut cutFunc
if HMM { if HMM {
cut_block = cut_DAG cut = cutDAG
} else { } else {
cut_block = cut_DAG_NO_HMM cut = cutDAGNoHMM
} }
if isCutAll { if isCutAll {
cut_block = cutAll cut = cutAll
} }
for _, blk := range blocks { for _, blk := range blocks {
if len(blk) == 0 { if len(blk) == 0 {
continue continue
} }
if reHan.MatchString(blk) { if reHan.MatchString(blk) {
for _, word := range cut_block(blk) { for _, word := range cut(blk) {
result = append(result, word) result = append(result, word)
} }
} else { } else {

View File

@@ -622,14 +622,14 @@ func init() {
} }
func TestCutDAG(t *testing.T) { func TestCutDAG(t *testing.T) {
result := cut_DAG("BP神经网络如何训练才能在分类时增加区分度") result := cutDAG("BP神经网络如何训练才能在分类时增加区分度")
if len(result) != 11 { if len(result) != 11 {
t.Error(result) t.Error(result)
} }
} }
func TestCutDAGNoHmm(t *testing.T) { func TestCutDAGNoHmm(t *testing.T) {
result := cut_DAG_NO_HMM("BP神经网络如何训练才能在分类时增加区分度") result := cutDAGNoHMM("BP神经网络如何训练才能在分类时增加区分度")
if len(result) != 11 { if len(result) != 11 {
t.Error(result) t.Error(result)
} }

View File

@@ -90,9 +90,9 @@ func cutDetail(sentence string) []WordTag {
return result return result
} }
type cutAction func(sentence string) []WordTag type cutFunc func(sentence string) []WordTag
func cut_DAG(sentence string) []WordTag { func cutDAG(sentence string) []WordTag {
dag := jiebago.DAG(sentence) dag := jiebago.DAG(sentence)
routes := jiebago.Calc(sentence, dag) routes := jiebago.Calc(sentence, dag)
x := 0 x := 0
@@ -180,7 +180,7 @@ func cut_DAG(sentence string) []WordTag {
return result return result
} }
func cut_DAG_NO_HMM(sentence string) []WordTag { func cutDAGNoHMM(sentence string) []WordTag {
result := make([]WordTag, 0) result := make([]WordTag, 0)
dag := jiebago.DAG(sentence) dag := jiebago.DAG(sentence)
routes := jiebago.Calc(sentence, dag) routes := jiebago.Calc(sentence, dag)
@@ -219,18 +219,22 @@ func cut_DAG_NO_HMM(sentence string) []WordTag {
return result return result
} }
func cut(sentence string, HMM bool) []WordTag { func Cut(sentence string, HMM bool) []WordTag {
for key := range jiebago.UserWordTagTab {
wordTagMap[key] = jiebago.UserWordTagTab[key]
delete(jiebago.UserWordTagTab, key)
}
result := make([]WordTag, 0) result := make([]WordTag, 0)
blocks := jiebago.RegexpSplit(reHanInternal, sentence) blocks := jiebago.RegexpSplit(reHanInternal, sentence)
var cut_block cutAction var cut cutFunc
if HMM { if HMM {
cut_block = cut_DAG cut = cutDAG
} else { } else {
cut_block = cut_DAG_NO_HMM cut = cutDAGNoHMM
} }
for _, blk := range blocks { for _, blk := range blocks {
if reHanInternal.MatchString(blk) { if reHanInternal.MatchString(blk) {
for _, wordTag := range cut_block(blk) { for _, wordTag := range cut(blk) {
result = append(result, wordTag) result = append(result, wordTag)
} }
} else { } else {
@@ -256,11 +260,3 @@ func cut(sentence string, HMM bool) []WordTag {
} }
return result return result
} }
func Cut(sentence string, HMM bool) []WordTag {
for key := range jiebago.UserWordTagTab {
wordTagMap[key] = jiebago.UserWordTagTab[key]
delete(jiebago.UserWordTagTab, key)
}
return cut(sentence, HMM)
}