yomichan
yomichan copied to clipboard
Yomichan doesn't prioritize exact matches with text replacement
Description
I've noticed this happen on many words. If you have text replacement on (hiragana to katakana here) then sometimes a non exact match will appear first.
ごわごわ is one example but it happens to other words as well. It does not appear to be affected by the use of a frequency sorting dictionary.
Browser version Chrome Version 99.0.4844.51 (Official Build) (64-bit)
Yomichan version Yomichan 21.10.31.1
Exported settings file (If you think it might be relevant, create a settings export file using the Export Settings button on the settings page; zip or rename the resulting file to .txt to attach to the issue.)
I agree that exact text match sometimes has significance. I haven't looked at the code for a while so I am not sure if this is the correct place in code, but I believe that the sort function Translator._sortTermDictionaryEntryDefinitions
should take text
in Translator.findTerms
and use it in addition to the other attributes in each term. Perhaps a distance function [1] or just v1 equals --> 1, v2 equals --> -1 or both equal --> 0.
https://github.com/FooSoft/yomichan/blob/289a61a62fd5cb41223ef639b1e83e290e1a9c77/ext/js/language/translator.js#L77-L115
https://github.com/FooSoft/yomichan/blob/289a61a62fd5cb41223ef639b1e83e290e1a9c77/ext/js/language/translator.js#L1416-L1450
- https://en.wikipedia.org/wiki/Levenshtein_distance