feat: sort results by average frequency across all dictionaries - #2460
Open
wtestcase wants to merge 1 commit into
Open
feat: sort results by average frequency across all dictionaries#2460wtestcase wants to merge 1 commit into
wtestcase wants to merge 1 commit into
Conversation
…ries Adds an "Average (all dictionaries)" option to the frequency sorting dictionary setting. When selected, results are ordered by the harmonic average frequency across every installed frequency dictionary, using the exact same value shown in the "Average" frequency display. Closes yomidevs#1957 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1957.
Yomitan can already display a per-entry harmonic average frequency across all installed frequency dictionaries, but the "Frequency sorting dictionary" setting could only sort by a single dictionary. This meant results could be ordered in a way that contradicts the average shown in the popup (see the
陽example in the issue, where an entry present in only one dictionary outranks an entry with a lower average).This PR adds an
Average (all dictionaries)option to that setting. When selected, results are sorted by the harmonic average frequency across every installed frequency dictionary.Details
getFrequencyHarmonic(entry, headwordIndex, null)used to render the "Average" frequency row, so the sort order always agrees with the number the user sees (rank-based and occurrence-based dictionaries are blended identically to the display).general.sortFrequencyDictionarysetting using a NUL-prefixed sentinel value, so there's no schema change / options migration and no possibility of colliding with a real dictionary title.simplelookup mode the translator normally loads only the selected sort dictionary's metadata; when Average is selected it now loads all enabled frequency dictionaries (asuseAllFrequencyDictionariesalready does), since averaging requires them.Testing
test/translator-frequency-sort.test.jscovering the new harmonic ordering: cross-dictionary averaging, ascending vs descending, one-value-per-dictionary de-duplication, and the no-frequency-data fallback.npm run test:js,test:ts, existing translator golden tests (test/dictionary-data.test.js), andoptions-utiltests pass.