-
Notifications
You must be signed in to change notification settings - Fork 232
Update: move const to types make code simpler #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,7 +19,6 @@ import ( | |||||
| "unicode/utf8" | ||||||
|
|
||||||
| "github.com/go-ego/gse" | ||||||
| "github.com/go-ego/gse/consts" | ||||||
| "github.com/go-ego/gse/hmm/segment" | ||||||
| "github.com/go-ego/gse/hmm/stopwords" | ||||||
| "github.com/go-ego/gse/types" | ||||||
|
|
@@ -74,7 +73,7 @@ func (bm25 *BM25) LoadDict(files ...string) error { | |||||
| for i, v := range files { | ||||||
| dictFiles[i] = &types.LoadDictFile{ | ||||||
| FilePath: v, | ||||||
| FileType: consts.LoadDictTypeBM25, | ||||||
| FileType: types.LoadDictTypeBM25, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -85,7 +84,7 @@ func (bm25 *BM25) LoadDict(files ...string) error { | |||||
| func (bm25 *BM25) LoadDictStr(dictStr string) error { | ||||||
| dictFile := &types.LoadDictFile{ | ||||||
| FilePath: dictStr, | ||||||
| FileType: consts.LoadDictTypeBM25, | ||||||
| FileType: types.LoadDictTypeBM25, | ||||||
| } | ||||||
| return bm25.Seg.LoadTFIDFDictStr(dictFile) | ||||||
| } | ||||||
|
|
@@ -184,15 +183,15 @@ func NewBM25(bm25Setting *types.BM25Setting) Relevance { | |||||
| // init value | ||||||
| if bm25Setting == nil { | ||||||
| bm25Setting = &types.BM25Setting{ | ||||||
| K1: consts.BM25DefaultK1, | ||||||
| B: consts.BM25DefaultB, | ||||||
| K1: types.BM25DefaultK1, | ||||||
| B: types.BM25DefaultB, | ||||||
| } | ||||||
| } | ||||||
| if bm25Setting.K1 == 0 { | ||||||
| bm25Setting.K1 = consts.BM25DefaultK1 | ||||||
| bm25Setting.K1 = types.BM25DefaultK1 | ||||||
| } | ||||||
| if bm25Setting.B == 0 { | ||||||
| bm25Setting.K1 = consts.BM25DefaultB | ||||||
| bm25Setting.K1 = types.BM25DefaultB | ||||||
|
||||||
| bm25Setting.K1 = types.BM25DefaultB | |
| bm25Setting.B = types.BM25DefaultB |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,3 +19,30 @@ type BM25Setting struct { | |||||
| // and we define B = 0.75 for defult value in `consts/dict_file.go` | ||||||
| B float64 | ||||||
| } | ||||||
|
|
||||||
| const ( | ||||||
| // dict file type to loading | ||||||
|
|
||||||
| // LoadDictTypeIDF dict of IDF to loading | ||||||
| LoadDictTypeIDF = iota + 1 | ||||||
|
Comment on lines
+23
to
+27
|
||||||
|
|
||||||
| // LoadDictTypeTFIDF dict of TFIDF to loading | ||||||
| LoadDictTypeTFIDF | ||||||
|
Comment on lines
+23
to
+30
|
||||||
|
|
||||||
| // LoadDictTypeBM25 dict of BM25 to loading | ||||||
| LoadDictTypeBM25 | ||||||
|
|
||||||
| // LoadDictTypeWithPos dict of with position to loading | ||||||
| LoadDictTypeWithPos | ||||||
|
|
||||||
| // LoadDictCorpus dict of corpus to loading | ||||||
| LoadDictCorpus | ||||||
| ) | ||||||
|
|
||||||
| const ( | ||||||
| // BM25DefaultK1 default k1 value for calculate bm25 | ||||||
| BM25DefaultK1 = 1.25 | ||||||
|
|
||||||
| // BM25DefaultK1 default B value for calculate bm25 | ||||||
|
||||||
| // BM25DefaultK1 default B value for calculate bm25 | |
| // BM25DefaultB default B parameter value for calculating bm25 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After fixing the defaulting logic for
B, it would be good to add a unit test coveringNewBM25defaults (e.g.,nilsettings and settings withB == 0) to prevent regressions. There are already Go tests in this repo (e.g.dict_1.16_test.go), but BM25 defaulting isn’t currently exercised.