55import logging
66import importlib .resources
77import spellchecker
8+ import requests
9+ import pathlib
810
911
1012def create_checker (dict_list : list [str ] = None ) -> spellchecker .SpellChecker :
@@ -22,13 +24,26 @@ def create_checker(dict_list: list[str] = None) -> spellchecker.SpellChecker:
2224 english_dict = str (lib_path ) + "/resources/en.json.gz"
2325 logger .info ("Loading English dictionary from: %s" , english_dict )
2426 checker .word_frequency .load_dictionary (english_dict )
27+ logger .info ("number of words: %s" , checker .word_frequency .unique_words )
2528
2629 # load the additional dictionaries
2730 if not isinstance (dict_list , list ):
2831 return checker
2932 if len (dict_list ) > 0 :
3033 for d in dict_list :
3134 logger .info ("Loading additional dictionary from: %s" , d )
32- checker .word_frequency .load_text_file (d )
35+ if isinstance (d , pathlib .PosixPath ):
36+ # assume it's a local file path
37+ checker .word_frequency .load_text_file (d )
38+ else :
39+ # load dictionary from URL
40+ if d .startswith ("http://" ) or d .startswith ("https://" ):
41+ response = requests .get (d )
42+ response .raise_for_status ()
43+ checker .word_frequency .load_text (response .text )
44+ else :
45+ # assume it's a local file path
46+ checker .word_frequency .load_text_file (d )
47+ logger .info ("# of words: %s" , checker .word_frequency .unique_words )
3348
3449 return checker
0 commit comments