Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up getFrequencyOrder for other languages #1616

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions ext/js/pages/settings/sort-frequency-dictionary-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,35 @@ export class SortFrequencyDictionaryController {
* @returns {Promise<number>}
*/
async _getFrequencyOrder(dictionary) {
const moreCommonTerms = ['来る', '言う', '出る', '入る', '方', '男', '女', '今', '何', '時'];
const lessCommonTerms = ['行なう', '論じる', '過す', '行方', '人口', '猫', '犬', '滝', '理', '暁'];
const terms = [...moreCommonTerms, ...lessCommonTerms];
const dictionaryInfo = await this._settingsController.application.api.getDictionaryInfo();
const dictionaryLang = dictionaryInfo.find(({title}) => title === dictionary)?.sourceLanguage ?? '';

/** @type {Record<string, string[]>} */
const moreCommonTerms = {
ja: ['来る', '言う', '出る', '入る', '方', '男', '女', '今', '何', '時'],
};
/** @type {Record<string, string[]>} */
const lessCommonTerms = {
ja: ['行なう', '論じる', '過す', '行方', '人口', '猫', '犬', '滝', '理', '暁'],
};
let langMoreCommonTerms = moreCommonTerms[dictionaryLang];
let langLessCommonTerms = lessCommonTerms[dictionaryLang];
if (dictionaryLang === '') {
langMoreCommonTerms = [];
for (const key in moreCommonTerms) {
if (Object.hasOwn(moreCommonTerms, key)) {
langMoreCommonTerms.push(...moreCommonTerms[key]);
}
}
langLessCommonTerms = [];
for (const key in lessCommonTerms) {
if (Object.hasOwn(lessCommonTerms, key)) {
langLessCommonTerms.push(...lessCommonTerms[key]);
}
}
}

const terms = [...langMoreCommonTerms, ...langLessCommonTerms];

const frequencies = await this._settingsController.application.api.getTermFrequencies(
terms.map((term) => ({term, reading: null})),
Expand All @@ -166,12 +192,12 @@ export class SortFrequencyDictionaryController {
const termDetails = new Map();
const moreCommonTermDetails = [];
const lessCommonTermDetails = [];
for (const term of moreCommonTerms) {
for (const term of langMoreCommonTerms) {
const details = {hasValue: false, minValue: Number.MAX_SAFE_INTEGER, maxValue: Number.MIN_SAFE_INTEGER};
termDetails.set(term, details);
moreCommonTermDetails.push(details);
}
for (const term of lessCommonTerms) {
for (const term of langLessCommonTerms) {
const details = {hasValue: false, minValue: Number.MAX_SAFE_INTEGER, maxValue: Number.MIN_SAFE_INTEGER};
termDetails.set(term, details);
lessCommonTermDetails.push(details);
Expand Down