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

Feature request : Adding words to the dictionary at runtime #29

Open
gweltou opened this issue Apr 21, 2024 · 2 comments
Open

Feature request : Adding words to the dictionary at runtime #29

gweltou opened this issue Apr 21, 2024 · 2 comments

Comments

@gweltou
Copy link

gweltou commented Apr 21, 2024

Hi,

I used to work with pyhunspell (which doesn't seem to be maintained anymore), then with cyhunspell (which is currently broken on Python >=3.10).

I'm now trying to switch to Spylls but there is one critical feature that I miss : the ability to add words to the loaded dictionary at runtime.

There doesn't seem to be any function for that in the documentation or the source code. Is there a plan to add this feature in the future ?

Thanks a lot !

@zverok
Copy link
Owner

zverok commented Apr 21, 2024

@gweltou Truth be told, I didn’t really expect to see spylls much used in production; I built it as educational material about how the classic spellchecker works. This is why it lacks some of the more “pragmatic” features that don’t affect the base principles.

I don’t expect to actively develop it further, for reasons both professional (what is said above) and personal (I am serving in the Ukrainian army currently); but I probably have enough capacity to accept PRs.

This being said, adding word to the dictionary can be achieved by exploiting internal APIs, though I can’t say it is convenient:

from spylls.hunspell import Dictionary

dictionary = Dictionary.from_files('internal/dictionaries/en_US')

from spylls.hunspell.data.dic import Word
from spylls.hunspell.algo.capitalization import Type

print(dictionary.lookup('Hogwarts')) #=> False

word = Word('Hogwarts', flags=set(), data={}, alt_spellings=[], captype=Type.INIT)
dictionary.dic.append(word, lower='hogwarts')

print(dictionary.lookup('Hogwarts')) #=> True

As APIs are internal, they expect a lot of arguments pre-calculated by the corresponding processes, but I assume that reusing those APIs, a reasonable public Dictionary.append('word', like='other_word') (common for various Hunspell wrappers) can be achieved.

@gweltou
Copy link
Author

gweltou commented Apr 24, 2024

Thank you for your answer ! I can definitely work with that !

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

No branches or pull requests

2 participants