Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions autotests/dfm-search-tests/tst_chinese_nlp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ private Q_SLOTS:
void fileType_archive_allSynonyms();
void fileType_application_allSynonyms();
void fileType_design_source_allSynonyms();
void fileType_designSource_shadowsImageSubstring();

// Filetype specific+general combination tests (span leak regression)
void fileType_specificAndGeneral_pptDocument();
Expand Down Expand Up @@ -1287,10 +1288,9 @@ void tst_ChineseNLP::fileType_archive_allSynonyms()
void tst_ChineseNLP::fileType_application_allSynonyms()
{
// Requirements: 安装包, 软件, 应用, 脚本, 程序, 包
// NOTE: "包" excluded from rules to avoid false positives with "表情包", "压缩包"
const QStringList inputs = {
QStringLiteral("安装包"), QStringLiteral("软件"), QStringLiteral("应用"),
QStringLiteral("脚本"), QStringLiteral("程序")
QStringLiteral("脚本"), QStringLiteral("程序"), QStringLiteral("包")
};
for (const QString &input : inputs) {
ParsedIntent intent;
Expand Down Expand Up @@ -1320,6 +1320,28 @@ void tst_ChineseNLP::fileType_design_source_allSynonyms()
}
}

void tst_ChineseNLP::fileType_designSource_shadowsImageSubstring()
{
ParsedIntent intent;
m_parser->parse(QStringLiteral("昨天创建的矢量图"), intent);

QVERIFY2(setEquals(intent.fileExtensions(), expectedExtsForRule("filetype_design_source")),
qPrintable(QStringLiteral("Extensions: ") + intent.fileExtensions().join(',')));

bool hasDesignSource = false;
bool hasImage = false;
for (const MatchSpan &span : intent.consumedSpans()) {
if (span.ruleId() == QLatin1String("filetype_design_source")) {
hasDesignSource = true;
} else if (span.ruleId() == QLatin1String("filetype_image")) {
hasImage = true;
}
}

QVERIFY(hasDesignSource);
QVERIFY(!hasImage);
}

// ===== Filetype specific+general combination tests (span leak regression) =====
// 当 specific filetype 规则与 general filetype 规则同时命中时,general 规则匹配的
// 文本(文档/表格/幻灯片)必须被消费,不得泄漏成 keyword;且 fileExtensions 应只
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ void FileTypeExtractor::extract(const QString &input, ParsedIntent &intent)
continue;
}

// Always consume the matched span so the matched text doesn't leak into keywords
MatchSpan span;
span.setStart(m.capturedStart());
span.setEnd(m.capturedEnd());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
},
{
"id": "filetype_application",
"pattern": "安装包|软件|应用|脚本|程序|包",
"pattern": "安装包|软件|应用|脚本|程序|包(?!含)",
"description": "Application packages",
"enabled": true,
"priority": 150,
Expand All @@ -143,7 +143,7 @@
"pattern": "源文件|设计稿|矢量图|工程文件|psd|fig|sketch",
"description": "Design source files",
"enabled": true,
"priority": 150,
"priority": 160,
"metadata": {
"extensions": ["psd", "ai", "fig", "sketch"]
}
Expand Down
Loading