Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Q] Add custom words to loaded dictionary? #41

Open
Herve-M opened this issue Sep 16, 2019 · 5 comments
Open

[Q] Add custom words to loaded dictionary? #41

Herve-M opened this issue Sep 16, 2019 · 5 comments
Labels

Comments

@Herve-M
Copy link

Herve-M commented Sep 16, 2019

Hello,

I didn't find any ticket or test about adding custom words to a loaded dictionary.
Is it possible?

Or do it need to re-create a new dictionary by merging?

Thanks,
Hervé

@aarondandy
Copy link
Owner

aarondandy commented Sep 25, 2019

I designed the implementation/port to be read-only and immutable. There could be thread safety issues with mutating a dictionary after it is loaded and the use case I was targeting at the time was strictly about quickly checking words. Now, lets say for example you wanted to support something such as "Add words to dictionary." The way I would recommend implementing that is to keep a separate dictionary (it doesn't even need to be hunspell) and use that for your other words. If you do want to use this lib for that custom dictionary, for suggestions as an example, it would have to be rebuilt for each new word.

Now if this is to become a feature request, that is a pretty interesting feature but would be very difficult to implement safely I think considering how spaghetti like the code is already 🍝 . I cleaned it up as best I could though, but it definitely feels like a challenging feature.

@aarondandy
Copy link
Owner

I just had a thought, one way this could be practical is based on how I had to create a "query" object to represent each suggestion and check call. I did this initially to move all the global/static variables into there so that queries could be made in parallel. This could be leveraged so that each running query could grab a reference to the immutable internal variables that make up a dictionary and affix structure. A mutation to the entire structure could possibly be done in an atomic way by cleverly swapping references around maybe. 🤔

@shell
Copy link

shell commented Jan 14, 2022

@aarondandy is there more information about this question?

I have the same problem that I need to implement custom user dictionaries for spellchecking and suggesting capabilities. I was using .AddWord and .RemoveWord when using NHunspell. It added words to something called "Internal dictionary" when using NHunspell package.
It seems it would be problematic if I use this package?

@aarondandy
Copy link
Owner

Nothing has changed yet, for now I recommend keeping two dictionaries. One dictionary from file, such as an en-us dictionary, and another dictionary in memory for the user's custom words. Example: https://github.com/aarondandy/WeCantSpell.Hunspell/blob/2c95ea91a1ca40a36b3b5dab219ca38dd613eebb/test/WeCantSpell.Hunspell.Tests/WordListTests.cs

@funex
Copy link

funex commented Dec 6, 2022

@aarondandy Just as a side note, if I'm not mistaken, NHunspell dictionaries are also immutable, the words are added/removed to/from the available instance in memory. Once the dictionary is reloaded, the added words are gone and the removed words are back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants