|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""v1.108.161 — BM25 tokenizer no longer discards non-ASCII text (jdoc #91 class). |
| 3 | +
|
| 4 | +_TOKEN_RE was [a-zA-Z0-9]{2,}, so every non-ASCII character acted as a |
| 5 | +separator: CJK symbol names/summaries/docstrings produced zero BM25 tokens |
| 6 | +and accented Latin was mangled. Now splits on Unicode word boundaries and |
| 7 | +expands CJK runs into overlapping character bigrams — identical at index and |
| 8 | +query time, so bigram overlap is the match signal. Suite parity with |
| 9 | +jdocmunch-mcp v1.114.1 and jdatamunch-mcp v1.23.1. |
| 10 | +""" |
| 11 | + |
| 12 | +from jcodemunch_mcp.tools.search_symbols import _cjk_bigrams, _tokenize |
| 13 | + |
| 14 | + |
| 15 | +class TestCJKTokenization: |
| 16 | + def test_korean_produces_bigrams(self): |
| 17 | + toks = _tokenize("초과근무 승인 규칙") |
| 18 | + assert toks == ["초과", "과근", "근무", "승인", "규칙"] |
| 19 | + |
| 20 | + def test_mixed_camelcase_and_korean(self): |
| 21 | + toks = _tokenize("OvertimeService 초과근무 계산") |
| 22 | + assert "overtime" in toks and "service" in toks |
| 23 | + assert "초과" in toks and "근무" in toks and "계산" in toks |
| 24 | + |
| 25 | + def test_accented_latin_survives_intact(self): |
| 26 | + # Was ['caf', 've'] (single-char fragments dropped by the old {2,}). |
| 27 | + toks = _tokenize("café naïve") |
| 28 | + assert "café" in toks and "naïve" in toks |
| 29 | + |
| 30 | + def test_japanese_bigrams(self): |
| 31 | + toks = _tokenize("日本語のドキュメント") |
| 32 | + assert "日本" in toks and "本語" in toks |
| 33 | + |
| 34 | + def test_single_cjk_char_kept(self): |
| 35 | + assert _tokenize("車") == ["車"] |
| 36 | + |
| 37 | + def test_mixed_script_run_splits(self): |
| 38 | + toks = _tokenize("초과근무OvertimeService") |
| 39 | + assert "overtime" in toks and "초과" in toks |
| 40 | + |
| 41 | + def test_bigram_helper(self): |
| 42 | + assert _cjk_bigrams("가") == ["가"] |
| 43 | + assert _cjk_bigrams("가나") == ["가나"] |
| 44 | + assert _cjk_bigrams("가나다") == ["가나", "나다"] |
| 45 | + |
| 46 | + def test_ascii_behavior_unchanged(self): |
| 47 | + # camelCase split + stemming + abbreviation expansion all intact. |
| 48 | + assert _tokenize("getUserData") == ["get", "user", "data"] |
| 49 | + toks = _tokenize("config") |
| 50 | + assert "config" in toks and "configuration" in toks |
| 51 | + # Single-char ASCII tokens still dropped (old {2,} behavior). |
| 52 | + assert _tokenize("a b") == [] |
0 commit comments