Skip to content

Commit 9556620

Browse files
committed
docs(spec): a supplied word holding a separator other than one space is not found, and a test pins it
Claude-Session: https://claude.ai/code/session_01RKKVnjzReaqV9utX3JueMS Co-authored-by: Claude <noreply@anthropic.com>
1 parent 75fcae7 commit 9556620

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎packages/services/service-segmenter/README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ segmenter.status(); // { engine: 'dictionary', segmenter: 'jieba', purposes: ['k
4242

4343
1. NFKC normalisation between separators: fullwidth letters and digits fold to ASCII.
4444
2. The supplied `word` entries are taken out of the whole question by longest match, in any script
45-
(明规条款, `OA审批`, `5G套餐`), and kept whole.
45+
(明规条款, `OA审批`, `5G套餐`), and kept whole. A word that holds a separator other than a single
46+
space (`R&D`, 《员工手册》) is not found: the question is split at its separators first.
4647
3. A run of Han characters: cut by one process-wide jieba instance, with the platform words in its
4748
dictionary. Words equal to a stop word are dropped (compared whole, so 还是 never eats 归还), and
4849
adjacent single characters are joined into words of two (年|假 → 年假). Without jieba, the stop

‎packages/services/service-segmenter/src/segmenter-service.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,23 @@ describe('SegmenterService — supplied entries over the platform defaults', ()
148148
expect(jieba.keywordTerms('OAuth登录', { entries: [{ term: 'OA', kind: 'word' }] })).toEqual(['登录', 'OAuth']);
149149
});
150150

151+
it('does not find a supplied word that holds a separator other than a single space', () => {
152+
// The question is split at the keyword separators before the words are matched, so a word holding
153+
// one never matches whole (the contract says so); the pieces around the separator are cut as usual.
154+
const entries: SegmenterEntry[] = [
155+
{ term: 'R&D', kind: 'word' },
156+
{ term: '《员工手册》', kind: 'word' },
157+
];
158+
const rd = jieba.keywordTerms('R&D预算怎么申请', { entries });
159+
expect(rd).not.toContain('R&D');
160+
expect(rd).toEqual(jieba.keywordTerms('R&D预算怎么申请'));
161+
const handbook = jieba.keywordTerms('《员工手册》在哪里看', { entries });
162+
expect(handbook).not.toContain('《员工手册》');
163+
expect(handbook).toEqual(jieba.keywordTerms('《员工手册》在哪里看'));
164+
// Control: the same title without its marks is found whole.
165+
expect(jieba.keywordTerms('员工手册在哪里看', { entries: [{ term: '员工手册', kind: 'word' }] })).toContain('员工手册');
166+
});
167+
151168
it('reads the entries afresh on every call, an array changed in place included; empty is the same as absent', () => {
152169
const entries: SegmenterEntry[] = [];
153170
expect(jieba.keywordTerms('明规条款怎么查', { entries })).toEqual(jieba.keywordTerms('明规条款怎么查'));

‎packages/spec/src/contracts/segmenter-service.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ export type SegmenterEntryPurpose = SegmenterPurpose | 'both';
4444
* `5G套餐`, a kana or Hangul word, a phrase with one space. A term that
4545
* begins or ends with a letter or digit of a spaced script (Latin, Cyrillic,
4646
* digits …) is not found where that edge touches another such character, so
47-
* `OA` is not found inside `OAuth`.
47+
* `OA` is not found inside `OAuth`. A term that holds a separator other than
48+
* a single space (`R&D`, 《员工手册》, 办法(试行)) is not found: the question is
49+
* split at its separators before the words are matched.
4850
* - `stop_word`: a term of the answer equal to it is dropped, compared whole;
4951
* a stop word never removes part of a word. (A provider answering by
5052
* sliding windows may also take a stop word out of an unspaced run before it

0 commit comments

Comments
 (0)