File size: 2,888 Bytes
b20aa16
 
9876f72
 
 
 
 
b20aa16
9876f72
 
 
 
81fb9bf
9876f72
 
81fb9bf
 
 
33c0ee8
 
fa044a3
33c0ee8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a9b6932
33c0ee8
4504ca9
 
 
a9b6932
33c0ee8
9801434
 
 
 
33c0ee8
 
 
 
 
 
 
 
 
 
 
 
fa044a3
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
---
license: mit
task_categories:
- image-classification
- text-to-image
language:
- en
---

# Metadata Database for Danbooru2023
Danbooru 2023 datasets: https://huggingface.co/datasets/nyanko7/danbooru2023

This dataset contains a sqlite db file which have all the tags and posts metadata in it.<br>
The Peewee ORM config file is provided too, plz check it for more information. (Especially on how I link posts and tags together)

The original data is from the official dump of the posts info.<br>
Check this [link](https://console.cloud.google.com/storage/browser/danbooru_public/data) for more info.

**The ID range of this dataset(\~7111459) is slightly larger then the danbooru2023 dataset(\~6899125)** <br>
**This dataset have 7073868 entries**

## Details
This section contains some details that you need to be aware of if you want to use other ORM system or use plain SQL query to utilize this database.

#### Custom Enum Fields
Some fields in Post/Tags use my custom enum field to store type/category or something like that:

* Post.rating
  * 0: general
  * 1: sensitive
  * 2: questionable
  * 3: explicit
* Tag.type
  * 0: general
  * 1: artist
  * 2: character
  * 3: copyright
  * 4: meta

#### Tag List
SQLite doesn't support any arrayfield or many-to-many relationship natively.<br>
So I use a custom TextField to store ids of tags belongs to a Post.

The basic idea is to use 2 unique symbol for start/end of the number. And use 36-base number<br>
(python support converting n-base number into integer natively, numpy have utils to convert integer into n-base number)

I use $xxx# format, so when you want to utilize the FTS table to search tag_list, use $\<36-base number\># to find if the tag is in the tag-list.

For example:<br>
The code in profiling.py use $6KMR# which is 306675 under base-36.<br>
So the profiling.py is doing "fetch all the Post object which have 'umamusume' tag in their tag list"<br>
**If you can ensure the tag type, you can specific the tag_list_\<type\> instead of full tag_list for more efficiency**

## Profiling
A test script for showing why I use FTS.


#### Utils
if you think above details are too complicated, just use the db_utils.py and other PeeWee API to utilize this database.
I also provide a write_csv.py for exporting whole dataset into csv for data analysis.


## License
The source code, database file of this repo is licensed under MiT License.<br>
**Notice**: The license doesn't cover the "content" of the database.<br>
All the content is from official danbooru dumps for posts' meta.


## Acknowledgement
Thx for AngelBottomless for fixing wrong entries and add more entries into this dataset:<br>
https://huggingface.co/datasets/AngelBottomless/danbooru-2023-sqlite-fixed-7110548

Note: I have changed the definition of TagListField and have added some index into it. Do not mixed up the .db files from 2 different repo.