1 | 'use strict';
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.doOptimize = exports.init = exports.segment = exports.type = void 0;
|
4 | const const_1 = require("../mod/const");
|
5 |
|
6 | exports.type = 'optimizer';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | function init(_segment) {
|
13 | exports.segment = _segment;
|
14 | }
|
15 | exports.init = init;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | function doOptimize(words, is_not_first) {
|
24 | if (typeof is_not_first == 'undefined') {
|
25 | is_not_first = false;
|
26 | }
|
27 |
|
28 | const TABLE = exports.segment.getDict('TABLE');
|
29 | const POSTAG = exports.segment.POSTAG;
|
30 | let i = 0;
|
31 | let ie = words.length - 1;
|
32 | while (i < ie) {
|
33 | let w1 = words[i];
|
34 | let w2 = words[i + 1];
|
35 |
|
36 | if ((w1.p & POSTAG.A_M) > 0) {
|
37 |
|
38 |
|
39 | if (w2.w in const_1.DATETIME) {
|
40 | let nw = w1.w + w2.w;
|
41 | let len = 2;
|
42 | let ma = [w1, w2];
|
43 |
|
44 | while (true) {
|
45 | let w11 = words[i + len];
|
46 | let w22 = words[i + len + 1];
|
47 | if (w11 && w22 && (w11.p & POSTAG.A_M) > 0 && w22.w in const_1.DATETIME) {
|
48 | len += 2;
|
49 | nw += w11.w + w22.w;
|
50 | ma.push(w11);
|
51 | ma.push(w22);
|
52 | }
|
53 | else {
|
54 | break;
|
55 | }
|
56 | }
|
57 | words.splice(i, len, {
|
58 | w: nw,
|
59 | p: POSTAG.D_T,
|
60 | m: ma,
|
61 | });
|
62 | ie -= len - 1;
|
63 | continue;
|
64 | }
|
65 |
|
66 | }
|
67 |
|
68 | i++;
|
69 | }
|
70 | return words;
|
71 | }
|
72 | exports.doOptimize = doOptimize;
|
73 |
|
\ | No newline at end of file |