View Single Post
Old 04-18-2025, 07:35 PM   #82
maxthegold
Member
maxthegold began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Mar 2011
Location: Weston-super-Mare, U.K.
Device: Kobo Libra 2
Quote:
Originally Posted by lomkiri View Post
To maxthegold and moldy:

In that way, you'll call the function capitalize() a lot, and you create 2 more tests in the loop, it's more efficient to modify directly the dict, automatically adding in it the capitalized form. In this way, you call the function only once for each word, at the initialization, it will be more efficient (and quicker on big ebooks).

And, as I put the possibility of capitalization as a parameter (True by default), I prefer not to put this test in the loop but in the init, for the same reason.

Furthermore, if "Paul" (for example) is in your dict, your code will search twice for it ("Paul" == "Paul".capitalize()), which is not the case in the code I propose.

Of course, the regex for those words, if provided, will be the same for lower case and capitalized case. If you don't want that for some words, put explicitly both forms in the dict

I have modified the code in the message 63 to include this feature. I also added a counter with the number of entries including the capitalized words in the dict.
I absolutely see your point, but at the time, I had over a thousand entries in my JSON file, and I am lazy. I wasn't particularly concerned about the added processing time. I like your solution, though, particularly as I now have about 1500 JSON entries. I'll give it a try. Keep up the excellent work lomkiri.
maxthegold is offline   Reply With Quote