-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from go-ego/range-pr
Optimize load dictionary and stop by embed files, support user dictio…
- Loading branch information
Showing
3 changed files
with
71 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,66 @@ | ||
//go:build go1.16 | ||
// +build go1.16 | ||
|
||
package gse | ||
|
||
import ( | ||
_ "embed" | ||
"testing" | ||
|
||
"github.com/vcaesar/tt" | ||
) | ||
|
||
//go:embed testdata/test_dict3.txt | ||
var testDict string | ||
|
||
//go:embed testdata/test_dict2.txt | ||
var testDict2 string | ||
|
||
//go:embed testdata/stop.txt | ||
var testStop string | ||
|
||
func TestLoadDictEmbed(t *testing.T) { | ||
// var seg1 Segmenter | ||
// err := seg1.LoadDictEmbed() | ||
// tt.Nil(t, err) | ||
var seg2 Segmenter | ||
err := seg2.LoadDictEmbed(testDict) | ||
tt.Nil(t, err) | ||
|
||
seg1, err := NewEmbed("zh, world 20 n", "en") | ||
seg1, err := NewEmbed("zh, word1 20 n, "+testDict+", "+testDict2, "en") | ||
tt.Nil(t, err) | ||
|
||
f, pos, ok := seg1.Find("1号店") | ||
tt.Bool(t, ok) | ||
tt.Equal(t, "n", pos) | ||
tt.Equal(t, 3, f) | ||
|
||
f, pos, ok = seg1.Find("hello") | ||
tt.Bool(t, ok) | ||
tt.Equal(t, "", pos) | ||
tt.Equal(t, 20, f) | ||
|
||
f, pos, ok = seg1.Find("world") | ||
tt.Bool(t, ok) | ||
tt.Equal(t, "n", pos) | ||
tt.Equal(t, 20, f) | ||
|
||
f, pos, ok = seg1.Find("word1") | ||
tt.Bool(t, ok) | ||
tt.Equal(t, "n", pos) | ||
tt.Equal(t, 20, f) | ||
|
||
f, pos, ok = seg1.Find("新星共和国") | ||
tt.Bool(t, ok) | ||
tt.Equal(t, "ns", pos) | ||
tt.Equal(t, 32, f) | ||
|
||
f, _, ok = seg1.Find("八千一百三十七万七千二百三十六口") | ||
tt.Bool(t, ok) | ||
tt.Equal(t, 2, f) | ||
} | ||
|
||
func TestLoadStopEmbed(t *testing.T) { | ||
var seg1 Segmenter | ||
err := seg1.LoadStopEmbed() | ||
err := seg1.LoadStopEmbed("zh, " + testStop) | ||
tt.Nil(t, err) | ||
tt.Bool(t, seg1.IsStop("比如")) | ||
tt.Bool(t, seg1.IsStop("离开")) | ||
} |