mirror of
https://github.com/fumiama/jieba.git
synced 2026-06-13 13:40:28 +08:00
small tweaks, add docs
This commit is contained in:
@@ -20,6 +20,8 @@ type WordTag struct {
|
||||
Word, Tag string
|
||||
}
|
||||
|
||||
// Set dictionary, it could be absolute path of dictionary file, or dictionary
|
||||
// name in current diectory.
|
||||
func SetDictionary(dictFileName string) error {
|
||||
err := jiebago.SetDictionary(dictFileName)
|
||||
if err != nil {
|
||||
@@ -42,7 +44,7 @@ func cutDetailInternal(sentence string) chan WordTag {
|
||||
|
||||
go func() {
|
||||
runes := []rune(sentence)
|
||||
_, posList := Viterbi(runes)
|
||||
_, posList := viterbi(runes)
|
||||
begin := 0
|
||||
next := 0
|
||||
for i, char := range runes {
|
||||
@@ -232,6 +234,8 @@ func cutDAGNoHMM(sentence string) chan WordTag {
|
||||
return result
|
||||
}
|
||||
|
||||
// Tags the POS of each word after segmentation, using labels compatible with
|
||||
// ictclas.
|
||||
func Cut(sentence string, HMM bool) chan WordTag {
|
||||
for key := range jiebago.UserWordTagTab {
|
||||
wordTagMap[key] = jiebago.UserWordTagTab[key]
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package posseg
|
||||
|
||||
const MinFloat = -3.14e100
|
||||
|
||||
type RuneFloatMap map[rune]float64
|
||||
|
||||
func (m RuneFloatMap) Get(key rune) float64 {
|
||||
if _, ok := m[key]; ok {
|
||||
return m[key]
|
||||
} else {
|
||||
return MIN_FLOAT
|
||||
return MinFloat
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
const MIN_FLOAT = -3.14e100
|
||||
|
||||
type StateTag struct {
|
||||
State byte
|
||||
Tag string
|
||||
@@ -49,7 +47,7 @@ func (pss ProbStates) Swap(i, j int) {
|
||||
pss[i], pss[j] = pss[j], pss[i]
|
||||
}
|
||||
|
||||
func Viterbi(obs []rune) (float64, []StateTag) {
|
||||
func viterbi(obs []rune) (float64, []StateTag) {
|
||||
obsLength := len(obs)
|
||||
V := make([]map[StateTag]float64, obsLength)
|
||||
V[0] = make(map[StateTag]float64)
|
||||
|
||||
@@ -30,8 +30,8 @@ var (
|
||||
|
||||
func TestViterbi(t *testing.T) {
|
||||
ss := "李小福是创新办主任也是云计算方面的专家;"
|
||||
prob, route := Viterbi([]rune(ss))
|
||||
if prob != MIN_FLOAT {
|
||||
prob, route := viterbi([]rune(ss))
|
||||
if prob != MinFloat {
|
||||
t.Error(prob)
|
||||
}
|
||||
if len(route) != len(route1) {
|
||||
|
||||
Reference in New Issue
Block a user