1
0
mirror of https://github.com/fumiama/jieba.git synced 2026-06-19 01:40:24 +08:00

make some public variable/function to private

This commit is contained in:
Wang Bin
2015-02-28 18:08:57 +08:00
parent a43924173d
commit d06ba85b0b
5 changed files with 22 additions and 17 deletions

View File

@@ -62,10 +62,10 @@ func ExtractTags(sentence string, topK int) (tags TfIdfs) {
tis := make(TfIdfs, 0)
for k, v := range freq {
var ti TfIdf
if freq_, ok := idfLoader.Freq[k]; ok {
if freq_, ok := loader.Freq[k]; ok {
ti = TfIdf{Word: k, Freq: freq_ * v}
} else {
ti = TfIdf{Word: k, Freq: idfLoader.Median * v}
ti = TfIdf{Word: k, Freq: loader.Median * v}
}
tis = append(tis, ti)
}

View File

@@ -6,26 +6,26 @@ import (
)
var (
idfLoader *IDFLoader
loader *idfLoader
)
func init() {
idfLoader = NewIDFLoader()
loader = newIDFLoader()
}
type IDFLoader struct {
type idfLoader struct {
Path string
Freq map[string]float64
Median float64
}
func NewIDFLoader() *IDFLoader {
loader := new(IDFLoader)
func newIDFLoader() *idfLoader {
loader := new(idfLoader)
loader.Freq = make(map[string]float64)
return loader
}
func (loader *IDFLoader) newPath(idfFilePath string) error {
func (loader *idfLoader) newPath(idfFilePath string) error {
if loader.Path == idfFilePath {
return nil
}
@@ -46,10 +46,12 @@ func (loader *IDFLoader) newPath(idfFilePath string) error {
return nil
}
// Set the IDF file path, could be absolute path of IDF file, or IDF file
// name in current directory.
func SetIdf(idfFileName string) error {
idfFilePath, err := jiebago.DictPath(idfFileName)
if err != nil {
return err
}
return idfLoader.newPath(idfFilePath)
return loader.newPath(idfFilePath)
}

View File

@@ -42,6 +42,8 @@ func init() {
}
}
// Set the stop words file path, could be absolute path of stop words file, or
// file name in current directory.
func SetStopWords(stopWordsFileName string) error {
stopWordsFilePath, err := jiebago.DictPath(stopWordsFileName)
if err != nil {

View File

@@ -7,9 +7,7 @@ import (
"sort"
)
const (
DampingFactor = 0.85
)
const dampingFactor = 0.85
var (
defaultAllowPOS = []string{"ns", "n", "vn", "v"}
@@ -95,7 +93,7 @@ func (u *undirectWeightedGraph) rank() TfIdfs {
for _, e := range inedges {
s += e.weight / outSum[e.end] * ws[e.end]
}
ws[n] = (1 - DampingFactor) + DampingFactor*s
ws[n] = (1 - dampingFactor) + dampingFactor*s
}
}
minRank := math.MaxFloat64
@@ -158,6 +156,9 @@ func TextRank(sentence string, topK int) TfIdfs {
return TextRankWithPOS(sentence, topK, defaultAllowPOS)
}
// Set the dictionary, could be absolute path of dictionary file, or dictionary
// name in current directory. This function must be called before cut any
// sentence.
func SetDictionary(dictFileName string) error {
return posseg.SetDictionary(dictFileName)
}