From 7a829e015bc2721bf56c289ac3587f3bf2facf0b Mon Sep 17 00:00:00 2001 From: dualfroz Date: Wed, 14 Oct 2026 18:48:44 +0200 Subject: [PATCH] fix sweep unTag with an array, fixes #1009 --- src/1-one/sweep/methods/tagger/index.js | 3 ++- tests/03-three/misc/sweep-tag.test.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/1-one/sweep/methods/tagger/index.js b/src/1-one/sweep/methods/tagger/index.js index 7f79c93..22c7690 100644 --- a/src/1-one/sweep/methods/tagger/index.js +++ b/src/1-one/sweep/methods/tagger/index.js @@ -47,7 +47,8 @@ const tagger = function (list, document, world) { } } if (todo.unTag !== undefined) { - unTag(terms, todo.unTag, model.one.tagSet, reason) + const tags = Array.isArray(todo.unTag) ? todo.unTag : [todo.unTag] + tags.forEach(tag => unTag(terms, tag, model.one.tagSet, reason)) } // allow setting chunks, too if (todo.chunk) { diff --git a/tests/03-three/misc/sweep-tag.test.js b/tests/03-three/misc/sweep-tag.test.js index b8235d8..38448ad 100644 --- a/tests/03-three/misc/sweep-tag.test.js +++ b/tests/03-three/misc/sweep-tag.test.js @@ -38,3 +38,21 @@ test('sweep-freeze:', function (t) { t.equal(m.has('#Adjective'), false, here + 'front steps frozen') t.end() }) + +test('sweep-untag:', function (t) { + const matches = [ + { match: 'clinic', unTag: ['ProperNoun', 'Person'] }, + { match: 'walked', unTag: 'Verb' }, + ] + const net = nlp.buildNet(matches) + let doc = nlp('There are thirty days in the January Clinic') + doc.sweep(net) + const m = doc.match('clinic') + t.equal(m.has('#ProperNoun'), false, here + 'untag array first') + t.equal(m.has('#Person'), false, here + 'untag array second') + + doc = nlp('Spencer walked') + doc.sweep(net) + t.equal(doc.has('#PastTense'), false, here + 'untag children') + t.end() +})