|
|
/**
|
|
|
* Align classify with 附件下载_邮件识别 gold:
|
|
|
* - 新增预报 / 请查收新增预<E5A29E>?on subject+body
|
|
|
* - 数据模版 / packing-list xlsx -> NEW_CONTAINER score
|
|
|
*/
|
|
|
import fs from "fs";
|
|
|
|
|
|
const path = "src/services/parse/classify.ts";
|
|
|
let src = fs.readFileSync(path, "utf8");
|
|
|
const nl = src.includes("\r\n") ? "\r\n" : "\n";
|
|
|
|
|
|
const oldForecast = ` if (/\\u65b0\\u589e\\u9884\\u62a5/.test(subject)) {
|
|
|
signals.push({
|
|
|
signal: "\\u65b0\\u589e\\u9884\\u62a5",
|
|
|
score: 50,
|
|
|
matched: "\\u65b0\\u589e\\u9884\\u62a5",
|
|
|
source: "subject",
|
|
|
});
|
|
|
scores.NEW_CONTAINER += 50;
|
|
|
}`;
|
|
|
|
|
|
// Match actual Chinese in file
|
|
|
const oldForecastRe =
|
|
|
/ if \(\/新增预报\/\.test\(subject\)\) \{\r?\n signals\.push\(\{\r?\n signal: "新增预报",\r?\n score: 50,\r?\n matched: "新增预报",\r?\n source: "subject",\r?\n \}\);\r?\n scores\.NEW_CONTAINER \+= 50;\r?\n \}/;
|
|
|
|
|
|
const newForecast = ` if (/新增预报|请查收新增预<E5A29E>?.test(text)) {
|
|
|
signals.push({
|
|
|
signal: "新增预报",
|
|
|
score: 50,
|
|
|
matched: "新增预报",
|
|
|
source: /新增预报|请查收新增预<E5A29E>?.test(subject) ? "subject" : "body",
|
|
|
});
|
|
|
scores.NEW_CONTAINER += 50;
|
|
|
}
|
|
|
|
|
|
// 金样:数据模<E68DAE>?/ 卡派清单<E6B885>?xlsx <20>?预报<E9A284>?
|
|
|
const forecastPacking = filenames.some(
|
|
|
(f) =>
|
|
|
/数据模版/i.test(f) ||
|
|
|
(/卡派|装箱|packing|货件清单|预报资料/i.test(f) &&
|
|
|
/\\.(xlsx|xls|csv)$/i.test(f)),
|
|
|
);
|
|
|
if (forecastPacking && scores.NEW_CONTAINER < 40) {
|
|
|
signals.push({
|
|
|
signal: "预报清单附件",
|
|
|
score: 45,
|
|
|
matched: filenames.find((f) => /数据模版|卡派|装箱|packing/i.test(f)) || "xlsx",
|
|
|
source: "attachment",
|
|
|
});
|
|
|
scores.NEW_CONTAINER += 45;
|
|
|
} else if (forecastPacking) {
|
|
|
scores.NEW_CONTAINER += 15;
|
|
|
signals.push({
|
|
|
signal: "预报清单附件",
|
|
|
score: 15,
|
|
|
matched: "xlsx",
|
|
|
source: "attachment",
|
|
|
});
|
|
|
}`;
|
|
|
|
|
|
if (!oldForecastRe.test(src)) {
|
|
|
const i = src.indexOf("新增预报");
|
|
|
console.log("near", JSON.stringify(src.slice(i - 30, i + 200)));
|
|
|
throw new Error("forecast block not found");
|
|
|
}
|
|
|
|
|
|
src = src.replace(oldForecastRe, newForecast);
|
|
|
|
|
|
// Also treat 数据模版 as packing boost lead (hasPacking already 卡派资料 only)
|
|
|
const oldHasPacking = ` const hasPacking = /卡派资料/.test(fileText);`;
|
|
|
const newHasPacking = ` const hasPacking = /卡派资料|数据模版/.test(fileText);`;
|
|
|
if (!src.includes(oldHasPacking)) throw new Error("hasPacking missing");
|
|
|
src = src.replace(oldHasPacking, newHasPacking);
|
|
|
|
|
|
fs.writeFileSync(path, src);
|
|
|
console.log("classify patched");
|