fix/crawler-proxy-config #42
@@ -567,24 +567,44 @@ class UnifiedSegmentationStrategy:
|
|||||||
return all_segments
|
return all_segments
|
||||||
|
|
||||||
def _fallback_chunk(self, chunk_text: str, offset: int) -> List[VideoSegment]:
|
def _fallback_chunk(self, chunk_text: str, offset: int) -> List[VideoSegment]:
|
||||||
"""对单个分块使用规则分段
|
"""对单个分块使用规则分段(降级)
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
chunk_text: 分块文本
|
chunk_text: 分块文本
|
||||||
offset: 该块在原文中的起始位置
|
offset: 该分块在原文中的起始位置
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
VideoSegment 对象列表
|
VideoSegment 对象列表
|
||||||
"""
|
"""
|
||||||
# 简单实现:将整个块作为一个分段
|
# 创建虚拟的分段对象用于规则分段器
|
||||||
return [
|
# 规则分段器需要 Segment 对象列表,我们创建一个包含整个文本的虚拟分段
|
||||||
VideoSegment(
|
from kb_workflow.srt.parser import Segment
|
||||||
title=None,
|
|
||||||
content=chunk_text,
|
virtual_segment = Segment(
|
||||||
start_index=offset,
|
index=1,
|
||||||
end_index=offset + len(chunk_text)
|
start_time=0.0,
|
||||||
|
end_time=1.0,
|
||||||
|
text=chunk_text
|
||||||
)
|
)
|
||||||
]
|
|
||||||
|
# 使用规则分段器
|
||||||
|
paragraphs = self.fallback_segmenter.segment([virtual_segment])
|
||||||
|
|
||||||
|
# 转换为 VideoSegment,并设置正确的偏移量
|
||||||
|
segments = []
|
||||||
|
current_pos = offset
|
||||||
|
for para in paragraphs:
|
||||||
|
# 计算该分段在原文中的位置
|
||||||
|
seg = VideoSegment(
|
||||||
|
title=None,
|
||||||
|
content=para,
|
||||||
|
start_index=current_pos,
|
||||||
|
end_index=current_pos + len(para)
|
||||||
|
)
|
||||||
|
segments.append(seg)
|
||||||
|
current_pos += len(para)
|
||||||
|
|
||||||
|
return segments
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user