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

fs.File -> io.Reader

This commit is contained in:
源文雨
2022-12-03 10:54:06 +08:00
parent 35ac98dc5f
commit 36c17a10b5
11 changed files with 28 additions and 28 deletions

View File

@@ -1,7 +1,7 @@
package analyse
import (
"io/fs"
"io"
"sort"
"sync"
@@ -39,7 +39,7 @@ func (i *Idf) Load(tokens ...dictionary.Token) {
i.Unlock()
}
func (i *Idf) loadDictionary(file fs.File) error {
func (i *Idf) loadDictionary(file io.Reader) error {
return dictionary.LoadDictionary(i, file)
}

View File

@@ -1,7 +1,7 @@
package analyse
import (
"io/fs"
"io"
"sync"
"github.com/fumiama/jieba/dictionary"
@@ -83,7 +83,7 @@ func (s *StopWord) Load(tokens ...dictionary.Token) {
s.Unlock()
}
func (s *StopWord) loadDictionary(file fs.File) error {
func (s *StopWord) loadDictionary(file io.Reader) error {
return dictionary.LoadDictionary(s, file)
}

View File

@@ -2,7 +2,7 @@
package analyse
import (
"io/fs"
"io"
"sort"
"strings"
"unicode/utf8"
@@ -53,7 +53,7 @@ type TagExtracter struct {
}
// LoadDictionary reads the given filename and create a new dictionary.
func (t *TagExtracter) LoadDictionary(file fs.File) (err error) {
func (t *TagExtracter) LoadDictionary(file io.Reader) (err error) {
t.stopWord = NewStopWord()
t.seg, err = jieba.LoadDictionary(file)
return
@@ -67,7 +67,7 @@ func (t *TagExtracter) LoadDictionaryAt(file string) (err error) {
}
// LoadIdf reads the given file and create a new Idf dictionary.
func (t *TagExtracter) LoadIdf(file fs.File) error {
func (t *TagExtracter) LoadIdf(file io.Reader) error {
t.idf = NewIdf()
return t.idf.loadDictionary(file)
}
@@ -79,7 +79,7 @@ func (t *TagExtracter) LoadIdfAt(fileName string) error {
}
// LoadStopWords reads the given file and create a new StopWord dictionary.
func (t *TagExtracter) LoadStopWords(file fs.File) error {
func (t *TagExtracter) LoadStopWords(file io.Reader) error {
t.stopWord = NewStopWord()
return t.stopWord.loadDictionary(file)
}

View File

@@ -2,7 +2,7 @@ package analyse
import (
"hash/crc64"
"io/fs"
"io"
"math"
"sort"
@@ -171,7 +171,7 @@ func (t *TextRanker) TextRank(sentence string, topK int) Segments {
type TextRanker posseg.Segmenter
// NewTextRanker reads a given file and create a new dictionary file for Textranker.
func NewTextRanker(file fs.File) (*TextRanker, error) {
func NewTextRanker(file io.Reader) (*TextRanker, error) {
seg, err := posseg.LoadDictionary(file)
return (*TextRanker)(seg), err
}