[Hack] Multiple spelling corrections are returned - #1254
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1254 +/- ##
==========================================
+ Coverage 42.87% 42.92% +0.04%
==========================================
Files 60 60
Lines 4744 4746 +2
Branches 2498 2498
==========================================
+ Hits 2034 2037 +3
- Misses 1088 1089 +1
+ Partials 1622 1620 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Here is a package that allows to evaluate the approach based on Levenshtein distance solution to multiple suggestions. The three misspellings used in the demo script produce the following results I set a limit of 100 on the number of spelling corrections to be returned. As you can see xapian's implementation of Levenshtein distance (+my hack to have more than a single result returned) produces for Please play with other misspellings and tell me if we should pursue this approach (or a variant of it) or go with a user-configurable general-purpose spell-checker instead. |
|
Maybe @ojwb you would have an insightful comment here. We have been trying to implement since months an effecient spellchecking system for the german dictionary DWDS. First implementation is #1230 but it delivers only one result (we would like to have many results if many of them share the same TOP Levenstein distance) and we try here to deliver more results... but like you see we pretty much struggle to get the quality suggestions we expect. Do we do something wrong? |
|
I can't seem to reproduce the problem in current Xapian git master (and nothing in this area has changed for a while): I see the same with 1.4.29. If it's a Xapian bug, it could perhaps be to do with checking spellings with uncommitted spelling changes (the way that's implemented I'd expect it should just be handled transparently, but it's something you are doing here that is more unusual and so probably less well tested). You could try adding As a more general point, I'd suggest you probably should call Also, I assume all your spellings are always added with frequency 1? For words where it is more |
@ojwb I was able to reproduce your example with 1.4.18 However when I populate the database with the more than 240 thousand entries found in the DWDS dictionary, |
@ojwb Thanks! That's a useful hint. |
@kelson42 I am not so much concerned about a potential bug in xapian, as about the usefulness of the Levenshtein distance based approach of spelling correction to DWDS's use case. I think I have demonstrated that that approach will produce non-relevant spelling suggestions for language learners (as opposed to random mistakes made when typing the word). |
|
@veloman-yunkan Please can you put a copy of your |
@kelson42 @gremid Can I publicly share the word list of the DWDS dictionary? |
@veloman-yunkan I think this is OK. Go ahead. |
@ojwb Here you are - dwds_zim_titles.zip. Run the following command after unpacking the archive: |
|
Thanks, I can reproduce the problem locally now. |
|
This much shorter list is enough to trigger it: There's an n-gram filter which identifies candidate words to calculate the edit distance for. What's happening is that I'm unsure of the logic behind this threshold - I don't see it documented in the code, but maybe it's in an old ticket somewhere. Making the threshold 3 here fixes this case, but I think I could construct examples which fail with arbitrary thresholds so it seems this may just be flawed. We may be able to just drop the check without too much impact - the edit distance calculation has been optimised and is now much faster than it used to be (I've done some experiments doing spelling correction without storing any special spelling data and just considering unstemmed terms as correctly spelled words and even that seems fast enough). I'll investigate further and decide what the best way to address it is. Thanks again for providing the data to reproduce. |
I've pushed a fix: xapian/xapian@e91ba89 FWIW, with this fixed the suggested correction for |
This is likely a throwaway PR intended to enable the customer to test a solution to openzim/libzim#1012 that may be implemented in a cleaner way at more development cost.