Danbooru Tag Graph
A NetworkX-based graph system for efficiently managing Danbooru tag relationships including implications, aliases, and deprecated status.
Features
- High-performance graph operations using NetworkX
- Tag relationship management (implications and aliases)
- Deprecated tag tracking
- Efficient serialization with pickle
- Transitive relationship queries
- Batch operations for optimal performance
Installation
pip install danbooru-tag-graph
Quick Start
from danbooru_tag_graph import DanbooruTagGraph
# Create a new graph
graph = DanbooruTagGraph()
# Add tags
graph.add_tag("cat", is_deprecated=False, fetched=True)
graph.add_tag("animal", is_deprecated=False, fetched=True)
graph.add_tag("feline", is_deprecated=False, fetched=True)
# Add relationships
graph.add_implication("cat", "animal") # cat implies animal
graph.add_alias("cat", "feline") # cat and feline are aliases
# Query relationships
implications = graph.get_implications("cat")
aliases = graph.get_aliases("cat")
transitive = graph.get_transitive_implications("cat")
# Expand tags with frequencies
expanded_tags, frequencies = graph.expand_tags(["cat"])
print(f"Expanded: {expanded_tags}")
print(f"Frequencies: {frequencies}")
# Save/load graph
graph.save_graph("my_tags.pickle")
new_graph = DanbooruTagGraph("my_tags.pickle")
Graph Structure
The tag graph uses NetworkX's MultiDiGraph with:
- Nodes: Individual tags with metadata (deprecated status, fetched status, etc.)
- Edges: Two types:
'implication': Directed edges from antecedent to consequent tags'alias': Bidirectional edges between alias tags
Performance Benefits
- Single file load vs thousands of individual files
- In-memory graph operations instead of repeated file I/O
- Batch relationship queries and transitive closure pre-computation
- Efficient serialization with pickle
API Reference
DanbooruTagGraph
Core Methods
add_tag(tag, is_deprecated=False, fetched=False, **metadata)- Add a tag nodeadd_implication(antecedent, consequent)- Add implication relationshipadd_alias(tag1, tag2)- Add alias relationshipis_tag_deprecated(tag)- Check if tag is deprecatedmark_tag_fetched(tag)- Mark tag as having relationships fetchedis_tag_fetched(tag)- Check if tag relationships are fetched
Query Methods
get_implications(tag, include_deprecated=False)- Get direct implicationsget_aliases(tag, include_deprecated=False)- Get direct aliasesget_transitive_implications(tag, include_deprecated=False)- Get all transitive implicationsget_alias_group(tag, include_deprecated=False)- Get complete alias groupexpand_tags(tags, include_deprecated=False)- Expand tags with frequencies
Persistence Methods
load_graph(cache_file)- Load graph from pickle filesave_graph(cache_file=None)- Save graph to pickle fileauto_save()- Save if graph has been modified
Utility Methods
stats()- Get graph statisticsget_unfetched_tags(tags)- Get list of tags needing data fetchimport_from_json_cache(cache_dir)- Import from old JSON cache format
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Metadata
Release files for danbooru-tag-graph 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| danbooru_tag_graph-0.2.2.tar.gz | 15.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| danbooru_tag_graph-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.2 kB
Release files / danbooru_tag_graph-0.2.2.tar.gz
| Download URL | danbooru_tag_graph-0.2.2.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9c671b56503d034a55073b89ad801b3f466f599fd35eb494694f03150f35bdb0
|
|
BLAKE2b-256 checksum How to use checksums |
2d8f0020cc7b7f8e89872db9120be86dd26507aedf233ec63352d4a5f8e0fc1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.17
|
Release files / danbooru_tag_graph-0.2.2-py3-none-any.whl
| Download URL | danbooru_tag_graph-0.2.2-py3-none-any.whl |
|---|---|
| Size | 9.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c89d6572c158340129bcb3592517f80615c60ca00f46cc7d27eaf210f33c8ff4
|
|
BLAKE2b-256 checksum How to use checksums |
9b07a6bb58a86cc188e506081a0196640325eafeaef98573fb39423bdd960bfe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.17
|