Repository navigation
Fix valid UTF-8 Chinese JSON misdetected as PTCP154 - #796
Conversation
Ousret
left a comment
There was a problem hiding this comment.
I tested it and it does regress other cases.
The CI itself report a few loss in coverage.
After running a couple of representative cases, I landed the following compromise:
if self._character_count < 4:
return 0.0
uncommon_form_usage: float = (
(2 * self._uncommon_count - self._character_count)
/ (5 * max(self._character_count, 16))
)
return max(0.0, uncommon_form_usage)regards,
|
Thanks for testing this and suggesting the compromise, @Ousret! I've applied your formula in 5adc843 to both the Python and Cython implementations, keeping the UTF-8 Chinese JSON regression test. I rechecked the short-input guard, the 50% boundary, the minimum denominator of 16, and the zero clamp in both implementations. Local validation passed:
The original JSON example still detects as UTF-8. Thanks again for helping preserve the other detection cases — could you take another look when you have a chance? |
Ousret
left a comment
There was a problem hiding this comment.
LGTM. The compromise seems to work as intended.
regards,
Problem
Commit 7835ef7 increased the CJK uncommon ratio from
/10to/5. For valid, meaningful Chinese text containing characters outside the limited common-character set, this can push UTF-8 chaos above the 10% fast-path threshold and allow single-byte encodings such as PTCP154 to rank first.Minimal reproduction:
{"title":"海岛旅居会员忠诚动因持续探索"}utf-8.ptcp154.Fix
/10in both the pure Python and Cython implementations.SuspiciousKatakanaPluginand the other detection improvements from 7835ef7 unchanged.detect(bytes)API.Validation