UNPKG

2.31 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.init = exports.AdjectiveOptimizer = void 0;
4const mod_1 = require("../mod");
5const COLORS_1 = require("../mod/COLORS");
6/**
7 * 把一些错认为名词的词标注为形容词,或者对名词作定语的情况
8 */
9class AdjectiveOptimizer extends mod_1.SubSModuleOptimizer {
10 constructor() {
11 super(...arguments);
12 this.name = 'AdjectiveOptimizer';
13 }
14 doOptimize(words) {
15 const POSTAG = this._POSTAG;
16 let index = 0;
17 while (index < words.length) {
18 const word = words[index];
19 const nextword = words[index + 1];
20 if (nextword) {
21 // 对于<颜色>+<的>,直接判断颜色是形容词(字典里颜色都是名词)
22 if (nextword.p & POSTAG.D_U && COLORS_1.COLOR_ALL[word.w]) {
23 word.op = word.op || word.p;
24 word.p |= POSTAG.D_A;
25 this.debugToken(word, {
26 [this.name]: true,
27 });
28 }
29 // 如果是连续的两个名词,前一个是颜色,那这个颜色也是形容词
30 if (word.p & POSTAG.D_N && this.isNominal(nextword.p) && COLORS_1.COLOR_ALL[word.w]) {
31 word.op = word.op || word.p;
32 word.p |= POSTAG.D_A;
33 word.p |= POSTAG.D_N;
34 this.debugToken(word, {
35 [this.name]: true,
36 });
37 }
38 }
39 // 移到下一个单词
40 index += 1;
41 }
42 return words;
43 }
44 isNominal(pos) {
45 /*
46 if (Array.isArray(pos))
47 {
48 return this.isNominal(pos[0]);
49 }
50 */
51 const POSTAG = this._POSTAG;
52 return (pos === POSTAG.D_N ||
53 pos === POSTAG.A_NT ||
54 pos === POSTAG.A_NX ||
55 pos === POSTAG.A_NZ ||
56 pos === POSTAG.A_NR ||
57 pos === POSTAG.A_NS ||
58 pos === POSTAG.URL);
59 }
60}
61exports.AdjectiveOptimizer = AdjectiveOptimizer;
62exports.init = AdjectiveOptimizer.init.bind(AdjectiveOptimizer);
63exports.default = AdjectiveOptimizer;
64//# sourceMappingURL=AdjectiveOptimizer.js.map
\No newline at end of file