Skip to content

Commit

Permalink
Merge pull request #16 from snapp-incubator/fix/check-minchar-length
Browse files Browse the repository at this point in the history
fix min char length
  • Loading branch information
sepehrsoh authored Feb 9, 2025
2 parents 31ab7b5 + b1d4656 commit f0c464f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/lookup_compound.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (s *SymSpell) LookupCompound(phrase string, maxEditDistance int) *items.Sug
// Combine adjacent terms
if i > 0 && !cp.isLastCombi {
cp.terms2 = terms1[i-1]
suggestionsCombi, _ := s.Lookup(cp.terms2+cp.terms1, verbositypkg.Top, maxEditDistance)
suggestionsCombi, _ := s.Lookup(fmt.Sprintf("%s %s", cp.terms2, cp.terms1), verbositypkg.Top, maxEditDistance)
if len(suggestionsCombi) > 0 {
best1 := cp.suggestionParts[len(cp.suggestionParts)-1]
best2 := s.getBestSuggestion2(cp, maxEditDistance)
Expand Down Expand Up @@ -114,7 +114,7 @@ func (s *SymSpell) LookupCompound(phrase string, maxEditDistance int) *items.Sug
}

func (s *SymSpell) getSuggestion(cp *compoundProcessor, maxEditDistance int) {
if len(cp.terms1) > s.MinimumCharToChange {
if len([]rune(cp.terms1)) > s.MinimumCharToChange {
cp.suggestions, _ = s.Lookup(cp.terms1, verbositypkg.Top, maxEditDistance)
} else {
cp.suggestions = []items.SuggestItem{{
Expand Down
18 changes: 17 additions & 1 deletion symspell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,22 @@ func TestSymspellLookupCompoundUnigram(t *testing.T) {
},
want: "بیمارستان ا",
},
{
name: "Test Min Character 2",
args: args{
a: "بیمارستان اما",
maxEditDistance: 3,
},
want: "بیمارستان اما",
},
{
name: "Test Min Character 3",
args: args{
a: "ا ب ث",
maxEditDistance: 3,
},
want: "ا ب ث",
},
{
name: "Split Number",
args: args{
Expand Down Expand Up @@ -245,7 +261,7 @@ func TestSymspellLookupCompoundUnigram(t *testing.T) {
options.WithMaxDictionaryEditDistance(3),
options.WithSplitItemThreshold(100),
options.WithSplitWordBySpace(),
options.WithMinimumCharacterToChange(2),
options.WithMinimumCharacterToChange(3),
options.WithSplitWordAndNumbers(),
)
for _, tt := range tests {
Expand Down

0 comments on commit f0c464f

Please sign in to comment.