1
0
mirror of https://github.com/fumiama/jieba.git synced 2026-06-10 03:30:24 +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
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 {

View File

@@ -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)
}

View File

@@ -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)
}