This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Language-experiments is a Python project that converts literary texts into visual representations using linguistic analysis. It maps word and bigram frequency data to color values, creating images that represent textual patterns.
# Generate visualization from a text file
python book_png.py <path_to_text_file>
# Output: <filename>-lenbig.pngNo build system or test framework exists. Dependencies: NLTK, PIL/Pillow, Flask, SQLAlchemy.
Four visualization methods that convert tokenized text to PNG images:
blue_red_gradient_words- Maps word frequency to blue-red gradient using logarithmic scalingrandom_colored_words- Assigns consistent random colors per unique wordconditional_probabilities_bigrams- Colors based on bigram transition probabilities (disabled)possible_bigrams- Colors based on bigram diversity per word (currently active)
Processing pipeline: Text → nltk.word_tokenize() → frequency analysis → color mapping → square PNG output
Image dimensions are automatically calculated as √n × √n where n = number of words/bigrams.
Skeleton Flask app with SQLAlchemy models (User, Book, Picture, PictureParams) using SQLite. No routes implemented - database schema only.
- Functional decomposition: each visualization method is self-contained
- NLTK for all NLP operations (tokenization, bigrams, frequency distributions)
- PIL for pixel-by-pixel image generation
- Square grid layout maps linear sequences to 2D images
- RGB channels encode different frequency metrics
- Written for Python 2.x (uses deprecated patterns like
has_key(), old Flask-SQLAlchemy imports) - No error handling or input validation
- Active function in
book_png.pyispossible_bigrams()at the bottom of the file