"""Week 6 demo 1: splitting text into chunks.

This intentionally uses simple Python so it can be read on a slide.
It is not the full StatsChat implementation.
"""

sample_text = """
Consumer Price Indices and Inflation Rates - March 2026.
Table 1: One month and twelve month percentage changes by CPI division.
Total: weight 100.0000, one month change 0.5%, twelve month change 4.4%.
Food and non-alcoholic beverages increased by 7.1% over twelve months.
Transport increased by 3.8% over twelve months.
Source: Kenya National Bureau of Statistics, CPI release, March 2026.
""".strip()


def chunk_words(text: str, max_words: int, overlap: int = 0) -> list[str]:
    """Split text into overlapping word chunks."""
    words = text.split()
    chunks = []
    start = 0

    while start < len(words):
        end = start + max_words
        chunks.append(" ".join(words[start:end]))
        start = end - overlap
        if start <= 0:
            start = end

    return chunks


for size in [16, 42]:
    print(f"\n--- max_words={size} ---")
    for i, chunk in enumerate(chunk_words(sample_text, size, overlap=4), start=1):
        print(f"Chunk {i}: {chunk}\n")
