aboutsummaryrefslogtreecommitdiff
path: root/ext/js/language
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/language')
-rw-r--r--ext/js/language/dictionary-data-util.js8
-rw-r--r--ext/js/language/dictionary-database.js8
-rw-r--r--ext/js/language/japanese-util.js26
-rw-r--r--ext/js/language/text-scanner.js34
-rw-r--r--ext/js/language/translator.js23
5 files changed, 50 insertions, 49 deletions
diff --git a/ext/js/language/dictionary-data-util.js b/ext/js/language/dictionary-data-util.js
index 3f096b02..0a3be234 100644
--- a/ext/js/language/dictionary-data-util.js
+++ b/ext/js/language/dictionary-data-util.js
@@ -93,10 +93,10 @@ class DictionaryDataUtil {
static getPitchAccentInfos(dictionaryEntry) {
const {headwords, pronunciations} = dictionaryEntry;
- const allExpressions = new Set();
+ const allTerms = new Set();
const allReadings = new Set();
for (const {term, reading} of headwords) {
- allExpressions.add(term);
+ allTerms.add(term);
allReadings.add(reading);
}
@@ -129,8 +129,8 @@ class DictionaryDataUtil {
for (const dictionaryPitchAccentInfoList of pitchAccentInfoMap.values()) {
for (const pitchAccentInfo of dictionaryPitchAccentInfoList) {
const {terms, reading, exclusiveTerms, exclusiveReadings} = pitchAccentInfo;
- if (!this._areSetsEqual(terms, allExpressions)) {
- exclusiveTerms.push(...this._getSetIntersection(terms, allExpressions));
+ if (!this._areSetsEqual(terms, allTerms)) {
+ exclusiveTerms.push(...this._getSetIntersection(terms, allTerms));
}
if (multipleReadings) {
exclusiveReadings.push(reading);
diff --git a/ext/js/language/dictionary-database.js b/ext/js/language/dictionary-database.js
index fc4336c5..98f56986 100644
--- a/ext/js/language/dictionary-database.js
+++ b/ext/js/language/dictionary-database.js
@@ -26,7 +26,7 @@ class DictionaryDatabase {
this._schemas = new Map();
this._createOnlyQuery1 = (item) => IDBKeyRange.only(item);
this._createOnlyQuery2 = (item) => IDBKeyRange.only(item.query);
- this._createOnlyQuery3 = (item) => IDBKeyRange.only(item.expression);
+ this._createOnlyQuery3 = (item) => IDBKeyRange.only(item.term);
this._createOnlyQuery4 = (item) => IDBKeyRange.only(item.path);
this._createBoundQuery1 = (item) => IDBKeyRange.bound(item, `${item}\uffff`, false, false);
this._createBoundQuery2 = (item) => { item = stringReverse(item); return IDBKeyRange.bound(item, `${item}\uffff`, false, false); };
@@ -387,7 +387,7 @@ class DictionaryDatabase {
_createTerm(row, index) {
return {
index,
- expression: row.expression,
+ term: row.expression,
reading: row.reading,
definitionTags: this._splitField(row.definitionTags || row.tags || ''),
termTags: this._splitField(row.termTags || ''),
@@ -413,8 +413,8 @@ class DictionaryDatabase {
};
}
- _createTermMeta({expression, mode, data, dictionary}, index) {
- return {expression, mode, data, dictionary, index};
+ _createTermMeta({expression: term, mode, data, dictionary}, index) {
+ return {term, mode, data, dictionary, index};
}
_createKanjiMeta({character, mode, data, dictionary}, index) {
diff --git a/ext/js/language/japanese-util.js b/ext/js/language/japanese-util.js
index cade393b..4d5e8092 100644
--- a/ext/js/language/japanese-util.js
+++ b/ext/js/language/japanese-util.js
@@ -315,7 +315,7 @@ const JapaneseUtil = (() => {
return wanakana.toRomaji(text);
}
- convertReading(expression, reading, readingMode) {
+ convertReading(term, reading, readingMode) {
switch (readingMode) {
case 'hiragana':
return this.convertKatakanaToHiragana(reading);
@@ -325,8 +325,8 @@ const JapaneseUtil = (() => {
if (reading) {
return this.convertToRomaji(reading);
} else {
- if (this.isStringEntirelyKana(expression)) {
- return this.convertToRomaji(expression);
+ if (this.isStringEntirelyKana(term)) {
+ return this.convertToRomaji(term);
}
}
return reading;
@@ -429,16 +429,16 @@ const JapaneseUtil = (() => {
// Furigana distribution
- distributeFurigana(expression, reading) {
- if (reading === expression) {
+ distributeFurigana(term, reading) {
+ if (reading === term) {
// Same
- return [this._createFuriganaSegment(expression, '')];
+ return [this._createFuriganaSegment(term, '')];
}
const groups = [];
let groupPre = null;
let isKanaPre = null;
- for (const c of expression) {
+ for (const c of term) {
const codePoint = c.codePointAt(0);
const isKana = !(this.isCodePointKanji(codePoint) || codePoint === ITERATION_MARK_CODE_POINT);
if (isKana === isKanaPre) {
@@ -462,18 +462,18 @@ const JapaneseUtil = (() => {
}
// Fallback
- return [this._createFuriganaSegment(expression, reading)];
+ return [this._createFuriganaSegment(term, reading)];
}
- distributeFuriganaInflected(expression, reading, source) {
- const expressionNormalized = this.convertKatakanaToHiragana(expression);
+ distributeFuriganaInflected(term, reading, source) {
+ const termNormalized = this.convertKatakanaToHiragana(term);
const readingNormalized = this.convertKatakanaToHiragana(reading);
const sourceNormalized = this.convertKatakanaToHiragana(source);
- let mainText = expression;
- let stemLength = this._getStemLength(expressionNormalized, sourceNormalized);
+ let mainText = term;
+ let stemLength = this._getStemLength(termNormalized, sourceNormalized);
- // Check if source is derived from the reading instead of the expression
+ // Check if source is derived from the reading instead of the term
const readingStemLength = this._getStemLength(readingNormalized, sourceNormalized);
if (readingStemLength > 0 && readingStemLength >= stemLength) {
mainText = reading;
diff --git a/ext/js/language/text-scanner.js b/ext/js/language/text-scanner.js
index 4dbd782b..b571435b 100644
--- a/ext/js/language/text-scanner.js
+++ b/ext/js/language/text-scanner.js
@@ -304,7 +304,7 @@ class TextScanner extends EventDispatcher {
}
async _search(textSource, searchTerms, searchKanji, inputInfo) {
- let definitions = null;
+ let dictionaryEntries = null;
let sentence = null;
let type = null;
let error = null;
@@ -322,13 +322,13 @@ class TextScanner extends EventDispatcher {
searched = true;
- const result = await this._findDefinitions(textSource, searchTerms, searchKanji, optionsContext);
+ const result = await this._findDictionaryEntries(textSource, searchTerms, searchKanji, optionsContext);
if (result !== null) {
- ({definitions, sentence, type} = result);
+ ({dictionaryEntries, sentence, type} = result);
this._inputInfoCurrent = inputInfo;
this.setCurrentTextSource(textSource);
} else if (textSource instanceof TextSourceElement && await this._hasJapanese(textSource.fullContent)) {
- definitions = [];
+ dictionaryEntries = [];
sentence = {sentence: '', offset: 0};
type = 'terms';
this._inputInfoCurrent = inputInfo;
@@ -343,7 +343,7 @@ class TextScanner extends EventDispatcher {
const results = {
textScanner: this,
type,
- definitions,
+ dictionaryEntries,
sentence,
inputInfo,
textSource,
@@ -804,22 +804,22 @@ class TextScanner extends EventDispatcher {
return null;
}
- async _findDefinitions(textSource, searchTerms, searchKanji, optionsContext) {
+ async _findDictionaryEntries(textSource, searchTerms, searchKanji, optionsContext) {
if (textSource === null) {
return null;
}
if (searchTerms) {
- const results = await this._findTerms(textSource, optionsContext);
+ const results = await this._findTermDictionaryEntries(textSource, optionsContext);
if (results !== null) { return results; }
}
if (searchKanji) {
- const results = await this._findKanji(textSource, optionsContext);
+ const results = await this._findKanjiDictionaryEntries(textSource, optionsContext);
if (results !== null) { return results; }
}
return null;
}
- async _findTerms(textSource, optionsContext) {
+ async _findTermDictionaryEntries(textSource, optionsContext) {
const scanLength = this._scanLength;
const sentenceScanExtent = this._sentenceScanExtent;
const sentenceTerminatorMap = this._sentenceTerminatorMap;
@@ -829,10 +829,10 @@ class TextScanner extends EventDispatcher {
const searchText = this.getTextSourceContent(textSource, scanLength, layoutAwareScan);
if (searchText.length === 0) { return null; }
- const {definitions, length} = await yomichan.api.termsFind(searchText, {}, optionsContext);
- if (definitions.length === 0) { return null; }
+ const {dictionaryEntries, originalTextLength} = await yomichan.api.termsFind(searchText, {}, optionsContext);
+ if (dictionaryEntries.length === 0) { return null; }
- textSource.setEndOffset(length, layoutAwareScan);
+ textSource.setEndOffset(originalTextLength, layoutAwareScan);
const sentence = this._documentUtil.extractSentence(
textSource,
layoutAwareScan,
@@ -842,10 +842,10 @@ class TextScanner extends EventDispatcher {
sentenceBackwardQuoteMap
);
- return {definitions, sentence, type: 'terms'};
+ return {dictionaryEntries, sentence, type: 'terms'};
}
- async _findKanji(textSource, optionsContext) {
+ async _findKanjiDictionaryEntries(textSource, optionsContext) {
const sentenceScanExtent = this._sentenceScanExtent;
const sentenceTerminatorMap = this._sentenceTerminatorMap;
const sentenceForwardQuoteMap = this._sentenceForwardQuoteMap;
@@ -854,8 +854,8 @@ class TextScanner extends EventDispatcher {
const searchText = this.getTextSourceContent(textSource, 1, layoutAwareScan);
if (searchText.length === 0) { return null; }
- const definitions = await yomichan.api.kanjiFind(searchText, optionsContext);
- if (definitions.length === 0) { return null; }
+ const dictionaryEntries = await yomichan.api.kanjiFind(searchText, optionsContext);
+ if (dictionaryEntries.length === 0) { return null; }
textSource.setEndOffset(1, layoutAwareScan);
const sentence = this._documentUtil.extractSentence(
@@ -867,7 +867,7 @@ class TextScanner extends EventDispatcher {
sentenceBackwardQuoteMap
);
- return {definitions, sentence, type: 'kanji'};
+ return {dictionaryEntries, sentence, type: 'kanji'};
}
async _searchAt(x, y, inputInfo) {
diff --git a/ext/js/language/translator.js b/ext/js/language/translator.js
index e066d62e..68a55cf9 100644
--- a/ext/js/language/translator.js
+++ b/ext/js/language/translator.js
@@ -27,6 +27,7 @@
class Translator {
/**
* Creates a new Translator instance.
+ * @param japaneseUtil An instance of JapaneseUtil.
* @param database An instance of DictionaryDatabase.
*/
constructor({japaneseUtil, database}) {
@@ -396,8 +397,8 @@ class Translator {
const {id} = databaseEntry;
if (ids.has(id)) { continue; }
- const sourceText = databaseEntry.expression;
- const dictionaryEntry = this._createTermDictionaryEntryFromDatabaseEntry(databaseEntry, sourceText, sourceText, sourceText, [], false, enabledDictionaryMap);
+ const {term} = databaseEntry;
+ const dictionaryEntry = this._createTermDictionaryEntryFromDatabaseEntry(databaseEntry, term, term, term, [], false, enabledDictionaryMap);
dictionaryEntries.push(dictionaryEntry);
ids.add(id);
ungroupedDictionaryEntriesMap.delete(id);
@@ -426,13 +427,13 @@ class Translator {
target.groups.push(group);
if (!dictionaryEntry.isPrimary && !target.searchSecondary) {
target.searchSecondary = true;
- termList.push({expression: term, reading});
+ termList.push({term, reading});
targetList.push(target);
}
}
}
- // Group unsequenced dictionary entries with sequenced entries that have a matching [expression, reading].
+ // Group unsequenced dictionary entries with sequenced entries that have a matching [term, reading].
for (const [id, dictionaryEntry] of ungroupedDictionaryEntriesMap.entries()) {
const {term, reading} = dictionaryEntry.headwords[0];
const key = this._createMapKey([term, reading]);
@@ -457,7 +458,7 @@ class Translator {
for (const databaseEntry of databaseEntries) {
const {index, id} = databaseEntry;
- const sourceText = termList[index].expression;
+ const sourceText = termList[index].term;
const target = targetList[index];
for (const {ids, dictionaryEntries} of target.groups) {
if (ids.has(id)) { continue; }
@@ -959,10 +960,10 @@ class Translator {
}
_createTermDictionaryEntryFromDatabaseEntry(databaseEntry, originalText, transformedText, deinflectedText, reasons, isPrimary, enabledDictionaryMap) {
- const {expression, reading: rawReading, definitionTags, termTags, glossary, score, dictionary, id, sequence, rules} = databaseEntry;
- const reading = (rawReading.length > 0 ? rawReading : expression);
+ const {term, reading: rawReading, definitionTags, termTags, glossary, score, dictionary, id, sequence, rules} = databaseEntry;
+ const reading = (rawReading.length > 0 ? rawReading : term);
const {index: dictionaryIndex, priority: dictionaryPriority} = this._getDictionaryOrder(dictionary, enabledDictionaryMap);
- const sourceTermExactMatchCount = (isPrimary && deinflectedText === expression ? 1 : 0);
+ const sourceTermExactMatchCount = (isPrimary && deinflectedText === term ? 1 : 0);
const source = this._createSource(originalText, transformedText, deinflectedText, isPrimary);
const maxTransformedTextLength = transformedText.length;
@@ -982,7 +983,7 @@ class Translator {
dictionaryPriority,
sourceTermExactMatchCount,
maxTransformedTextLength,
- [this._createTermHeadword(0, expression, reading, [source], headwordTagGroups, rules)],
+ [this._createTermHeadword(0, term, reading, [source], headwordTagGroups, rules)],
[this._createTermDefinition(0, [0], dictionary, definitionTagGroups, glossary)]
);
}
@@ -1204,7 +1205,7 @@ class Translator {
i = v2.score - v1.score;
if (i !== 0) { return i; }
- // Sort by expression text
+ // Sort by headword term text
const headwords1 = v1.headwords;
const headwords2 = v2.headwords;
for (let j = 0, jj = Math.min(headwords1.length, headwords2.length); j < jj; ++j) {
@@ -1277,7 +1278,7 @@ class Translator {
let i = v2.dictionaryPriority - v1.dictionaryPriority;
if (i !== 0) { return i; }
- // Sory by expression order
+ // Sory by headword order
i = v1.headwordIndex - v2.headwordIndex;
if (i !== 0) { return i; }