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

Commit

Permalink
fixed Suggester.suggestNgram error which it occurs when the first wor…
Browse files Browse the repository at this point in the history
…d begins with a non-alphabetic character.
  • Loading branch information
high-moctane committed Oct 1, 2019
1 parent 56c9c77 commit 0adb536
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions suggester.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ func (sg *Suggester) suggestNgram(words []string) (candidates []string, err erro
// open data
n := len(words) + 1
initial := strings.ToLower(string([]rune(words[0])[0]))
if (initial < "A" || "Z" <= initial) && (initial < "a" || "z" <= initial) {
return
}

f, err := os.Open(sg.filePath(n, initial))
if err != nil {
return
Expand Down
8 changes: 8 additions & 0 deletions suggester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ func TestSuggester_SuggestNgram(t *testing.T) {
[]string{"I felt paint"},
nil,
},
{
[]string{"0000000000"},
nil,
},
{
[]string{"🤔"},
nil,
},
}

for idx, test := range tests {
Expand Down

0 comments on commit 0adb536

Please sign in to comment.