Spaces:
Sleeping
Sleeping
Update helpers/indexer.py
Browse files- helpers/indexer.py +26 -15
helpers/indexer.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
-
# helpers/indexer.py
|
| 2 |
from typing import List, Dict, Optional
|
| 3 |
|
| 4 |
def build_indexed_response(
|
| 5 |
texts: List[Dict[str, str]],
|
| 6 |
-
title_index: int,
|
| 7 |
-
preamble_end: int,
|
| 8 |
body_end: Optional[int] = None,
|
| 9 |
*,
|
| 10 |
preamble_start: Optional[int] = None,
|
|
@@ -20,19 +19,31 @@ def build_indexed_response(
|
|
| 20 |
return []
|
| 21 |
|
| 22 |
last_idx = len(texts) - 1
|
| 23 |
-
title_index = min(title_index, last_idx)
|
| 24 |
-
preamble_end = min(preamble_end, last_idx)
|
| 25 |
-
body_end = min(body_end if body_end is not None else last_idx, last_idx)
|
| 26 |
-
|
| 27 |
-
preamble_start = min(preamble_start or title_index + 1, last_idx)
|
| 28 |
-
body_start = min(body_start or preamble_end + 1, last_idx)
|
| 29 |
-
|
| 30 |
result = []
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
result.append({
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
return result
|
|
|
|
|
|
|
| 1 |
from typing import List, Dict, Optional
|
| 2 |
|
| 3 |
def build_indexed_response(
|
| 4 |
texts: List[Dict[str, str]],
|
| 5 |
+
title_index: Optional[int] = None,
|
| 6 |
+
preamble_end: Optional[int] = None,
|
| 7 |
body_end: Optional[int] = None,
|
| 8 |
*,
|
| 9 |
preamble_start: Optional[int] = None,
|
|
|
|
| 19 |
return []
|
| 20 |
|
| 21 |
last_idx = len(texts) - 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
result = []
|
| 23 |
|
| 24 |
+
# ===== العنوان =====
|
| 25 |
+
if title_index is not None and 0 <= title_index <= last_idx:
|
| 26 |
+
result.append({
|
| 27 |
+
"text": texts[title_index]["value"].strip(),
|
| 28 |
+
"type": "title"
|
| 29 |
+
})
|
| 30 |
+
|
| 31 |
+
# ===== المقدمة =====
|
| 32 |
+
if preamble_end is not None and preamble_end >= 0:
|
| 33 |
+
start = preamble_start or (title_index + 1 if title_index is not None else 0)
|
| 34 |
+
for i in range(start, min(preamble_end, last_idx) + 1):
|
| 35 |
+
result.append({
|
| 36 |
+
"text": texts[i]["value"].strip(),
|
| 37 |
+
"type": "preamble"
|
| 38 |
+
})
|
| 39 |
+
|
| 40 |
+
# ===== النص الأساسي (body) =====
|
| 41 |
+
start_body = body_start or (preamble_end + 1 if preamble_end is not None else 0)
|
| 42 |
+
end_body = body_end or last_idx
|
| 43 |
+
for i in range(start_body, min(end_body, last_idx) + 1):
|
| 44 |
+
result.append({
|
| 45 |
+
"text": texts[i]["value"].strip(),
|
| 46 |
+
"type": "body"
|
| 47 |
+
})
|
| 48 |
|
| 49 |
return result
|