Skip to content
This repository has been archived by the owner on Mar 29, 2022. It is now read-only.

Commit

Permalink
don't raise error when data file is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
high-moctane committed Jan 30, 2020
1 parent 7ae9ff7 commit 846571e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nextword.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ func (nw *Nextword) searchNgram(ngram []string) (candidates []string, err error)

// open
path := filepath.Join(nw.params.DataPath, fname)
if _, err = os.Stat(path); err != nil {
return nil, nil
}
f, err := os.Open(path)
if err != nil {
return
Expand Down
24 changes: 24 additions & 0 deletions nextword_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,30 @@ func TestNextword_Suggest(t *testing.T) {
nil,
nil,
},

// not alphabet
{
"-",
&NextwordParams{
DataPath: NextwordTestDataPath,
CandidateNum: 10,
Greedy: false,
},
nil,
nil,
},

// not alphabet
{
"- ",
&NextwordParams{
DataPath: NextwordTestDataPath,
CandidateNum: 10,
Greedy: false,
},
nil,
nil,
},
}

for idx, test := range tests {
Expand Down

0 comments on commit 846571e

Please sign in to comment.