update content_summary in chunking
Browse files- app/law_document_chunker.py +15 -34
app/law_document_chunker.py
CHANGED
|
@@ -181,47 +181,28 @@ class LawDocumentChunker:
|
|
| 181 |
# và xuất hiện trước chunk hiện tại
|
| 182 |
ancestors = []
|
| 183 |
|
| 184 |
-
# Tìm
|
| 185 |
-
|
| 186 |
-
|
| 187 |
if chunk_id == parent_id:
|
| 188 |
-
parent_index = i
|
| 189 |
break
|
| 190 |
-
|
| 191 |
-
if parent_index == -1:
|
| 192 |
-
logger.warning(f"[CHUNKER] Parent chunk {parent_id} not found in stack")
|
| 193 |
-
return
|
| 194 |
-
|
| 195 |
-
# Tìm tất cả chunks có level cao hơn từ index trước đó
|
| 196 |
-
level_priority = {
|
| 197 |
-
"PHAN": 1, "PHU_LUC": 1, "CHUONG": 2, "MUC": 3,
|
| 198 |
-
"DIEU": 4, "KHOAN": 5, "DIEM": 6, "CONTENT": 7
|
| 199 |
-
}
|
| 200 |
-
|
| 201 |
-
# Tìm parent level của chunk hiện tại
|
| 202 |
-
current_level = None
|
| 203 |
-
for chunk_id, level, _, _ in chunk_stack:
|
| 204 |
-
if chunk_id == parent_id:
|
| 205 |
-
current_level = level
|
| 206 |
-
break
|
| 207 |
-
|
| 208 |
-
if not current_level:
|
| 209 |
-
return
|
| 210 |
-
|
| 211 |
-
current_priority = level_priority.get(current_level, 999)
|
| 212 |
-
|
| 213 |
-
# Tìm tất cả ancestors từ index trước chunk hiện tại
|
| 214 |
-
for i in range(parent_index - 1, -1, -1):
|
| 215 |
-
chunk_id, level, level_value, content = chunk_stack[i]
|
| 216 |
-
|
| 217 |
# Tìm tất cả chunks Điều xuất hiện trước chunk hiện tại
|
| 218 |
if level == "DIEU":
|
| 219 |
ancestors.append((level, level_value, content))
|
| 220 |
logger.debug(f"[CHUNKER] Found DIEU ancestor: {level_value}")
|
| 221 |
# Tìm chunks Khoản chỉ nếu chunk hiện tại là Điểm
|
| 222 |
-
elif level == "KHOAN"
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
logger.debug(f"[CHUNKER] Found {len(ancestors)} ancestors: {[(level, value) for level, value, content in ancestors]}")
|
| 227 |
|
|
|
|
| 181 |
# và xuất hiện trước chunk hiện tại
|
| 182 |
ancestors = []
|
| 183 |
|
| 184 |
+
# Tìm tất cả chunks Điều và Khoản xuất hiện trước chunk hiện tại
|
| 185 |
+
for chunk_id, level, level_value, content in chunk_stack:
|
| 186 |
+
# Dừng khi gặp chunk hiện tại
|
| 187 |
if chunk_id == parent_id:
|
|
|
|
| 188 |
break
|
| 189 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
# Tìm tất cả chunks Điều xuất hiện trước chunk hiện tại
|
| 191 |
if level == "DIEU":
|
| 192 |
ancestors.append((level, level_value, content))
|
| 193 |
logger.debug(f"[CHUNKER] Found DIEU ancestor: {level_value}")
|
| 194 |
# Tìm chunks Khoản chỉ nếu chunk hiện tại là Điểm
|
| 195 |
+
elif level == "KHOAN":
|
| 196 |
+
# Tìm level của chunk hiện tại
|
| 197 |
+
current_level = None
|
| 198 |
+
for cid, lvl, _, _ in chunk_stack:
|
| 199 |
+
if cid == parent_id:
|
| 200 |
+
current_level = lvl
|
| 201 |
+
break
|
| 202 |
+
|
| 203 |
+
if current_level == "DIEM":
|
| 204 |
+
ancestors.append((level, level_value, content))
|
| 205 |
+
logger.debug(f"[CHUNKER] Found KHOAN ancestor: {level_value}")
|
| 206 |
|
| 207 |
logger.debug(f"[CHUNKER] Found {len(ancestors)} ancestors: {[(level, value) for level, value, content in ancestors]}")
|
| 208 |
|