Merge pull request #450 from toasted-nutbread/frequency-readings
Add support for filtering frequency metadata based on readings
This commit is contained in:
commit
9297eb45ae
@ -26,8 +26,30 @@
|
|||||||
{},
|
{},
|
||||||
{"enum": ["freq"]},
|
{"enum": ["freq"]},
|
||||||
{
|
{
|
||||||
"type": ["string", "number"],
|
"oneOf": [
|
||||||
"description": "Frequency information for the term or expression."
|
{
|
||||||
|
"type": ["string", "number"],
|
||||||
|
"description": "Frequency information for the term or expression."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": ["object"],
|
||||||
|
"required": [
|
||||||
|
"reading",
|
||||||
|
"frequency"
|
||||||
|
],
|
||||||
|
"additionalProperties": false,
|
||||||
|
"properties": {
|
||||||
|
"reading": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Reading for the term or expression."
|
||||||
|
},
|
||||||
|
"frequency": {
|
||||||
|
"type": ["string", "number"],
|
||||||
|
"description": "Frequency information for the term or expression."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -482,7 +482,9 @@ class Translator {
|
|||||||
switch (mode) {
|
switch (mode) {
|
||||||
case 'freq':
|
case 'freq':
|
||||||
for (const term of termsUnique[index]) {
|
for (const term of termsUnique[index]) {
|
||||||
term.frequencies.push({expression, frequency: data, dictionary});
|
const frequencyData = this.getFrequencyData(expression, data, dictionary, term);
|
||||||
|
if (frequencyData === null) { continue; }
|
||||||
|
term.frequencies.push(frequencyData);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'pitch':
|
case 'pitch':
|
||||||
@ -575,6 +577,18 @@ class Translator {
|
|||||||
return tagMetaList;
|
return tagMetaList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFrequencyData(expression, data, dictionary, term) {
|
||||||
|
if (data !== null && typeof data === 'object') {
|
||||||
|
const {frequency, reading} = data;
|
||||||
|
|
||||||
|
const termReading = term.reading || expression;
|
||||||
|
if (reading !== termReading) { return null; }
|
||||||
|
|
||||||
|
return {expression, frequency, dictionary};
|
||||||
|
}
|
||||||
|
return {expression, frequency: data, dictionary};
|
||||||
|
}
|
||||||
|
|
||||||
async getPitchData(expression, data, dictionary, term) {
|
async getPitchData(expression, data, dictionary, term) {
|
||||||
const reading = data.reading;
|
const reading = data.reading;
|
||||||
const termReading = term.reading || expression;
|
const termReading = term.reading || expression;
|
||||||
|
@ -2,6 +2,12 @@
|
|||||||
["打", "freq", 1],
|
["打", "freq", 1],
|
||||||
["打つ", "freq", 2],
|
["打つ", "freq", 2],
|
||||||
["打ち込む", "freq", 3],
|
["打ち込む", "freq", 3],
|
||||||
|
["打", "freq", {"reading": "だ", "frequency": 4}],
|
||||||
|
["打", "freq", {"reading": "ダース", "frequency": 5}],
|
||||||
|
["打つ", "freq", {"reading": "うつ", "frequency": 6}],
|
||||||
|
["打つ", "freq", {"reading": "ぶつ", "frequency": 7}],
|
||||||
|
["打ち込む", "freq", {"reading": "うちこむ", "frequency": 8}],
|
||||||
|
["打ち込む", "freq", {"reading": "ぶちこむ", "frequency": 9}],
|
||||||
[
|
[
|
||||||
"打ち込む",
|
"打ち込む",
|
||||||
"pitch",
|
"pitch",
|
||||||
|
@ -235,8 +235,8 @@ async function testDatabase1() {
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
vm.assert.deepStrictEqual(counts, {
|
vm.assert.deepStrictEqual(counts, {
|
||||||
counts: [{kanji: 2, kanjiMeta: 2, terms: 32, termMeta: 6, tagMeta: 14}],
|
counts: [{kanji: 2, kanjiMeta: 2, terms: 32, termMeta: 12, tagMeta: 14}],
|
||||||
total: {kanji: 2, kanjiMeta: 2, terms: 32, termMeta: 6, tagMeta: 14}
|
total: {kanji: 2, kanjiMeta: 2, terms: 32, termMeta: 12, tagMeta: 14}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Test find* functions
|
// Test find* functions
|
||||||
@ -626,9 +626,9 @@ async function testFindTermMetaBulk1(database, titles) {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
expectedResults: {
|
expectedResults: {
|
||||||
total: 1,
|
total: 3,
|
||||||
modes: [
|
modes: [
|
||||||
['freq', 1]
|
['freq', 3]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -639,9 +639,9 @@ async function testFindTermMetaBulk1(database, titles) {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
expectedResults: {
|
expectedResults: {
|
||||||
total: 1,
|
total: 3,
|
||||||
modes: [
|
modes: [
|
||||||
['freq', 1]
|
['freq', 3]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -652,9 +652,9 @@ async function testFindTermMetaBulk1(database, titles) {
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
expectedResults: {
|
expectedResults: {
|
||||||
total: 3,
|
total: 5,
|
||||||
modes: [
|
modes: [
|
||||||
['freq', 1],
|
['freq', 3],
|
||||||
['pitch', 2]
|
['pitch', 2]
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user