build_tools.syllable_walk_tui.modules.analyzer.exporter
Analysis export functionality.
This module provides functions to export corpus shape metrics to text format for sharing and discussion. Exports are human-readable and include all metrics displayed on the AnalysisScreen.
- Design Philosophy:
Mirror the screen display in text form
Include timestamps and corpus paths for provenance
Pure formatting functions (no side effects except final write)
Percentages shown in parentheses for contextual understanding
- Percentage Display:
Exported metrics include percentages where they add meaningful context:
Length distribution: Each length count shown as “length:count (pct%)” where pct is the share of total inventory at that length. Example: “2:120 (9.7%), 3:456 (37.0%)”
Hapax rate: Syllables appearing exactly once, shown as “count (pct%)” where pct is hapax_count / total_syllables * 100. Example: “Hapax (freq=1): 456 (37.0%)”
Top 5 frequency: Each top syllable shown as “syllable: count (pct%)” where pct is count / total_occurrences * 100. Example: “the: 500 (4.1%)”
These percentages help users quickly assess: - Syllable shape preferences (length distribution) - Vocabulary diversity vs. concentration (hapax rate) - Zipfian distribution characteristics (top N coverage)
- Export Format:
CORPUS SHAPE METRICS EXPORT Generated: YYYY-MM-DD HH:MM:SS
Corpus: corpus_name
- INVENTORY
Total syllables: 1,234 Length dist: 2:120 (9.7%), 3:456 (37.0%), …
- FREQUENCY
Hapax (freq=1): 456 (37.0%) Top 5 by frequency:
the: 500 (4.1%) …
[FEATURE SATURATION, TERRAIN sections follow]
[Same format as Patch A]
Functions
Format inventory metrics as text. |
|
|
Format frequency metrics as text. |
Format feature saturation metrics as text. |
|
|
Format terrain metrics as text with ASCII bars. |
|
Format all metrics for a single patch. |
|
Format complete analysis export for both patches. |
|
Export analysis to a text file. |
Generate a timestamped filename for export. |
Module Contents
- build_tools.syllable_walk_tui.modules.analyzer.exporter.format_inventory_metrics(inv)[source]
Format inventory metrics as text.
Displays raw counts and derived percentages for length distribution. Percentages show each length’s share of total inventory.
- Parameters:
inv (build_tools.syllable_walk_tui.services.metrics.InventoryMetrics) – Inventory metrics to format
- Returns:
Formatted text block with length distribution percentages
- Return type:
- Example output:
- INVENTORY
Total syllables: 1,234 Length min: 2 Length max: 8 Length mean: 3.45 Length median: 3.0 Length std: 1.23 Length dist: 2:120 (9.7%), 3:456 (37.0%), 4:389 (31.5%), …
- build_tools.syllable_walk_tui.modules.analyzer.exporter.format_frequency_metrics(freq, total_syllables=None)[source]
Format frequency metrics as text.
Displays raw frequency statistics and derived percentages for: - Hapax rate: percentage of unique syllables appearing exactly once - Top 5 coverage: percentage of total occurrences for most frequent syllables
- Parameters:
freq (build_tools.syllable_walk_tui.services.metrics.FrequencyMetrics) – Frequency metrics to format
total_syllables (int | None) – Total unique syllable count (from InventoryMetrics) for computing hapax rate percentage. If None, percentage is omitted.
- Returns:
Formatted text block with percentages in parentheses
- Return type:
- Example output:
- FREQUENCY
Total occurrences: 12,345 Freq min: 1 Freq max: 500 Freq mean: 10.00 Freq median: 5.0 Freq std: 25.50 Unique freq values: 234 Hapax (freq=1): 456 (37.0%) … Top 5 by frequency:
the: 500 (4.1%) and: 350 (2.8%)
- build_tools.syllable_walk_tui.modules.analyzer.exporter.format_feature_saturation(feat)[source]
Format feature saturation metrics as text.
- Parameters:
feat (build_tools.syllable_walk_tui.services.metrics.FeatureSaturationMetrics) – Feature saturation metrics to format
- Returns:
Formatted text block
- Return type:
- build_tools.syllable_walk_tui.modules.analyzer.exporter.format_terrain_metrics(terrain)[source]
Format terrain metrics as text with ASCII bars.
Hi-fi resolution (30 chars) with center marker and delta display.
- Parameters:
terrain (build_tools.syllable_walk_tui.services.metrics.TerrainMetrics) – Terrain metrics to format
- Returns:
Formatted text block with visualization
- Return type:
- build_tools.syllable_walk_tui.modules.analyzer.exporter.format_patch_metrics(patch_name, metrics, corpus_path=None)[source]
Format all metrics for a single patch.
Combines inventory, frequency, feature saturation, and terrain metrics into a single formatted text block. Passes total_syllables from inventory to frequency formatter for hapax rate percentage computation.
- Parameters:
patch_name (str) – “A” or “B”
metrics (build_tools.syllable_walk_tui.services.metrics.CorpusShapeMetrics | None) – Corpus shape metrics, or None if not loaded
corpus_path (pathlib.Path | None) – Optional path to corpus directory
- Returns:
Formatted text block for entire patch with all metrics and percentages
- Return type:
- build_tools.syllable_walk_tui.modules.analyzer.exporter.format_analysis_export(metrics_a, metrics_b, corpus_path_a=None, corpus_path_b=None)[source]
Format complete analysis export for both patches.
- Parameters:
metrics_a (build_tools.syllable_walk_tui.services.metrics.CorpusShapeMetrics | None) – Metrics for Patch A, or None if not loaded
metrics_b (build_tools.syllable_walk_tui.services.metrics.CorpusShapeMetrics | None) – Metrics for Patch B, or None if not loaded
corpus_path_a (pathlib.Path | None) – Optional path to Patch A corpus
corpus_path_b (pathlib.Path | None) – Optional path to Patch B corpus
- Returns:
Complete formatted export text
- Return type:
- build_tools.syllable_walk_tui.modules.analyzer.exporter.export_analysis_to_file(filepath, metrics_a, metrics_b, corpus_path_a=None, corpus_path_b=None)[source]
Export analysis to a text file.
- Parameters:
filepath (pathlib.Path) – Path to write the export file
metrics_a (build_tools.syllable_walk_tui.services.metrics.CorpusShapeMetrics | None) – Metrics for Patch A, or None if not loaded
metrics_b (build_tools.syllable_walk_tui.services.metrics.CorpusShapeMetrics | None) – Metrics for Patch B, or None if not loaded
corpus_path_a (pathlib.Path | None) – Optional path to Patch A corpus
corpus_path_b (pathlib.Path | None) – Optional path to Patch B corpus
- Returns:
Path to the written file
- Raises:
OSError – If file cannot be written
- Return type: