From f6c298fc655b9b4b4214af170427452b9ff662cb Mon Sep 17 00:00:00 2001 From: Wang Bin Date: Thu, 26 Feb 2015 17:38:26 +0800 Subject: [PATCH] small refactor for function names --- jieba.go | 14 +++++++------- jieba_test.go | 4 ++-- posseg/posseg.go | 28 ++++++++++++---------------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/jieba.go b/jieba.go index 290548e..ada0b6e 100644 --- a/jieba.go +++ b/jieba.go @@ -129,7 +129,7 @@ func Calc(sentence string, dag map[int][]int) map[int]*Route { type cutFunc func(sentence string) []string -func cut_DAG(sentence string) []string { +func cutDAG(sentence string) []string { dag := DAG(sentence) routes := Calc(sentence, dag) x := 0 @@ -191,7 +191,7 @@ func cut_DAG(sentence string) []string { return result } -func cut_DAG_NO_HMM(sentence string) []string { +func cutDAGNoHMM(sentence string) []string { result := make([]string, 0) dag := DAG(sentence) @@ -264,21 +264,21 @@ func Cut(sentence string, isCutAll bool, HMM bool) []string { reSkip = reSkipDefault } blocks := RegexpSplit(reHan, sentence) - var cut_block cutFunc + var cut cutFunc if HMM { - cut_block = cut_DAG + cut = cutDAG } else { - cut_block = cut_DAG_NO_HMM + cut = cutDAGNoHMM } if isCutAll { - cut_block = cutAll + cut = cutAll } for _, blk := range blocks { if len(blk) == 0 { continue } if reHan.MatchString(blk) { - for _, word := range cut_block(blk) { + for _, word := range cut(blk) { result = append(result, word) } } else { diff --git a/jieba_test.go b/jieba_test.go index fb6276e..d59a431 100644 --- a/jieba_test.go +++ b/jieba_test.go @@ -622,14 +622,14 @@ func init() { } func TestCutDAG(t *testing.T) { - result := cut_DAG("BP神经网络如何训练才能在分类时增加区分度?") + result := cutDAG("BP神经网络如何训练才能在分类时增加区分度?") if len(result) != 11 { t.Error(result) } } func TestCutDAGNoHmm(t *testing.T) { - result := cut_DAG_NO_HMM("BP神经网络如何训练才能在分类时增加区分度?") + result := cutDAGNoHMM("BP神经网络如何训练才能在分类时增加区分度?") if len(result) != 11 { t.Error(result) } diff --git a/posseg/posseg.go b/posseg/posseg.go index 907c9e9..549517e 100644 --- a/posseg/posseg.go +++ b/posseg/posseg.go @@ -90,9 +90,9 @@ func cutDetail(sentence string) []WordTag { 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) routes := jiebago.Calc(sentence, dag) x := 0 @@ -180,7 +180,7 @@ func cut_DAG(sentence string) []WordTag { return result } -func cut_DAG_NO_HMM(sentence string) []WordTag { +func cutDAGNoHMM(sentence string) []WordTag { result := make([]WordTag, 0) dag := jiebago.DAG(sentence) routes := jiebago.Calc(sentence, dag) @@ -219,18 +219,22 @@ func cut_DAG_NO_HMM(sentence string) []WordTag { 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) blocks := jiebago.RegexpSplit(reHanInternal, sentence) - var cut_block cutAction + var cut cutFunc if HMM { - cut_block = cut_DAG + cut = cutDAG } else { - cut_block = cut_DAG_NO_HMM + cut = cutDAGNoHMM } for _, blk := range blocks { if reHanInternal.MatchString(blk) { - for _, wordTag := range cut_block(blk) { + for _, wordTag := range cut(blk) { result = append(result, wordTag) } } else { @@ -256,11 +260,3 @@ func cut(sentence string, HMM bool) []WordTag { } 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) -}