FooSoft / yomichan

Japanese pop-up dictionary extension for Chrome and Firefox.
https://foosoft.net/projects/yomichan
Other
1.06k stars 213 forks source link

Yomichan doesn't prioritize exact matches with text replacement #2082

Open MarvNC opened 2 years ago

MarvNC commented 2 years ago

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. chrome_ごわごわ_-_Yomichan_Search_-_Google_Chrome_2022-03-10_13-06-51

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.)

siikamiika commented 2 years ago

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

  1. https://en.wikipedia.org/wiki/Levenshtein_distance