Improve empty reading handling (#1497)
* Handle empty readings earlier in the definition creation process * Remove empty reading check * Remove special handling of empty readings
This commit is contained in:
parent
a65742a884
commit
16217728af
@ -70,8 +70,7 @@ class DisplayGenerator {
|
|||||||
|
|
||||||
const uniqueExpressions = new Set();
|
const uniqueExpressions = new Set();
|
||||||
const uniqueReadings = new Set();
|
const uniqueReadings = new Set();
|
||||||
for (let {expression, reading} of expressions) {
|
for (const {expression, reading} of expressions) {
|
||||||
if (reading.length === 0) { reading = expression; }
|
|
||||||
uniqueExpressions.add(expression);
|
uniqueExpressions.add(expression);
|
||||||
uniqueReadings.add(reading);
|
uniqueReadings.add(reading);
|
||||||
}
|
}
|
||||||
@ -244,7 +243,7 @@ class DisplayGenerator {
|
|||||||
const expressionContainer = node.querySelector('.expression-text');
|
const expressionContainer = node.querySelector('.expression-text');
|
||||||
const tagContainer = node.querySelector('.expression-tag-list');
|
const tagContainer = node.querySelector('.expression-tag-list');
|
||||||
|
|
||||||
node.dataset.readingIsSame = `${!reading || reading === expression}`;
|
node.dataset.readingIsSame = `${reading === expression}`;
|
||||||
node.dataset.frequency = termFrequency;
|
node.dataset.frequency = termFrequency;
|
||||||
|
|
||||||
const pitchAccentCategories = this._getPitchAccentCategories(pitches);
|
const pitchAccentCategories = this._getPitchAccentCategories(pitches);
|
||||||
@ -252,7 +251,7 @@ class DisplayGenerator {
|
|||||||
node.dataset.pitchAccentCategories = pitchAccentCategories;
|
node.dataset.pitchAccentCategories = pitchAccentCategories;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._setTextContent(node.querySelector('.expression-reading'), reading.length > 0 ? reading : expression);
|
this._setTextContent(node.querySelector('.expression-reading'), reading);
|
||||||
|
|
||||||
this._appendFurigana(expressionContainer, furiganaSegments, this._appendKanjiLinks.bind(this));
|
this._appendFurigana(expressionContainer, furiganaSegments, this._appendKanjiLinks.bind(this));
|
||||||
this._appendMultiple(tagContainer, this._createTag.bind(this), termTags);
|
this._appendMultiple(tagContainer, this._createTag.bind(this), termTags);
|
||||||
|
@ -96,8 +96,7 @@ class DictionaryDataUtil {
|
|||||||
const allExpressions = new Set();
|
const allExpressions = new Set();
|
||||||
const allReadings = new Set();
|
const allReadings = new Set();
|
||||||
|
|
||||||
for (let {expression, reading, pitches: expressionPitches} of definition.expressions) {
|
for (const {expression, reading, pitches: expressionPitches} of definition.expressions) {
|
||||||
if (reading.length === 0) { reading = expression; }
|
|
||||||
allExpressions.add(expression);
|
allExpressions.add(expression);
|
||||||
allReadings.add(reading);
|
allReadings.add(reading);
|
||||||
|
|
||||||
|
@ -430,7 +430,7 @@ const JapaneseUtil = (() => {
|
|||||||
// Furigana distribution
|
// Furigana distribution
|
||||||
|
|
||||||
distributeFurigana(expression, reading) {
|
distributeFurigana(expression, reading) {
|
||||||
if (!reading || reading === expression) {
|
if (reading === expression) {
|
||||||
// Same
|
// Same
|
||||||
return [this._createFuriganaSegment(expression, '')];
|
return [this._createFuriganaSegment(expression, '')];
|
||||||
}
|
}
|
||||||
|
@ -648,8 +648,7 @@ class Translator {
|
|||||||
|
|
||||||
for (const {expressions, frequencies: frequencies1, pitches: pitches1} of allDefinitions) {
|
for (const {expressions, frequencies: frequencies1, pitches: pitches1} of allDefinitions) {
|
||||||
for (let i = 0, ii = expressions.length; i < ii; ++i) {
|
for (let i = 0, ii = expressions.length; i < ii; ++i) {
|
||||||
let {expression, reading, frequencies: frequencies2, pitches: pitches2} = expressions[i];
|
const {expression, reading, frequencies: frequencies2, pitches: pitches2} = expressions[i];
|
||||||
if (reading.length === 0) { reading = expression; }
|
|
||||||
let readingMap = expressionMap.get(expression);
|
let readingMap = expressionMap.get(expression);
|
||||||
if (typeof readingMap === 'undefined') {
|
if (typeof readingMap === 'undefined') {
|
||||||
readingMap = new Map();
|
readingMap = new Map();
|
||||||
@ -1079,7 +1078,8 @@ class Translator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _createTermDefinitionFromDatabaseDefinition(databaseDefinition, source, rawSource, sourceTerm, reasons, isPrimary, enabledDictionaryMap) {
|
async _createTermDefinitionFromDatabaseDefinition(databaseDefinition, source, rawSource, sourceTerm, reasons, isPrimary, enabledDictionaryMap) {
|
||||||
const {expression, reading, definitionTags, termTags, glossary, score, dictionary, id, sequence} = databaseDefinition;
|
const {expression, reading: rawReading, definitionTags, termTags, glossary, score, dictionary, id, sequence} = databaseDefinition;
|
||||||
|
const reading = (rawReading.length > 0 ? rawReading : expression);
|
||||||
const dictionaryOrder = this._getDictionaryOrder(dictionary, enabledDictionaryMap);
|
const dictionaryOrder = this._getDictionaryOrder(dictionary, enabledDictionaryMap);
|
||||||
const termTagsExpanded = await this._expandTags(termTags, dictionary);
|
const termTagsExpanded = await this._expandTags(termTags, dictionary);
|
||||||
const definitionTagsExpanded = await this._expandTags(definitionTags, dictionary);
|
const definitionTagsExpanded = await this._expandTags(definitionTags, dictionary);
|
||||||
|
@ -131,7 +131,7 @@ class AudioDownloader {
|
|||||||
if (htmlReadings.length === 0) { continue; }
|
if (htmlReadings.length === 0) { continue; }
|
||||||
|
|
||||||
const htmlReading = dom.getTextContent(htmlReadings[0]);
|
const htmlReading = dom.getTextContent(htmlReadings[0]);
|
||||||
if (htmlReading && (!reading || reading === htmlReading)) {
|
if (htmlReading && (reading === expression || reading === htmlReading)) {
|
||||||
url = this._normalizeUrl(url, response.url);
|
url = this._normalizeUrl(url, response.url);
|
||||||
return [{type: 'url', url}];
|
return [{type: 'url', url}];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user