|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Sentibank is a Python package that provides a comprehensive database of expert-curated sentiment dictionaries and lexicons for sentiment analysis. It consolidates 15+ sentiment dictionaries spanning various domains (general, finance, social media, psychology, politics) into an integrated, open-source resource. |
| 8 | + |
| 9 | +## Key Commands |
| 10 | + |
| 11 | +### Development Setup |
| 12 | +```bash |
| 13 | +# Install the package in development mode |
| 14 | +pip install -e ".[dev]" |
| 15 | + |
| 16 | +# Install dependencies |
| 17 | +pip install -r requirements.txt |
| 18 | +pip install -r test_requirements.txt |
| 19 | + |
| 20 | +# Run tests with coverage |
| 21 | +pytest tests/ --cov=sentibank --cov-report=html |
| 22 | + |
| 23 | +# Run legacy basic test |
| 24 | +python test.py |
| 25 | + |
| 26 | +# Lint and format code |
| 27 | +black sentibank/ |
| 28 | +isort sentibank/ |
| 29 | +flake8 sentibank/ |
| 30 | +mypy sentibank/ |
| 31 | + |
| 32 | +# Build distribution (modern) |
| 33 | +python -m build |
| 34 | + |
| 35 | +# Build distribution (legacy) |
| 36 | +python setup.py sdist bdist_wheel |
| 37 | +``` |
| 38 | + |
| 39 | +### Package Installation (for users) |
| 40 | +```bash |
| 41 | +pip install sentibank |
| 42 | +``` |
| 43 | + |
| 44 | +### CLI Usage |
| 45 | +```bash |
| 46 | +# List available dictionaries |
| 47 | +sentibank list |
| 48 | + |
| 49 | +# Analyze sentiment |
| 50 | +sentibank analyze VADER_v2014 "I love this product!" |
| 51 | + |
| 52 | +# Get dictionary info |
| 53 | +sentibank info VADER_v2014 |
| 54 | + |
| 55 | +# Export dictionary |
| 56 | +sentibank export VADER_v2014 --format json |
| 57 | +``` |
| 58 | + |
| 59 | +## Architecture |
| 60 | + |
| 61 | +### Core Components |
| 62 | + |
| 63 | +**sentibank/archive.py** - Main data loading interface |
| 64 | +- `load` class provides methods to: |
| 65 | + - `dict(idx)` - Load preprocessed sentiment dictionaries |
| 66 | + - `origin(idx)` - Load original raw datasets |
| 67 | + - `json_dict(idx)` - Load JSON format dictionaries |
| 68 | + |
| 69 | +**sentibank/utils.py** - Analysis utilities |
| 70 | +- `analysis` class for sentiment analysis operations |
| 71 | +- `analyze()` provides: |
| 72 | + - `dictionary(dictionary)` - Analyze dictionary structure/stats |
| 73 | + - `sentiment(text, dictionary)` - Perform sentiment analysis on text |
| 74 | + |
| 75 | +**sentibank/validate.py** - Dictionary validation functionality |
| 76 | + |
| 77 | +**sentibank/dict_arXiv/** - Pre-processed sentiment dictionaries storage |
| 78 | +- Each dictionary stored in multiple formats: CSV (original), JSON, Pickle |
| 79 | +- Organized by dictionary name in subdirectories |
| 80 | + |
| 81 | +### Dictionary Loading System |
| 82 | + |
| 83 | +The package uses a path-based mapping system to load dictionaries. Each dictionary identifier maps to a specific subdirectory containing preprocessed versions. Dictionary identifiers follow patterns: |
| 84 | +- `{NAME}_{VERSION}` - Base processed version |
| 85 | +- `{NAME}_{VERSION}_{refinement}` - With additional transformations (e.g., "_boosted", "_norm", "_simple") |
| 86 | + |
| 87 | +### Sentiment Analysis Approach |
| 88 | + |
| 89 | +The package implements bag-of-words sentiment analysis: |
| 90 | +- Score-based dictionaries: Returns sum of matched term scores (float/int) |
| 91 | +- Label-based dictionaries: Returns dictionary with counts per sentiment category |
| 92 | + |
| 93 | +## Development Notes |
| 94 | + |
| 95 | +### Dependencies |
| 96 | +- spacy==3.7.2 (with en_core_web_sm model) |
| 97 | +- spacymoji==3.1.0 (emoji detection) |
| 98 | +- pandas==2.1.4 |
| 99 | +- pyenchant==3.2.2 (spell checking) |
| 100 | +- rich==13.4.2 (CLI display) |
| 101 | + |
| 102 | +The package auto-downloads the spacy en_core_web_sm model if not present. |
| 103 | + |
| 104 | +### Adding New Dictionaries |
| 105 | + |
| 106 | +New sentiment dictionaries should: |
| 107 | +1. Be placed in `sentibank/dict_arXiv/{DictionaryName}/` |
| 108 | +2. Include CSV original, JSON, and Pickle formats |
| 109 | +3. Add mapping in `archive.py` lexicon_paths dictionary |
| 110 | +4. Follow naming convention: `{Name}_v{Year}` or with refinement suffix |
| 111 | + |
| 112 | +### Testing |
| 113 | + |
| 114 | +Run `python test.py` to verify: |
| 115 | +- Package imports correctly |
| 116 | +- Dictionary loading works |
| 117 | +- Analyzer initializes properly |
| 118 | + |
| 119 | +## Repository Structure |
| 120 | + |
| 121 | +``` |
| 122 | +sentibank/ |
| 123 | +βββ sentibank/ # Main package |
| 124 | +β βββ __init__.py |
| 125 | +β βββ archive.py # Dictionary loading |
| 126 | +β βββ utils.py # Analysis utilities |
| 127 | +β βββ validate.py # Validation functions |
| 128 | +β βββ dict_arXiv/ # Dictionary data storage |
| 129 | +βββ docs/ # Documentation (Jupyter Book) |
| 130 | +βββ setup.py # Package configuration |
| 131 | +βββ requirements.txt # Dependencies |
| 132 | +βββ test.py # Basic functionality tests |
| 133 | +``` |
0 commit comments