Skip to content

Commit

Permalink
Set up getFrequencyOrder for other languages
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuuuube committed Nov 26, 2024
1 parent 49be0db commit 14a8a83
Showing 1 changed file with 31 additions and 5 deletions.
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

0 comments on commit 14a8a83

Please sign in to comment.