A tool for expanding Danbooru tags with their implications and aliases
Project description
Danbooru Tag Expander
A Python tool for expanding Danbooru tags with their implications and aliases. This tool helps you get a complete set of related tags when working with Danbooru's tagging system.
Features
- Expand tags with their implications and aliases
- Support for both command-line and programmatic usage
- Configurable output formats (text, JSON, CSV)
- Progress tracking and detailed logging
- Caching support for better performance
Graph Theory Concepts
The tag expansion system can be understood through graph theory:
Tag Graph Structure
- Tags are nodes in a directed graph
- Two types of edges exist:
- Implications: Directed edges between different concepts (A → B means "A implies B")
- Aliases: Form equivalence classes (subgraphs) where all nodes represent the same concept
Frequency Calculation
- For implications:
- Multiple implications to the same tag sum their frequencies
- Example: If A implies X and B implies X, then freq(X) = freq(A) + freq(B)
- For aliases:
- All nodes in an alias subgraph share the same frequency
- Example: If X and Y are aliases, then freq(X) = freq(Y) = total frequency of their concept
- This reflects that aliases are different names for the same underlying concept
Example
Given:
- Tags: [cat, feline, kitten]
- Aliases: cat ↔ feline (they're the same concept)
- Implications: kitten → cat
Results:
- Expanded tags: [cat, feline, kitten]
- Frequencies:
- cat: 2 (1 from original + 1 from kitten implication)
- feline: 2 (same as cat since they're aliases)
- kitten: 1 (from original tag)
Installation
You can install the package using pip:
pip install danbooru-tag-expander
Usage
Command Line
# Basic usage with tags
danbooru-tag-expander --tags "1girl" "solo"
# Using a file containing tags
danbooru-tag-expander --file tags.txt
# Output in different formats
danbooru-tag-expander --tags "1girl" --format json
danbooru-tag-expander --tags "1girl" --format csv
# Control logging verbosity
danbooru-tag-expander --tags "1girl" --quiet
danbooru-tag-expander --tags "1girl" --log-level DEBUG
Python API
from danbooru_tag_expander.tag_expander import TagExpander
# Create an expander instance
expander = TagExpander(
username="your-username", # Optional, can be set via environment
api_key="your-api-key", # Optional, can be set via environment
use_cache=True # Enable caching for better performance
)
# Expand tags
expanded_tags, frequencies = expander.expand_tags(["1girl", "solo"])
# Print results
print(f"Original tags: 1girl, solo")
print(f"Expanded tags: {', '.join(expanded_tags)}")
Configuration
The tool can be configured using environment variables or command-line arguments:
DANBOORU_USERNAME: Your Danbooru usernameDANBOORU_API_KEY: Your Danbooru API keyDANBOORU_SITE_URL: Custom Danbooru instance URL (optional)DANBOORU_CACHE_DIR: Custom cache directory location (optional)
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file danbooru_tag_expander-0.1.6.tar.gz.
File metadata
- Download URL: danbooru_tag_expander-0.1.6.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e10ccbe7af70579b569ab44a75cc160c414ea0340352e592d95c24980e9ff9c1
|
|
| MD5 |
5762962f26dc9116fea6020d919e64bb
|
|
| BLAKE2b-256 |
2b6a9e999788bf31833e5395a253d423bd6a484d595082beb2ed62fb716f5871
|
File details
Details for the file danbooru_tag_expander-0.1.6-py3-none-any.whl.
File metadata
- Download URL: danbooru_tag_expander-0.1.6-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8893a8bce4811b35ff8a5cfdc96fd7edda3ecb3be062e7b4921ff675f3babf4
|
|
| MD5 |
08d931d9bd8b0655fbddbbc30c756926
|
|
| BLAKE2b-256 |
5cbb87de9d9297c5824337d7bfd038e80f839eec40dbc563f9504ec705002e7b
|