{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7ad8de84",
   "metadata": {},
   "source": [
    "# 13-25 · Анализатор текста v2\n",
    "\n",
    "Практика к разделу [«Мини-проект — анализатор текста v2»](../../site/chapters/glava-13/13-25-mini-proekt-analizator-v2.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4c50aa45",
   "metadata": {},
   "source": [
    "## Цель\n",
    "\n",
    "Собрать анализатор текста из конвейера чистых функций."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "17d7dfb2",
   "metadata": {},
   "source": [
    "## Задание ★ Базовая практика"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8b7eb663",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-17T18:54:20.808151Z",
     "iopub.status.busy": "2026-08-17T18:54:20.808042Z",
     "iopub.status.idle": "2026-08-17T18:54:20.825462Z",
     "shell.execute_reply": "2026-08-17T18:54:20.824712Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'total_words': 7, 'unique_words': 5, 'counts': {'python': 2, 'is': 2, 'great': 1, 'and': 1, 'fun': 1}}\n"
     ]
    }
   ],
   "source": [
    "def normalize_text(text):\n",
    "    return text.lower()\n",
    "\n",
    "def split_words(text):\n",
    "    return text.split()\n",
    "\n",
    "def word_frequency(words):\n",
    "    counts = {}\n",
    "    for word in words:\n",
    "        counts[word] = counts.get(word, 0) + 1\n",
    "    return counts\n",
    "\n",
    "def build_summary(text):\n",
    "    clean = normalize_text(text)\n",
    "    words = split_words(clean)\n",
    "    counts = word_frequency(words)\n",
    "    return {\n",
    "        \"total_words\": len(words),\n",
    "        \"unique_words\": len(set(words)),\n",
    "        \"counts\": counts,\n",
    "    }\n",
    "\n",
    "summary = build_summary(\"Python is great and python is fun\")\n",
    "print(summary)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
