aarondandy / WeCantSpell.Hunspell

A port of Hunspell v1 for .NET and .NET Standard
https://www.nuget.org/packages/WeCantSpell.Hunspell/
Other
126 stars 19 forks source link

Suggest Method Returns Only Single Suggestion #88

Closed hetavi-chaudhary closed 2 months ago

hetavi-chaudhary commented 3 months ago

We have recently migrated our code from Python to .NET and are encountering an issue with the Suggest method in WeCantSpell.Hunspell version 5.0.0. In our Python implementation, using hunspell==0.3.2, the Suggest method correctly returned multiple suggestions for a given search term. However, in .NET, it only provides a single suggestion, even when there are multiple potential matches.

We create the word list using WordList.CreateFromWords(inputstringList) and then use dictionary.Suggest(searchString) to get suggestions. Instead of getting all possible matches, we only receive a single suggestion each time.

var inputstringList = new List<string> { "Seville", "Deville" };
var dictionary = WordList.CreateFromWords(inputstringList);
var suggestions = dictionary.Suggest(searchString);

When using the Suggest method with a search term like "Sevill", we expect to receive both "Seville" and "Deville" as suggestions. However, we are only getting a single suggestion, typically "Seville," when it should return both.

Context:

WeCantSpell.Hunspell Version: 5.0.0 .NET Version: 8 Python Version: hunspell==0.3.2

aarondandy commented 2 months ago

it should return both

To my knowledge, there isn't any real way to do this exactly with origin (https://github.com/hunspell/hunspell) so it isn't clear to me how this should work. This port has a goal of treating the original C/C++ hunspell library as what it should match for behavior. Because of that, I would avoid making a behavioral change to match the behavior of another port or what may be an older version of hunspell.

I do agree that it would be nice to see both words suggested for your query. When debugging, it would be interesting to see what case in the code causes "Deville" to be rejected as a suggestion. Knowing the specifics there as well as how to create a similar reproduction in the original C++ library/tools would make the path forward much more clear.

hetavi-chaudhary commented 2 months ago

We've managed to handle our use case. Thank you for your response!

aarondandy commented 1 month ago

I have not come up with a total fix for this, and I'm still not sure what the correct suggestion is for this, but I do have something in the works that will consistently return "Seville" as the suggestion for "Sevill". Issue #92 I think was the root cause of the inconsistent behavior, so at least that should be improved in the next release.