merged mode: rewrite term frequency (use score)
This commit is contained in:
parent
04def64521
commit
f54f909701
@ -318,21 +318,24 @@ function dictTagsSort(tags) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function dictJmdictTermTagsRare(tags) {
|
function dictTermTagScore(tags) {
|
||||||
const rareTags = [
|
let score = 0;
|
||||||
'ik',
|
|
||||||
'iK',
|
const tagScores = {
|
||||||
'ok',
|
'ik': -5,
|
||||||
'oK',
|
'iK': -5,
|
||||||
'io',
|
'ok': -5,
|
||||||
'oik'
|
'oK': -5,
|
||||||
];
|
'io': -5,
|
||||||
|
'oik': -5,
|
||||||
|
'P': 10
|
||||||
|
};
|
||||||
|
|
||||||
for (const tag of tags) {
|
for (const tag of tags) {
|
||||||
if (rareTags.includes(tag)) {
|
score += tagScores[tag] || 0;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
function dictFieldSplit(field) {
|
function dictFieldSplit(field) {
|
||||||
|
@ -313,7 +313,7 @@ templates['terms.html'] = template({"1":function(container,depth0,helpers,partia
|
|||||||
},"29":function(container,depth0,helpers,partials,data,blockParams,depths) {
|
},"29":function(container,depth0,helpers,partials,data,blockParams,depths) {
|
||||||
var stack1, helper, options, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", buffer =
|
var stack1, helper, options, alias1=depth0 != null ? depth0 : (container.nullContext || {}), alias2=helpers.helperMissing, alias3="function", buffer =
|
||||||
" <div class=\"expression\">\n <span class=\"expression-"
|
" <div class=\"expression\">\n <span class=\"expression-"
|
||||||
+ container.escapeExpression(((helper = (helper = helpers.jmdictTermFrequency || (depth0 != null ? depth0.jmdictTermFrequency : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"jmdictTermFrequency","hash":{},"data":data}) : helper)))
|
+ container.escapeExpression(((helper = (helper = helpers.termFrequency || (depth0 != null ? depth0.termFrequency : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"termFrequency","hash":{},"data":data}) : helper)))
|
||||||
+ "\">";
|
+ "\">";
|
||||||
stack1 = ((helper = (helper = helpers.kanjiLinks || (depth0 != null ? depth0.kanjiLinks : depth0)) != null ? helper : alias2),(options={"name":"kanjiLinks","hash":{},"fn":container.program(30, data, 0, blockParams, depths),"inverse":container.noop,"data":data}),(typeof helper === alias3 ? helper.call(alias1,options) : helper));
|
stack1 = ((helper = (helper = helpers.kanjiLinks || (depth0 != null ? depth0.kanjiLinks : depth0)) != null ? helper : alias2),(options={"name":"kanjiLinks","hash":{},"fn":container.program(30, data, 0, blockParams, depths),"inverse":container.noop,"data":data}),(typeof helper === alias3 ? helper.call(alias1,options) : helper));
|
||||||
if (!helpers.kanjiLinks) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
|
if (!helpers.kanjiLinks) { stack1 = helpers.blockHelperMissing.call(depth0,stack1,options)}
|
||||||
|
@ -113,15 +113,15 @@ class Translator {
|
|||||||
expression: expression,
|
expression: expression,
|
||||||
reading: reading,
|
reading: reading,
|
||||||
termTags: dictTagsSort(tags),
|
termTags: dictTagsSort(tags),
|
||||||
jmdictTermFrequency: (tags => {
|
termFrequency: (score => {
|
||||||
if (tags.has('P')) {
|
if (score > 0) {
|
||||||
return 'popular';
|
return 'popular';
|
||||||
} else if (dictJmdictTermTagsRare(tags)) {
|
} else if (score < 0) {
|
||||||
return 'rare';
|
return 'rare';
|
||||||
} else {
|
} else {
|
||||||
return 'normal';
|
return 'normal';
|
||||||
}
|
}
|
||||||
})(result.expressions.get(expression).get(reading))
|
})(dictTermTagScore(result.expressions.get(expression).get(reading)))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
{{#if merged}}
|
{{#if merged}}
|
||||||
{{#each expressions}}
|
{{#each expressions}}
|
||||||
<div class="expression">
|
<div class="expression">
|
||||||
<span class="expression-{{jmdictTermFrequency}}">{{#kanjiLinks}}{{#furigana}}{{{.}}}{{/furigana}}{{/kanjiLinks}}</span><!--
|
<span class="expression-{{termFrequency}}">{{#kanjiLinks}}{{#furigana}}{{{.}}}{{/furigana}}{{/kanjiLinks}}</span><!--
|
||||||
--><div class="peek-wrapper">
|
--><div class="peek-wrapper">
|
||||||
{{~#if ../playback~}}
|
{{~#if ../playback~}}
|
||||||
<a href="#" class="action-play-audio"><img src="/mixed/img/play-audio.png" title="Play audio" alt></a>
|
<a href="#" class="action-play-audio"><img src="/mixed/img/play-audio.png" title="Play audio" alt></a>
|
||||||
|
Loading…
Reference in New Issue
Block a user