15m33 恢复成书页末语义切: findSemanticCut 从纯115硬切恢复为句末标点+段落边界切, 修'BUG后整段劈'+'三、运营方'标题被劈成'三|、'顶层编号孤标题
Auto Release / build (push) Successful in 6m25s
Auto Release / build (push) Successful in 6m25s
This commit is contained in:
@@ -647,13 +647,34 @@ public class CustomScreenManager implements Listener {
|
||||
private int findSemanticCut(String s, int limit) { return findSemanticCut(s, limit, 10); }
|
||||
private int findSemanticCut(String s, int limit, int tol) {
|
||||
if (s.length() <= limit) return s.length();
|
||||
// 15m10 先歇着句末/逗号语义切, 统一整字符硬切 limit:
|
||||
// 验证"纯按字数切"会不会把标点劈到下一页。若整字符也断标点, 水还深, 再启语义切。
|
||||
// [15m9 句末歇着] int searchEnd=Math.min(s.length()-1, limit+tol); int best=-1;
|
||||
// [15m9 句末歇着] for(int i=searchEnd;i>=0;i--){char c=s.charAt(i);if(c=='。'||c=='!'||c=='?'||c==';'||c=='\n'){best=i+1;break;}}
|
||||
// [15m9 孤短退化歇着] if(best<55)best=-1; if(best>0&&best<=limit+tol)return best;
|
||||
// [15m9 逗号退化歇着] for(int i=Math.min(s.length()-1,limit-1);i>=0;i--){char c=s.charAt(i);if(c==','||c==','||c=='、'||c==' '||c=='\n')return i+1;}
|
||||
// 整字符硬切 limit
|
||||
// 15m33 恢复句末语义切: 在 limit 附近找最近句末标点(。!?;)或段落边界(\n)切, 避免劈词/劈标题。
|
||||
// 整字符 115 硬切已验证会劈"详见第六章第3节"→"详|见"、劈"三、运营方"→"三|、",
|
||||
// 恢复句末切: 切点落句末标点/段落边界, 残句自然续下一页, 整篇读着连贯。
|
||||
// 段落边界(\n)=标题行/新段落, 整行翻页不劈; 句末标点=句子切分。
|
||||
int searchEnd = Math.min(s.length() - 1, limit + tol);
|
||||
// ① 最近段落边界 \n 优先(标题行整行翻页, 防劈"三、运营方"标题)
|
||||
// 阈值: 段边界切点在 [55, limit+tol] 内才采纳——过靠前(<55)孤稀, 过远(>limit+tol)页超115
|
||||
for (int i = searchEnd; i >= 0; i--) {
|
||||
if (s.charAt(i) == '\n') {
|
||||
int pcut = i + 1;
|
||||
if (pcut >= 55 && pcut <= limit + tol) return pcut;
|
||||
}
|
||||
}
|
||||
// ② 最近句末标点(。!?;)
|
||||
int best = -1;
|
||||
for (int i = searchEnd; i >= 0; i--) {
|
||||
char c = s.charAt(i);
|
||||
if (c == '。' || c == '!' || c == '?' || c == ';') { best = i + 1; break; }
|
||||
}
|
||||
// 孤短退化: 句末切点太靠前(<55, 半页空)则放弃句末, 退化到逗号/顿号/空格
|
||||
if (best < 55) best = -1;
|
||||
if (best > 0 && best <= limit + tol) return best;
|
||||
// ③ 逗号/顿号/空格退化切
|
||||
for (int i = Math.min(s.length() - 1, limit - 1); i >= 0; i--) {
|
||||
char c = s.charAt(i);
|
||||
if (c == ',' || c == ',' || c == '、' || c == ' ' || c == '\n') return i + 1;
|
||||
}
|
||||
// 兜底硬切 limit (后续套 protectCut 保护编号/英文词)
|
||||
return limit;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user