Initial commit: 2125_GCE project

This commit is contained in:
GlyphRunner System
2026-07-09 12:54:44 -04:00
parent c3a826b65c
commit ae13f78c22
299 changed files with 124289 additions and 1031 deletions
Regular → Executable
+23 -8
View File
@@ -50,25 +50,33 @@ def normalize_segments(
Converts raw segment metadata from codex_lineage.segments into normalized form
with required keys: id, start_line, end_line, text, symbolic_lane, semantic_role.
Assumptions:
- Raw segments have: id, start, end (0-based line indices)
- Optional: lane, role metadata
- Text extraction is stubbed (reserved for future payload analysis)
Text extraction: Decompresses payload and extracts text for each segment using
byte ranges from segment metadata (start_byte, end_byte).
Args:
manifest: GX manifest dict
raw_segments: List of raw segment dicts from codex_lineage
payload: Compressed payload bytes (reserved for text extraction)
payload: Compressed payload bytes
Returns:
List of normalized segment dicts conforming to Segment schema
"""
from xic_extensions.gsz3_decompressor import GSZ3Decompressor, GSZ3DecompressionError
normalized = []
# Decompress payload to get full text
try:
decompressed = GSZ3Decompressor.decompress(payload)
except GSZ3DecompressionError:
decompressed = ""
for raw_seg in raw_segments:
seg_id = str(raw_seg.get("id", "unknown"))
start_line = int(raw_seg.get("start", 0))
end_line = int(raw_seg.get("end", 0))
start_byte = int(raw_seg.get("start_byte", 0))
end_byte = int(raw_seg.get("end_byte", len(decompressed)))
# Explicit lane from metadata, or infer
explicit_lane = raw_seg.get("lane")
@@ -83,8 +91,15 @@ def normalize_segments(
# Semantic role: infer from segment metadata
semantic_role = _infer_semantic_role(raw_seg)
# Text: stub for now; in production extract from payload via byte ranges
text = f"[segment {seg_id}: lines {start_line}{end_line}]"
# Extract text from decompressed payload using byte ranges
text = ""
if decompressed and start_byte < len(decompressed):
end = min(end_byte, len(decompressed))
text = decompressed[start_byte:end]
# Fallback if no text extracted
if not text.strip():
text = f"[segment {seg_id}: lines {start_line}{end_line}]"
normalized_seg = {
"id": seg_id,
@@ -93,7 +108,7 @@ def normalize_segments(
"text": text,
"symbolic_lane": symbolic_lane,
"semantic_role": semantic_role,
"_raw": raw_seg, # preserve original for debugging
"_raw": raw_seg,
}
normalized.append(normalized_seg)