@customize-agent/knowledge 4.2.0 → 4.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -46,6 +46,8 @@ export interface TextCleanStats {
|
|
|
46
46
|
cadAttributeLines: number;
|
|
47
47
|
/** 图纸:CAD 图元属性枚举行数(管道符表格形态的实体罗列,K3) */
|
|
48
48
|
cadEntityPropertyLines: number;
|
|
49
|
+
/** 招标文件:电子投标程序句行数(加密/解密/上传/撤回等操作句,行级) */
|
|
50
|
+
tenderEprocedureLines: number;
|
|
49
51
|
/** 清单:纯报价表格段行数(费汇总/暂估价/规费/税金,K3) */
|
|
50
52
|
billPricingLines: number;
|
|
51
53
|
/** 清单:扉页签章段行数(K3) */
|
|
@@ -3,7 +3,8 @@ function zeroStats() {
|
|
|
3
3
|
headerFooterLines: 0, pageNumberLines: 0, tocRegionLines: 0, blankLines: 0,
|
|
4
4
|
tenderFormatLines: 0, tenderGenericLines: 0, clarificationLines: 0, cadNoiseLines: 0,
|
|
5
5
|
contractGeneralClauseLines: 0, announcementProcedureLines: 0, businessReviewLines: 0,
|
|
6
|
-
cadTitleBlockLines: 0, cadAttributeLines: 0, cadEntityPropertyLines: 0,
|
|
6
|
+
cadTitleBlockLines: 0, cadAttributeLines: 0, cadEntityPropertyLines: 0,
|
|
7
|
+
tenderEprocedureLines: 0, billPricingLines: 0, billTitlePageLines: 0,
|
|
7
8
|
};
|
|
8
9
|
}
|
|
9
10
|
/** 文档类型判定:文件名 + 文首内容双重特征(招标文件 / 补疑答疑 / 工程量清单 / 其他) */
|
|
@@ -107,6 +108,10 @@ function collectTenderFormatBlock(lines, start) {
|
|
|
107
108
|
}
|
|
108
109
|
/** 招标文件:泛化引用行("详见投标人须知前附表"类短行,无实质项目信息;后缀短语可选) */
|
|
109
110
|
const TENDER_GENERIC_LINE_RE = /^(详见|具体见|以|按).{0,30}?(前附表|招标文件|招标公告|补疑|澄清|清单|图纸|合同文件)((的)?(要求|规定|为准|执行))?[。;;]?$|^投标人应(仔细|认真)(阅读|核对)(招标文件|本项目)(的全部内容)?[。;;]?$|^未(按|依照|按照)(上述|本|招标文件)要求/u;
|
|
111
|
+
/** 招标文件:电子投标程序句(行级)。投标人须知条目式排版无可靠段落边界,按句删除
|
|
112
|
+
* 程序性操作(加密/解密/上传/撤回/签号/病毒防范);双重信号(程序动词 + 程序对象)
|
|
113
|
+
* 防止误删技术条款。仅招标文件生效。 */
|
|
114
|
+
const TENDER_EPROCEDURE_LINE_RE = /(?:电子交易系统|数字证书|加密|解密|撤回操作|上传投标文件|签号|病毒防范).{0,30}(?:上传|递交|撤回|解密|完成|显示|关闭|发放|防范)|(?:投标截止时间).{0,25}(?:上传|递交|撤回|自动关闭)/u;
|
|
110
115
|
/** 补疑文件:零信息回复行("答:按招标文件执行"类套话;含数字/单位的实质回复不删) */
|
|
111
116
|
const CLARIFICATION_BOILERPLATE_RE = /^(?:(?:答|答复|回复)[::]\s*)?(?:按|以)(招标文件|招标公告|合同文件|清单|图纸|补疑|答疑)?(约定|规定|要求|执行|为准)[。;;]?$|^(?:(?:答|答复|回复)[::]\s*)?不(作|做|予)(调整|修改|变更)[。;;]?$|^(?:(?:答|答复|回复)[::]\s*)?维持(不变|原状)[。;;]?$|^(?:(?:答|答复|回复)[::]\s*)?(本项|此项)(无|没有)(调整|修改|变化)[。;;]?$/u;
|
|
112
117
|
/** 图纸:无汉字纯坐标数字行(≥2 组相邻 "数字,数字" 坐标对即 ≥3 个连续坐标值,设计坐标不写入施组正文) */
|
|
@@ -226,6 +231,25 @@ function collectParagraphRegion(lines, start, maxLines = 60) {
|
|
|
226
231
|
}
|
|
227
232
|
return { end, body: parts.join('\n') };
|
|
228
233
|
}
|
|
234
|
+
/** CAD 文本格式控制码(AutoCAD MTEXT/DTEXT 语法):
|
|
235
|
+
* %%U/%%O 下划线/上划线格式开关(删除,后接文本保留)、%%D/%%P/%%C 度/正负/直径符号、
|
|
236
|
+
* %%% 百分号转义(「95%%%」=「95%」)。DWG/DXF 提取文本中的字段占位「%%U %%U」
|
|
237
|
+
* (如「本工程叠合板均按%%U %%U设计」)是未解析的字段表达式,逐字保留会污染
|
|
238
|
+
* 检索语义与生成引用,还原为可读文本。 */
|
|
239
|
+
const CAD_CONTROL_CODE_RE = /(%%[UuOo])|(%%[Dd])|(%%[Pp])|(%%[Cc])|(%%%)/gu;
|
|
240
|
+
function cleanCadControlCodes(line) {
|
|
241
|
+
return line.replace(CAD_CONTROL_CODE_RE, (_match, underline, degree, plusMinus, diameter) => {
|
|
242
|
+
if (underline)
|
|
243
|
+
return '';
|
|
244
|
+
if (degree)
|
|
245
|
+
return '°';
|
|
246
|
+
if (plusMinus)
|
|
247
|
+
return '±';
|
|
248
|
+
if (diameter)
|
|
249
|
+
return '∅';
|
|
250
|
+
return '%';
|
|
251
|
+
});
|
|
252
|
+
}
|
|
229
253
|
/**
|
|
230
254
|
* K2 预扫描:整篇文档一次遍历,产出「起始行 → 待删区段」映射。
|
|
231
255
|
* 三条规则均要求「标题模式 + 内容/规模证据」双重确认:
|
|
@@ -300,7 +324,11 @@ export function cleanExtractedText(input) {
|
|
|
300
324
|
return { text: input.text, removedChars: 0, removedLines: 0, stats: zeroStats() };
|
|
301
325
|
const docKind = detectDocKind(input.fileName || '', input.text.slice(0, 4000));
|
|
302
326
|
const isCad = input.category === 'cad' || input.category === 'diagram';
|
|
303
|
-
|
|
327
|
+
// CAD 控制码还原前置:确定性无损替换(%%U/%%O 格式开关删除、%%%→%),
|
|
328
|
+
// 不参与行级启发式删除与 30% 回退保护——纯图纸文件(标高/图元行占比高)常触发
|
|
329
|
+
// 回退保护使整个清洗作废,控制码还原若挂在行级规则里会随之失效
|
|
330
|
+
const sourceText = isCad ? cleanCadControlCodes(input.text) : input.text;
|
|
331
|
+
const lines = sourceText.split(/\r?\n/u);
|
|
304
332
|
const totalLines = lines.length;
|
|
305
333
|
// 全文高重复行统计(页眉/页脚/图框标题栏判定依据)
|
|
306
334
|
const lineCounts = new Map();
|
|
@@ -390,6 +418,12 @@ export function cleanExtractedText(input) {
|
|
|
390
418
|
index += 1;
|
|
391
419
|
continue;
|
|
392
420
|
}
|
|
421
|
+
// 招标文件:电子投标程序句(行级;加密/解密/上传/撤回等操作句,无时间地点证据可依)
|
|
422
|
+
if (TENDER_EPROCEDURE_LINE_RE.test(trimmed)) {
|
|
423
|
+
drop(line, s => { s.tenderEprocedureLines += 1; });
|
|
424
|
+
index += 1;
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
393
427
|
}
|
|
394
428
|
// 6. 补疑文件:零信息回复行(行级,长度 ≤25 且无数字/单位)
|
|
395
429
|
if (docKind === 'clarification' && trimmed.length <= 25 && CLARIFICATION_BOILERPLATE_RE.test(trimmed) && !/\d/u.test(trimmed)) {
|
|
@@ -429,13 +463,14 @@ export function cleanExtractedText(input) {
|
|
|
429
463
|
// 1) 行级启发式删除导致剩余不足原文 30% → 判定误伤,回退原文;
|
|
430
464
|
// 2) K2 章节级删除(标题 + 规模/内容 + 边界三重证据)置信度高,不参与 30% 判定,
|
|
431
465
|
// 否则通用条款占比高的合同文件永远洗不掉;但剩余不足原文 10% 时仍整体回退(防极端全删)
|
|
432
|
-
|
|
466
|
+
// 回退时返回 sourceText(已做 CAD 控制码还原),保证确定性还原在回退路径同样生效
|
|
467
|
+
const totalChars = sourceText.trim().length;
|
|
433
468
|
const remainingRatio = totalChars > 0 ? resultText.trim().length / totalChars : 1;
|
|
434
469
|
const lineLevelRemovedChars = removedChars - sectionRemovedChars;
|
|
435
470
|
const lineLevelSafe = lineLevelRemovedChars === 0 || remainingRatio >= 0.3;
|
|
436
471
|
const extremeSafe = remainingRatio >= 0.1;
|
|
437
472
|
if (removedChars > 0 && totalChars > 2000 && (!lineLevelSafe || !extremeSafe)) {
|
|
438
|
-
return { text:
|
|
473
|
+
return { text: sourceText, removedChars: 0, removedLines: 0, stats: zeroStats() };
|
|
439
474
|
}
|
|
440
475
|
return { text: resultText, removedChars, removedLines, stats };
|
|
441
476
|
}
|
|
@@ -957,6 +957,14 @@ export class IndexStateStore {
|
|
|
957
957
|
const terms = new Set(normalized ? [normalized] : []);
|
|
958
958
|
for (const term of normalized.split(/[\s,,。;;::、]+/u).filter(Boolean)) {
|
|
959
959
|
terms.add(term);
|
|
960
|
+
// 「C35混凝土」「GB55015规范」类字母数字与汉字连续串:按边界拆出独立 token。
|
|
961
|
+
// 整串只能作 trigram 短语匹配(要求三字组在文档中连续出现),清单特征
|
|
962
|
+
// 「强度等级:C35」与查询串「C35混凝土」永远无法短语命中,精确项「c35」被淹没,
|
|
963
|
+
// 导致「C35混凝土」检索返回大量仅命中「混凝土」的低相关文档
|
|
964
|
+
for (const part of term.split(/([\p{Script=Han}]+)/u).filter(part => part.length > 0)) {
|
|
965
|
+
if (part !== term)
|
|
966
|
+
terms.add(part);
|
|
967
|
+
}
|
|
960
968
|
for (const gram of this.chineseNgrams(term))
|
|
961
969
|
terms.add(gram);
|
|
962
970
|
}
|