Token Classification
Transformers
ONNX
Safetensors
English
Japanese
Chinese
bert
anime
filename-parsing
Eval Results (legacy)
Run this model with HF Jobs
Run ModerRAS/AniFileBERT on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/ModerRAS/AniFileBERT. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/ModerRAS/AniFileBERT on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use ModerRAS/AniFileBERT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ModerRAS/AniFileBERT with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="ModerRAS/AniFileBERT")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForTokenClassification tokenizer = AutoTokenizer.from_pretrained("ModerRAS/AniFileBERT") model = AutoModelForTokenClassification.from_pretrained("ModerRAS/AniFileBERT", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Add Rust schema v2 synthetic augmentation
Browse filesFiles changed (8)
- AGENTS.md+35-2
- data/synthetic_numeric_titles.txtAdded+148
- data/synthetic_path_prefixes.txtAdded+154
- tools/schema_v2_synthetic_augment/Cargo.lockAdded+664
- tools/schema_v2_synthetic_augment/Cargo.tomlAdded+15
- tools/schema_v2_synthetic_augment/README.mdAdded+151
- tools/schema_v2_synthetic_augment/src/bin/validate_synthetic_aug_jsonl.rsAdded+251
- tools/schema_v2_synthetic_augment/src/main.rsAdded+1573
91 unmodified lines92939495969771 unmodified lines16917017117217317412 unmodified lines18718818919019119219319491 unmodified lines`--apply-label-repairs`. Regenerate the cache after changing the JSONL, vocab,label schema, max length, split ratio, or seed.Export for Android:```bash71 unmodified lines- For Rust encoded-cache changes, run `cargo check --manifest-path tools\encoded_dataset_cache\Cargo.toml`,generate a small cache with `--limit-rows`, and verify `python -m anifilebert.train`can start with `--encoded-cache-dir`.- For export changes, run `python -m tools.export_onnx ...` and confirm the exporterreports a small PyTorch/ONNX logits difference.- For performance-sensitive inference changes, run `uv run python -m tools.benchmark_inference ...`12 unmodified lines- For real training, choose exactly one current dataset:`datasets/AnimeName/dmhy_weak.jsonl` for regex tokenization or`datasets/AnimeName/dmhy_weak_char.jsonl` for character tokenization.Treat `mixed_train.jsonl`, `ab_mix_100k.jsonl`, and other alternate JSONLfiles as legacy unless a task explicitly asks to inspect them.- The published default checkpoint is the character tokenizer variant with`max_seq_length=128`. Keep `vocab.json`, `vocab.char.json`, `config.json`,ONNX export, Android assets, and docs synchronized.91 unmodified lines929394959697989910010110210310410510610710810911011111211311411511611711811912012171 unmodified lines19319419519619719819920020120220320412 unmodified lines21721821922022122222322422522622791 unmodified lines`--apply-label-repairs`. Regenerate the cache after changing the JSONL, vocab,label schema, max length, split ratio, or seed.Generate schema v2 synthetic augmentation with Rust. This is an independentaugmentation chain and must not rewrite the authoritative DMHY dataset or themain DMHY template-application flow:```powershellcargo run --release --manifest-path tools\schema_v2_synthetic_augment\Cargo.toml --bin schema_v2_synthetic_augment -- `--recipes reports\dmhy_template_recipes.full_top5000.seed.jsonl `--label-schema-file label_schema.json `--numeric-title-seeds data\synthetic_numeric_titles.txt `--path-prefix-seeds data\synthetic_path_prefixes.txt `--limit-templates 3000 `--max-rows 50000 `--output data\schema_v2_synthetic_aug.jsonl `--manifest-output data\schema_v2_synthetic_aug.manifest.json```Validate the generated augmentation with the Rust validator:```powershellcargo run --release --manifest-path tools\schema_v2_synthetic_augment\Cargo.toml --bin validate_synthetic_aug_jsonl -- `--input data\schema_v2_synthetic_aug.jsonl `--manifest data\schema_v2_synthetic_aug.manifest.json```Export for Android:```bash71 unmodified lines- For Rust encoded-cache changes, run `cargo check --manifest-path tools\encoded_dataset_cache\Cargo.toml`,generate a small cache with `--limit-rows`, and verify `python -m anifilebert.train`can start with `--encoded-cache-dir`.- For schema v2 synthetic augmentation changes, prefer Rust tools over Python:run `cargo test --manifest-path tools\schema_v2_synthetic_augment\Cargo.toml`,generate a small smoke JSONL, and validate it with the Rust`validate_synthetic_aug_jsonl` binary. Confirm the manifest reports separate`path_series_rows`, `path_movie_rows`, `path_special_rows`,`path_confuser_rows`, and `dropped_media_kind_mismatch`.- For export changes, run `python -m tools.export_onnx ...` and confirm the exporterreports a small PyTorch/ONNX logits difference.- For performance-sensitive inference changes, run `uv run python -m tools.benchmark_inference ...`12 unmodified lines- For real training, choose exactly one current dataset:`datasets/AnimeName/dmhy_weak.jsonl` for regex tokenization or`datasets/AnimeName/dmhy_weak_char.jsonl` for character tokenization.Synthetic augmentation JSONL such as `data/schema_v2_synthetic_aug.jsonl`should be mixed in as an independent augmentation source, not treated as areplacement for the authoritative dataset. Treat `mixed_train.jsonl`,`ab_mix_100k.jsonl`, and other alternate JSONL files as legacy unless a taskexplicitly asks to inspect them.- The published default checkpoint is the character tokenizer variant with`max_seq_length=128`. Keep `vocab.json`, `vocab.char.json`, `config.json`,ONNX export, Android assets, and docs synchronized.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148# Numeric-title synthetic seeds.# Keep each seed internally style-consistent. Numbers inside these titles are title-owned.
# Canonical short / title-like numeric patterns7-nin no Majo100-nin no Kanojo3-gatsu no Lion12-gatsu no Uta91 Days500 Days86Area 88No.6Level E11-nin Iru!20 Seiki Denki Mokuroku21 Emon8-gatsu no Symphony07-Ghost22/7009 Re:Cyborg801 T.T.S. Airbats2.43 Seiin Koukou Danshi Volley-bu4-nin wa Sorezore Uso wo Tsuku5-toubun no Hanayome18if
# Romanized Japanese / light-novel style7-nin no Maou to Hazure Skill no Slow Life7-nin no Yuusha wa Kyou mo Dungeon ni Moguru7-nin no Kouhai to Himitsu no Gakuen7-nin no Osananajimi ga Isekai de Guild wo Tsukuru7-nin no Majo to Zero no Kishi7-nin no Tantei wa Natsu ni Uso wo Tsuku7-nin no Senpai ga Haishin wo Hajimeta7-nin no Imouto to Mahou no Kyoushitsu100-nin no Classmate ni Kokuhaku Sareta Ore100-nin no Guild Member to Hajimeru Isekai Seikatsu100-nin no Maou ga Boku no Ie ni Sumitsuita100-nin no Kanojo ga Dungeon de Matteru100-nin no Yuusha Kouho to Saigo no Shiken100-nin no Mahoutsukai to Nemurenai Oujo100-nin no Akuyaku Reijou to Level 1 no Ore100-nin no Senpai ga Erabu Tada Hitotsu no Mahou3-gatsu no Guild de 12-kai Me no Tensei3-gatsu no Mahoutsukai wa 7-nin no Deshi wo Motsu3-gatsu no Kimi to 100-nin no Yakusoku3-gatsu no Gakuen ni Level E no Kaze ga Fuku3-gatsu no Yuusha wa 86-banme ni Warau3-gatsu no Dungeon de Asa wo Matsu12-gatsu no Majo wa 3-gatsu ni Kaeru12-gatsu no Guild to 7-nin no Yuusha12-gatsu no Senpai wa 100-nin no Namae wo Shiranai12-gatsu no Netoge Yome wa Level 212-gatsu no Akuyaku Reijou wa No.6 ni Sumu12-gatsu no Mahou ShotenNo.6 Chiku no Saigo no MahoutsukaiNo.6 no Kouhai wa Level ENo.6 no Heya ni 7-nin no MaouNo.6 kara Hajimaru Slow LifeArea 88 no Sora ni Kieta YuushaArea 88 no Kishi to Sabaku no MajoArea 88 kara Kita KouhaiArea 88 no Mahoutsukai wa Yoru ni Tobu86-banme no Yuusha wa Season 2 wo Shinjinai86-banme no Maou to Nanatsu no Yakusoku86 no Gakuen de Hajimaru Isekai Haishin86 no Senpai wa Dungeon ni KaeranaiLevel E no Kouhai wa 3-gatsu ni WarauLevel E no Maou to 100-nin no DeshiLevel E no Kyoushitsu ni No.6 wa InaiLevel E kara Hajimeru Netoge Seikatsu1000-nen Nemutta Maou ga Level 1 kara Yarinaosu1000-nen no Mahoutsukai to 7-nin no Deshi1000-nen Mae no Guild ni Tensei shita Ore1000-nen no Yakusoku wo 3-gatsu ni Hatasu2001-nen ni Netoge no Yome ga Isekai kara Kita2001-nen no Gakuen de Kimi to Deatta2001-nen no Mahou Shoten to 86-banme no Kyaku2001-nen kara Hajimaru Slow LifeDai 7 Ouji wa 100-nin no Mahoutsukai wo ErabuDai 7 Maou wa Level E no Heya ni SumuDai 86 Yuusha no Retry LifeDai 100 Shiken no Akuyaku Reijou
# English-style numeric titles91 Days After Becoming the Villainess Butler91 Days Until the Last Sky Witch91 Days in the No.6 District91 Days Before the Guild Closes500 Days Until the Dungeon Closes500 Days with the Level E Roommate500 Days Before Area 88 Falls500 Days of the Seventh PrinceArea 88 and the Last Sky WitchArea 88 Before the 100th DawnArea 88 Academy Has 7 WitchesNo.6 District and the 500 Day PromiseNo.6 Roommate Has 100 SecretsThe Level E Roommate Has 100 SecretsLevel E Academy and the 7 Lost WitchesThe 86th Hero Refuses Season 2The 100th Villainess Starts at Level 1The 7th Prince Runs a 100 Person GuildThe 2001st Login Changed My Isekai LifeA 1000 Year Sleep Before Level 1
# CJK-style numeric titles第7王子与100人的魔法公会第7魔王今天也想过慢生活第7教室的86号勇者第7次转生后遇到100人的同班同学100人的异世界公会与第7位新人100位魔法师和第86号勇者100人的地下城直播间100位青梅竹马的告白战争3月的魔法公会与第7位新人3月醒来的1000年魔王3月与91天的约定12月的第7王子12月的100人勇者考试12月的86号教室91天后的恶役千金管家91天的异世界打工日记500天后的地下城关闭500天与第7位魔法师86号勇者不相信第二季86号教室的转学生88区的天空魔女88区来的第7位骑士6号房间的100个秘密E级教室的第7位魔王1000年后醒来的第86号勇者1000年的魔法书与第7个约定2001年的异世界网游新娘2001年的第7次登录
# Title-owned season-like tokens that must remain TITLE_*S01 no Rakuen 86S02 no Mahoutsukai to 7-nin no DeshiSeason 03 Chronicle 91Season 2 no Yuusha wa 100-nin IruPart 2 no No.6Phase 01 no Level EEpisode 0 no 1000-nen MaouFile S01 91 Days第2季不是续篇而是番名第01话开始前的1000年123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154# Path wrapper seeds for schema_v2_synthetic_augment.# Format: kind|template. Plain lines are treated as series for backward compatibility.# {title} is labeled PATH_TITLE_*, {filename} projects leaf labels, {season_dir} is label-classified per segment.
# TV / episodic series paths: season-like dirs may become PATH_SEASON.series|/mnt/media/anime/{title}/Season 01/{filename}series|/mnt/media/anime/{title}/Season 1/{filename}series|/mnt/media/anime/{title}/Season 02/{filename}series|/mnt/media/anime/{title}/Season 2/{filename}series|/mnt/media/anime/{title}/S01/{filename}series|/mnt/media/anime/{title}/S02/{filename}series|/mnt/media/anime/{title}/01/{filename}series|/mnt/media/anime/{title}/02/{filename}series|/mnt/media/anime/{title}/第1季/{filename}series|/mnt/media/anime/{title}/第2季/{filename}series|Anime/{title}/Season 01/{filename}series|Anime/{title}/Season 1/{filename}series|Anime/{title}/Season 02/{filename}series|Anime/{title}/Season 2/{filename}series|Anime/{title}/S01/{filename}series|Anime/{title}/S02/{filename}series|Anime/{title}/01/{filename}series|Anime/{title}/02/{filename}series|Anime/{title}/第1季/{filename}series|Anime/{title}/第2季/{filename}series|Bangumi/{title}/Season 01/{filename}series|Bangumi/{title}/Season 1/{filename}series|Bangumi/{title}/Season 02/{filename}series|Bangumi/{title}/Season 2/{filename}series|Bangumi/{title}/S01/{filename}series|Bangumi/{title}/S02/{filename}series|Bangumi/{title}/01/{filename}series|Bangumi/{title}/02/{filename}series|Bangumi/{title}/第1季/{filename}series|Bangumi/{title}/第2季/{filename}series|Library/Anime/{title}/Season 01/{filename}series|Library/Anime/{title}/Season 02/{filename}series|Library/Anime/{title}/S01/{filename}series|Library/Anime/{title}/S02/{filename}series|Downloads/BDRip/{title}/Season 01/{filename}series|Downloads/BDRip/{title}/Season 02/{filename}series|Downloads/BDRip/{title}/S01/{filename}series|Downloads/BDRip/{title}/S02/{filename}series|TV/{title}/Season 01/{filename}series|TV/{title}/Season 02/{filename}series|TV/{title}/S01/{filename}series|TV/{title}/S02/{filename}series|D:/Library/Anime/{title}/Season 01/{filename}series|D:/Library/Anime/{title}/Season 02/{filename}series|D:/Library/Anime/{title}/S01/{filename}series|D:/Library/Anime/{title}/S02/{filename}series|E:/Downloads/BDRip/{title}/Season 01/{filename}series|E:/Downloads/BDRip/{title}/Season 02/{filename}series|E:/Downloads/BDRip/{title}/S01/{filename}series|E:/Downloads/BDRip/{title}/S02/{filename}series|Z:/Bangumi/{title}/Season 01/{filename}series|Z:/Bangumi/{title}/Season 02/{filename}series|Z:/Bangumi/{title}/S01/{filename}series|Z:/Bangumi/{title}/S02/{filename}series|Bangumi/{title}/{season_dir}/{filename}series|Library/Anime/{title}/{season_dir}/{filename}series|__mnt__/x7Q9/anime/{title}/Season 01/{filename}series|_tmp/[incomplete]/ANM_0007/{title}/S01/{filename}series|rclone_cache/a9/f3/{title}/Season 02/{filename}series|Media/@@watching/0xA1B2/{title}/S02/{filename}series|Downloads/_aria2/!done/{title}/Season 01/{filename}series|[NAS-01]/#anime#/queue_42/{title}/S01/{filename}series|zz_unsorted/2024-raws/{title}/Season 01/{filename}series|.staging/.uuid-9f3a/{title}/01/{filename}series|xXx/BDMV_TMP/anime_{title}/Season 01/{filename}series|__LIB__/A_N_I_M_E/{title}/第2季/{filename}
# Theatrical / movie paths: no TV season dirs here.movie|Movies/{title}/{filename}movie|Movie/{title}/{filename}movie|Films/{title}/{filename}movie|Anime Movies/{title}/{filename}movie|Gekijouban/{title}/{filename}movie|劇場版/{title}/{filename}movie|BDMovie/{title}/{filename}movie|Library/Anime Movies/{title}/{filename}movie|Library/Anime/{title}/Movie/{filename}movie|Library/Anime/{title}/Gekijouban/{filename}movie|Downloads/BDRip/Movie/{title}/{filename}movie|Downloads/BDRip/Gekijouban/{title}/{filename}movie|/mnt/media/anime_movies/{title}/{filename}movie|/mnt/media/anime/{title}/Movie/{filename}movie|/mnt/media/anime/{title}/Gekijouban/{filename}movie|D:/Library/Anime Movies/{title}/{filename}movie|E:/Downloads/BDRip/Movie/{title}/{filename}movie|__mnt__/mv_0x88/{title}/{filename}movie|_tmp/[movie-drop]/A1B2C3/{title}/{filename}movie|rclone_cache/movie/f9/{title}/{filename}movie|Media/@@movies/seed_007/{title}/{filename}movie|Downloads/_aria2/!movie_done/{title}/{filename}movie|[NAS-02]/#gekijouban#/queue_88/{title}/{filename}movie|zz_unsorted/movie-raws/{title}/{filename}movie|.staging/.uuid-mv91/{title}/{filename}
# Specials / extras paths: numbered specials stay SPECIAL in the filename leaf.special|SPs/{title}/{filename}special|SPs/{title}/Specials/{filename}special|Extras/{title}/{filename}special|Extras/{title}/Specials/{filename}special|OVA/{title}/{filename}special|OAD/{title}/{filename}special|NCOP/{title}/{filename}special|NCED/{title}/{filename}special|PV/{title}/{filename}special|CM/{title}/{filename}special|Trailer/{title}/{filename}special|Menu/{title}/{filename}special|/mnt/media/anime/{title}/SPs/{filename}special|/mnt/media/anime/{title}/Extras/{filename}special|/mnt/media/anime/{title}/OVA/{filename}special|/mnt/media/anime/{title}/OAD/{filename}special|Library/Anime/{title}/SPs/{filename}special|Library/Anime/{title}/Extras/{filename}special|Downloads/BDRip/{title}/Extras/{filename}special|__mnt__/sp_0x07/{title}/Extras/{filename}special|_tmp/[extras-drop]/SPCACHE/{title}/{filename}special|rclone_cache/special/e1/{title}/SPs/{filename}special|Media/@@extras/seed_013/{title}/{filename}special|Downloads/_aria2/!special_done/{title}/Extras/{filename}special|[NAS-03]/#specials#/queue_12/{title}/{filename}special|zz_unsorted/menu-pv-cm/{title}/{filename}special|.staging/.uuid-sp02/{title}/SPs/{filename}
# Hard-negative/confuser paths: these dirs are TAG, not PATH_SEASON.confuser|Bangumi/{title}/Gekijouban/{filename}confuser|Bangumi/{title}/Movie/{filename}confuser|Bangumi/{title}/2004/{filename}confuser|Bangumi/{title}/TV/{filename}confuser|Library/Anime/{title}/TV/{filename}confuser|Library/Anime/{title}/Gekijouban/{filename}confuser|Library/Anime/{title}/Movie/{filename}confuser|Library/Anime/{title}/2004/{filename}confuser|Downloads/BDRip/{title}/TV/{filename}confuser|Downloads/BDRip/{title}/Gekijouban/{filename}confuser|Downloads/BDRip/{title}/Movie/{filename}confuser|Downloads/BDRip/{title}/2004/{filename}confuser|TV/{title}/{filename}confuser|2004/{title}/{filename}confuser|Movie/{title}/2004/{filename}confuser|Gekijouban/{title}/2004/{filename}confuser|Library/Anime/{title}/Extras/2004/{filename}confuser|__mnt__/noise_2004/{title}/TV/{filename}confuser|_tmp/[confuse]/Gekijouban/{title}/2004/{filename}confuser|rclone_cache/tv_or_movie/88/{title}/Movie/{filename}confuser|Media/@@ambiguous/seed_2004/{title}/TV/{filename}confuser|Downloads/_aria2/!misc_done/{title}/2004/{filename}confuser|[NAS-04]/#confuser#/queue_tv/{title}/Gekijouban/{filename}confuser|zz_unsorted/TV-Movie-2004/{title}/TV/{filename}confuser|.staging/.uuid-cf04/{title}/2004/{filename}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664# This file is automatically @generated by Cargo.# It is not intended for manual editing.version = 4
[[package]]name = "aho-corasick"version = "1.1.4"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"dependencies = [ "memchr",]
[[package]]name = "anstream"version = "1.0.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", "is_terminal_polyfill", "utf8parse",]
[[package]]name = "anstyle"version = "1.0.14"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
[[package]]name = "anstyle-parse"version = "1.0.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"dependencies = [ "utf8parse",]
[[package]]name = "anstyle-query"version = "1.1.5"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"dependencies = [ "windows-sys",]
[[package]]name = "anstyle-wincon"version = "3.0.11"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"dependencies = [ "anstyle", "once_cell_polyfill", "windows-sys",]
[[package]]name = "anyhow"version = "1.0.102"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"
[[package]]name = "bitflags"version = "2.11.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3"
[[package]]name = "cfg-if"version = "1.0.4"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]name = "clap"version = "4.6.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51"dependencies = [ "clap_builder", "clap_derive",]
[[package]]name = "clap_builder"version = "4.6.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f"dependencies = [ "anstream", "anstyle", "clap_lex", "strsim",]
[[package]]name = "clap_derive"version = "4.6.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "f2ce8604710f6733aa641a2b3731eaa1e8b3d9973d5e3565da11800813f997a9"dependencies = [ "heck", "proc-macro2", "quote", "syn",]
[[package]]name = "clap_lex"version = "1.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
[[package]]name = "colorchoice"version = "1.0.5"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
[[package]]name = "crossbeam-deque"version = "0.8.6"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51"dependencies = [ "crossbeam-epoch", "crossbeam-utils",]
[[package]]name = "crossbeam-epoch"version = "0.9.18"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"dependencies = [ "crossbeam-utils",]
[[package]]name = "crossbeam-utils"version = "0.8.21"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
[[package]]name = "either"version = "1.16.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e"
[[package]]name = "equivalent"version = "1.0.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]]name = "errno"version = "0.3.14"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"dependencies = [ "libc", "windows-sys",]
[[package]]name = "fastrand"version = "2.4.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6"
[[package]]name = "foldhash"version = "0.1.5"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]]name = "getrandom"version = "0.4.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555"dependencies = [ "cfg-if", "libc", "r-efi", "wasip2", "wasip3",]
[[package]]name = "hashbrown"version = "0.15.5"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"dependencies = [ "foldhash",]
[[package]]name = "hashbrown"version = "0.17.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
[[package]]name = "heck"version = "0.5.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]]name = "id-arena"version = "2.3.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"
[[package]]name = "indexmap"version = "2.14.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"dependencies = [ "equivalent", "hashbrown 0.17.1", "serde", "serde_core",]
[[package]]name = "is_terminal_polyfill"version = "1.70.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]]name = "itoa"version = "1.0.18"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
[[package]]name = "leb128fmt"version = "0.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
[[package]]name = "libc"version = "0.2.186"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
[[package]]name = "linux-raw-sys"version = "0.12.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
[[package]]name = "log"version = "0.4.30"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "616ec5685824bcc94416c6d4a7a446eea774a31efd7062c8480ba6fd06d7a6e5"
[[package]]name = "memchr"version = "2.8.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8"
[[package]]name = "once_cell"version = "1.21.4"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
[[package]]name = "once_cell_polyfill"version = "1.70.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]name = "prettyplease"version = "0.2.37"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"dependencies = [ "proc-macro2", "syn",]
[[package]]name = "proc-macro2"version = "1.0.106"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"dependencies = [ "unicode-ident",]
[[package]]name = "quote"version = "1.0.45"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"dependencies = [ "proc-macro2",]
[[package]]name = "r-efi"version = "6.0.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
[[package]]name = "rayon"version = "1.12.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d"dependencies = [ "either", "rayon-core",]
[[package]]name = "rayon-core"version = "1.13.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"dependencies = [ "crossbeam-deque", "crossbeam-utils",]
[[package]]name = "regex"version = "1.12.3"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "e10754a14b9137dd7b1e3e5b0493cc9171fdd105e0ab477f51b72e7f3ac0e276"dependencies = [ "aho-corasick", "memchr", "regex-automata", "regex-syntax",]
[[package]]name = "regex-automata"version = "0.4.14"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f"dependencies = [ "aho-corasick", "memchr", "regex-syntax",]
[[package]]name = "regex-syntax"version = "0.8.10"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a"
[[package]]name = "rustix"version = "1.1.4"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190"dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", "windows-sys",]
[[package]]name = "schema_v2_synthetic_augment"version = "0.1.0"dependencies = [ "anyhow", "clap", "rayon", "regex", "serde", "serde_json", "tempfile",]
[[package]]name = "semver"version = "1.0.28"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"
[[package]]name = "serde"version = "1.0.228"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"dependencies = [ "serde_core", "serde_derive",]
[[package]]name = "serde_core"version = "1.0.228"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"dependencies = [ "serde_derive",]
[[package]]name = "serde_derive"version = "1.0.228"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"dependencies = [ "proc-macro2", "quote", "syn",]
[[package]]name = "serde_json"version = "1.0.150"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9"dependencies = [ "itoa", "memchr", "serde", "serde_core", "zmij",]
[[package]]name = "strsim"version = "0.11.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]name = "syn"version = "2.0.117"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"dependencies = [ "proc-macro2", "quote", "unicode-ident",]
[[package]]name = "tempfile"version = "3.27.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"dependencies = [ "fastrand", "getrandom", "once_cell", "rustix", "windows-sys",]
[[package]]name = "unicode-ident"version = "1.0.24"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
[[package]]name = "unicode-xid"version = "0.2.6"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
[[package]]name = "utf8parse"version = "0.2.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]name = "wasip2"version = "1.0.3+wasi-0.2.9"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6"dependencies = [ "wit-bindgen 0.57.1",]
[[package]]name = "wasip3"version = "0.4.0+wasi-0.3.0-rc-2026-01-06"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5"dependencies = [ "wit-bindgen 0.51.0",]
[[package]]name = "wasm-encoder"version = "0.244.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319"dependencies = [ "leb128fmt", "wasmparser",]
[[package]]name = "wasm-metadata"version = "0.244.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909"dependencies = [ "anyhow", "indexmap", "wasm-encoder", "wasmparser",]
[[package]]name = "wasmparser"version = "0.244.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe"dependencies = [ "bitflags", "hashbrown 0.15.5", "indexmap", "semver",]
[[package]]name = "windows-link"version = "0.2.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]name = "windows-sys"version = "0.61.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"dependencies = [ "windows-link",]
[[package]]name = "wit-bindgen"version = "0.51.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"dependencies = [ "wit-bindgen-rust-macro",]
[[package]]name = "wit-bindgen"version = "0.57.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e"
[[package]]name = "wit-bindgen-core"version = "0.51.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc"dependencies = [ "anyhow", "heck", "wit-parser",]
[[package]]name = "wit-bindgen-rust"version = "0.51.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21"dependencies = [ "anyhow", "heck", "indexmap", "prettyplease", "syn", "wasm-metadata", "wit-bindgen-core", "wit-component",]
[[package]]name = "wit-bindgen-rust-macro"version = "0.51.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a"dependencies = [ "anyhow", "prettyplease", "proc-macro2", "quote", "syn", "wit-bindgen-core", "wit-bindgen-rust",]
[[package]]name = "wit-component"version = "0.244.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2"dependencies = [ "anyhow", "bitflags", "indexmap", "log", "serde", "serde_derive", "serde_json", "wasm-encoder", "wasm-metadata", "wasmparser", "wit-parser",]
[[package]]name = "wit-parser"version = "0.244.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736"dependencies = [ "anyhow", "id-arena", "indexmap", "log", "semver", "serde", "serde_derive", "serde_json", "unicode-xid", "wasmparser",]
[[package]]name = "zmij"version = "1.0.21"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"123456789101112131415[package]name = "schema_v2_synthetic_augment"version = "0.1.0"edition = "2021"
[dependencies]anyhow = "1"clap = { version = "4", features = ["derive"] }rayon = "1"regex = "1"serde = { version = "1", features = ["derive"] }serde_json = "1"
[dev-dependencies]tempfile = "3"123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151# schema_v2_synthetic_augment
Independent schema v2 synthetic augmentation generator for numeric-title andpath-context samples. It does not rewrite DMHY source records or modify thetemplate application pipeline.
```powershellcargo run --release --manifest-path tools\schema_v2_synthetic_augment\Cargo.toml --bin schema_v2_synthetic_augment -- ` --recipes reports\dmhy_template_recipes.full_top5000.seed.jsonl ` --label-schema-file label_schema.json ` --numeric-title-seeds data\synthetic_numeric_titles.txt ` --path-prefix-seeds data\synthetic_path_prefixes.txt ` --limit-templates 3000 ` --output data\schema_v2_synthetic_aug.jsonl ` --manifest-output data\schema_v2_synthetic_aug.manifest.json```
The output is char-tokenized JSONL (`tokens == list(filename)`) with schema v2labels and `tokenizer_variant: "char"`.
Validate a generated JSONL/manifest pair with the Rust validator:
```powershellcargo run --release --manifest-path tools\schema_v2_synthetic_augment\Cargo.toml --bin validate_synthetic_aug_jsonl -- ` --input data\schema_v2_synthetic_aug.jsonl ` --manifest data\schema_v2_synthetic_aug.manifest.json```
Smoke validation example:
```powershellcargo run --release --manifest-path tools\schema_v2_synthetic_augment\Cargo.toml --bin validate_synthetic_aug_jsonl -- ` --input reports\schema_v2_synthetic_aug.smoke.jsonl ` --manifest reports\schema_v2_synthetic_aug.smoke.manifest.json```
Path seeds are typed: plain or `series|...` entries generate `path_series`rows; `movie|...` / `film|...` / `theatrical|...` entries generate`path_movie` rows; `special|...` entries generate `path_special` rows; and`confuser|...` entries generate `path_confuser` rows. The manifest reports eachcount separately so training mixtures can control these distributions and avoidmixing TV-series and movie/special path priors.
## Plan refinements before scaling
### Separate TV-series and movie/special path generation
Do not treat TV anime and theatrical/movie releases as interchangeable whenwrapping filenames in synthetic paths. A TV-style filename wrapped in a moviefolder, or a movie/special-style filename wrapped in `Season 01` / `S01` / `第2季`folders, creates noisy path labels and can teach the parser the wrong prior.
Before expanding beyond the small validation set, split path generation by mediakind:
- `series` / TV rows: - may use season directories such as `Season 01`, `Season 1`, `S01`, `01`, `第1季`, `第2季`; - may emit `PATH_SEASON` only for those directory-level season components; - should be paired with ordinary episodic base filenames.- `movie` / theatrical rows: - should use movie-appropriate directories such as `Movie`, `Movies`, `Gekijouban`, `劇場版`, `Films`, `BDMovie`, or a direct title folder; - must not synthesize TV season directories unless the seed explicitly models a collection folder where the season-like component is a `TAG`, not `PATH_SEASON`; - should be paired with movie/special base filenames, not ordinary TV episode templates.- `special` rows: - should cover `SPs`, `Specials`, `Extras`, `OVA`, `OAD`, `NCOP`, `NCED`, `PV`, `CM`, `Trailer`, `Menu`; - numbered specials keep their number inside `SPECIAL`, not `EPISODE`.- `confuser` rows: - keep hard negatives such as `Gekijouban`, `Movie`, `2004`, and `TV` as `TAG` when they are non-season directories; - four-digit year directories remain `TAG`, never `PATH_SEASON`.- noisy library/cache/download prefixes: - include a small controlled set of random-looking or operational directories such as `_tmp`, `.staging`, `rclone_cache`, `@@watching`, `0xA1B2`, `[NAS-01]`, `queue_42`, and `!done`; - these segments should remain `O` unless they are an explicit movie/special/ confuser tag segment; - the goal is to teach slash/path robustness without making the model overfit to clean media-library roots only.
Implemented generator/manifest requirements for this split:
- base filename media classifier: `series_episode`, `movie`, `special`, `unknown`;- path seed kinds: `series|...`, `movie|...`, `special|...`, `confuser|...`;- cross-kind combinations are rejected by default: - `movie` base + `series` path = drop; - `series_episode` base + `movie` path = drop; - `confuser` rows remain explicit hard negatives and may wrap any base kind;- manifest stats include `path_movie_rows`, `path_confuser_rows`, `dropped_media_kind_mismatch`, and per-kind seed counts.
### Improve numeric-title seed quality
The numeric title list should not look like a small set of mechanical templateswith only the number swapped. Keep the bucket coverage from the original plan,but make the names feel closer to anime, light-novel, and web-novel titles. Theseeds still do not need to be real works; they need structural diversity and aclear label intent: every number inside the title remains part of `TITLE_*`.
Seed curation guidelines:
- Mix short canonical numeric titles with long light-novel / web-novel style titles.- Include Japanese romanization, English, and CJK-flavored forms where useful, but keep each seed internally style-consistent. Avoid unnatural mixed-language constructions such as romanized Japanese titles with a stray Chinese `年` year suffix, or English phrases glued to Japanese grammar.- Vary separators and numeric forms: `7-nin`, `100-nin`, `3-gatsu`, `12-gatsu`, `91 Days`, `No.6`, `Area 88`, `86`, `Level E`, `2.43`, `22/7`, `Dai 7`, `1000-nen`, `2001-nen`, `第7`, `1000年`, `2001年`.- Add long-title patterns, but keep the whole seed in one coherent naming style: - romanized Japanese / light-novel style: - `7-nin no Maou to Hazure Skill no Slow Life` - `100-nin no Classmate ni Kokuhaku Sareta Ore` - `3-gatsu no Guild de 12-kai Me no Tensei` - `No.6 Chiku no Saigo no Mahoutsukai` - `86-banme no Yuusha wa Season 2 wo Shinjinai` - `2001-nen ni Netoge no Yome ga Isekai kara Kita` - English-style titles: - `91 Days After Becoming the Villainess Butler` - `Area 88 and the Last Sky Witch` - `The Level E Roommate Has 100 Secrets` - `500 Days Until the Dungeon Closes` - CJK-style titles: - `第7王子与100人的魔法公会` - `2001年的异世界网游新娘` - `1000年后醒来的第86号勇者`- Explicitly include misleading but title-owned season-like tokens, for example `S01 no Rakuen 86`, `Season 03 Chronicle 91`, `Part 2 no No.6`, and `Episode 0 no 1000-nen Maou`; these must remain `TITLE_*` when used as the title seed.- Avoid overusing obvious placeholders like `Chronicle`, `Report`, `Club`, and `Patrol`; replace some with more natural genre terms such as `Maou`, `Yuusha`, `Akuyaku Reijou`, `Guild`, `Dungeon`, `Mahoutsukai`, `Tensei`, `Slow Life`, `Netoge`, `Haishin`, `Kouhai`, `Senpai`, `Kyoushitsu`, and `Gakuen`.
Acceptance checks for seed quality:
- each required numeric bucket has multiple non-near-duplicate examples;- long-title seeds do not collapse into the same phrase skeleton;- title-owned numeric and season-like tokens are verified to stay contiguous `TITLE_*` in generated rows;- fixed cases such as `vcb_numeric_title_nced` improve without introducing new false `EPISODE` / `SEASON` spans inside titles.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251use anyhow::{bail, Context, Result};use clap::Parser;use serde_json::{Map, Value};use std::collections::BTreeSet;use std::fs::File;use std::io::{BufRead, BufReader};use std::path::PathBuf;
const VALID_TOKENIZER_VARIANTS: &[&str] = &["char", "regex"];const REQUIRED_MANIFEST_STATS: &[&str] = &[ "generated_rows", "dropped_conflicting_templates", "deduped_rows", "numeric_title_rows", "path_rows",];const REQUIRED_ROW_FIELDS: &[&str] = &[ "tokens", "labels", "tokenizer_variant", "source", "synthetic_kind",];const NEW_PATH_BUCKET_KEYS: &[&str] = &[ "path_series_rows", "path_movie_rows", "path_special_rows", "path_confuser_rows",];
#[derive(Parser, Debug)]#[command(about = "Validate schema v2 synthetic augmentation JSONL and manifest")]struct Args { #[arg(long)] input: PathBuf,
#[arg(long)] manifest: PathBuf,}
fn main() -> Result<()> { let args = Args::parse();
let rows = validate_jsonl(&args.input) .with_context(|| format!("failed to validate {}", args.input.display()))?; validate_manifest(&args.manifest, rows) .with_context(|| format!("failed to validate {}", args.manifest.display()))?;
Ok(())}
fn validate_jsonl(path: &PathBuf) -> Result<usize> { let file = File::open(path).with_context(|| format!("failed to open {}", path.display()))?; let reader = BufReader::new(file); let mut rows = 0usize;
for (line_index, line_result) in reader.lines().enumerate() { let line_no = line_index + 1; let line = line_result.with_context(|| format!("line {line_no}: failed to read line"))?; if line.trim().is_empty() { bail!("line {line_no}: blank lines are not valid JSONL rows"); } let row: Value = serde_json::from_str(&line).with_context(|| format!("line {line_no}: invalid JSON"))?; validate_row(&row, line_no)?; rows = line_no; }
Ok(rows)}
fn validate_row(row: &Value, line_no: usize) -> Result<()> { let object = row .as_object() .ok_or_else(|| anyhow::anyhow!("line {line_no}: row must be a JSON object"))?; validate_row_metadata(object, line_no)?;
let tokens = object .get("tokens") .and_then(Value::as_array) .ok_or_else(|| anyhow::anyhow!("line {line_no}: tokens and labels must be lists"))?; let labels = object .get("labels") .and_then(Value::as_array) .ok_or_else(|| anyhow::anyhow!("line {line_no}: tokens and labels must be lists"))?;
if tokens.len() != labels.len() { bail!("line {line_no}: tokens/labels length mismatch"); }
let tokenizer_variant = object .get("tokenizer_variant") .and_then(Value::as_str) .expect("tokenizer_variant already validated as a string"); if tokenizer_variant == "char" { for (index, token) in tokens.iter().enumerate() { let Some(token) = token.as_str() else { bail!("line {line_no}: char tokenizer token at {index} must be one character"); }; if token.chars().count() != 1 { bail!("line {line_no}: char tokenizer token at {index} must be one character"); } } }
let mut prev_entity: Option<String> = None; let mut has_title = false; for (index, label) in labels.iter().enumerate() { if label == "O" { prev_entity = None; continue; } let (prefix, entity) = split_bio_label(label, index, line_no)?; if prefix == "I" && prev_entity.as_deref() != Some(entity) { bail!( "line {line_no}: orphan I-tag at {index}: {}", label_for_error(label) ); } prev_entity = Some(entity.to_string()); if entity.contains("TITLE") { has_title = true; } }
if !has_title { bail!("line {line_no}: missing title span"); }
Ok(())}
fn validate_row_metadata(row: &Map<String, Value>, line_no: usize) -> Result<()> { let keys: BTreeSet<&str> = row.keys().map(String::as_str).collect(); let missing: Vec<&str> = REQUIRED_ROW_FIELDS .iter() .copied() .filter(|field| !keys.contains(field)) .collect(); if !missing.is_empty() { bail!("line {line_no}: missing required fields: {missing:?}"); }
let tokenizer_variant = require_non_empty_string(row, "tokenizer_variant", line_no)?; if !VALID_TOKENIZER_VARIANTS.contains(&tokenizer_variant) { bail!("line {line_no}: unsupported tokenizer_variant {tokenizer_variant:?}"); } require_non_empty_string(row, "source", line_no)?; require_non_empty_string(row, "synthetic_kind", line_no)?;
Ok(())}
fn require_non_empty_string<'a>( row: &'a Map<String, Value>, field: &str, line_no: usize,) -> Result<&'a str> { let value = row .get(field) .and_then(Value::as_str) .ok_or_else(|| anyhow::anyhow!("line {line_no}: {field} must be a non-empty string"))?; if value.trim().is_empty() { bail!("line {line_no}: {field} must be a non-empty string"); } Ok(value)}
fn split_bio_label(label: &Value, index: usize, line_no: usize) -> Result<(&str, &str)> { let label = label .as_str() .ok_or_else(|| anyhow::anyhow!("line {line_no}: non-string label at {index}: {label:?}"))?; let Some((prefix, entity)) = label.split_once('-') else { bail!("line {line_no}: malformed BIO label at {index}: {label:?}"); }; if prefix != "B" && prefix != "I" { bail!("line {line_no}: invalid BIO prefix at {index}: {label}"); } if entity.is_empty() { bail!("line {line_no}: empty BIO entity at {index}: {label}"); } Ok((prefix, entity))}
fn label_for_error(label: &Value) -> String { match label.as_str() { Some(label) => label.to_string(), None => format!("{label:?}"), }}
fn validate_manifest(path: &PathBuf, rows: usize) -> Result<()> { let manifest_text = std::fs::read_to_string(path) .with_context(|| format!("failed to read {}", path.display()))?; let manifest: Value = serde_json::from_str(&manifest_text).context("manifest is invalid JSON")?; let manifest = manifest .as_object() .ok_or_else(|| anyhow::anyhow!("manifest must be a JSON object"))?;
let keys: BTreeSet<&str> = manifest.keys().map(String::as_str).collect(); let missing: Vec<&str> = REQUIRED_MANIFEST_STATS .iter() .copied() .filter(|field| !keys.contains(field)) .collect(); if !missing.is_empty() { bail!("manifest missing keys: {missing:?}"); }
for key in REQUIRED_MANIFEST_STATS { manifest_non_negative_integer(manifest, key)?; }
let has_all_new_path_buckets = NEW_PATH_BUCKET_KEYS.iter().all(|key| keys.contains(key)); if has_all_new_path_buckets { let mut path_bucket_sum = 0u64; for key in NEW_PATH_BUCKET_KEYS { path_bucket_sum += manifest_non_negative_integer(manifest, key)?; } if path_bucket_sum != manifest_non_negative_integer(manifest, "path_rows")? { bail!( "manifest path_series_rows + path_movie_rows + path_special_rows + path_confuser_rows must equal path_rows" ); } } else if keys.contains("path_series_rows") || keys.contains("path_special_rows") { let path_series_rows = manifest_non_negative_integer(manifest, "path_series_rows")?; let path_special_rows = manifest_non_negative_integer(manifest, "path_special_rows")?; if path_series_rows + path_special_rows != manifest_non_negative_integer(manifest, "path_rows")? { bail!("manifest path_series_rows + path_special_rows must equal path_rows"); } }
let generated_rows = manifest_non_negative_integer(manifest, "generated_rows")?; if generated_rows != rows as u64 { bail!("manifest generated_rows {generated_rows} != jsonl rows {rows}"); }
Ok(())}
fn manifest_non_negative_integer(manifest: &Map<String, Value>, key: &str) -> Result<u64> { let value = manifest .get(key) .ok_or_else(|| anyhow::anyhow!("manifest {key} must be a non-negative integer"))?; value .as_u64() .ok_or_else(|| anyhow::anyhow!("manifest {key} must be a non-negative integer"))}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573use anyhow::{bail, Context, Result};use clap::Parser;use rayon::ThreadPoolBuilder;use regex::Regex;use serde::{Deserialize, Serialize};#[cfg(test)]use serde_json::Value;use std::collections::HashSet;use std::fs::{self, File};use std::io::{BufRead, BufReader, BufWriter, Write};use std::path::{Path, PathBuf};use std::sync::OnceLock;
const DEFAULT_MAX_ROWS: usize = 50_000;const NUMERIC_RATIO_PERCENT: usize = 60;const DEFAULT_PATH_SPECIAL_RATIO_PERCENT: usize = 25;
#[derive(Parser, Debug)]#[command(about = "Generate schema v2 numeric-title and path synthetic augmentation JSONL")]struct Args { #[arg( long, default_value = "reports/dmhy_template_recipes.full_top5000.seed.jsonl" )] recipes: PathBuf,
#[arg(long, default_value = "label_schema.json")] label_schema_file: PathBuf,
#[arg(long, default_value = "data/synthetic_numeric_titles.txt")] numeric_title_seeds: PathBuf,
#[arg(long, default_value = "data/synthetic_path_prefixes.txt")] path_prefix_seeds: PathBuf,
#[arg(long, default_value_t = 3000)] limit_templates: usize,
#[arg(long, default_value_t = DEFAULT_MAX_ROWS)] max_rows: usize,
#[arg(long, default_value_t = DEFAULT_PATH_SPECIAL_RATIO_PERCENT)] path_special_ratio_percent: usize,
#[arg(long, default_value = "data/schema_v2_synthetic_aug.jsonl")] output: PathBuf,
#[arg(long, default_value = "data/schema_v2_synthetic_aug.manifest.json")] manifest_output: PathBuf,
#[arg(long, default_value_t = 0)] threads: usize,}
#[derive(Debug, Deserialize)]struct LabelSchema { labels: Vec<String>,}
#[derive(Debug, Clone, Deserialize)]struct Recipe { template_id: String, template: String, roles: Vec<String>, confidence: Option<String>, #[serde(rename = "count")] _count: Option<u64>,}
#[derive(Debug, Clone, Serialize)]struct Record { filename: String, tokens: Vec<String>, labels: Vec<String>, source: String, template_id: String, template: String, synthetic_kind: String, tokenizer_variant: String,}
#[derive(Debug, Default, Serialize)]struct Manifest { generated_rows: usize, dropped_conflicting_templates: usize, deduped_rows: usize, numeric_title_rows: usize, path_rows: usize, path_series_rows: usize, path_movie_rows: usize, path_special_rows: usize, path_confuser_rows: usize, dropped_media_kind_mismatch: usize, recipes: String, label_schema_file: String, numeric_title_seeds: String, path_prefix_seeds: String, limit_templates: usize, max_rows: usize, templates_loaded: usize, numeric_seed_count: usize, path_seed_count: usize, path_series_seed_count: usize, path_movie_seed_count: usize, path_special_seed_count: usize, path_confuser_seed_count: usize,}
#[derive(Debug, Default)]struct BuildStats { dropped_conflicting_templates: usize, deduped_rows: usize, numeric_title_rows: usize, path_rows: usize, path_series_rows: usize, path_movie_rows: usize, path_special_rows: usize, path_confuser_rows: usize, dropped_media_kind_mismatch: usize,}
#[derive(Debug, Clone, Copy, Eq, PartialEq)]enum PathSeedKind { Series, Movie, Special, Confuser,}
impl PathSeedKind { const ALL: [PathSeedKind; 4] = [ PathSeedKind::Series, PathSeedKind::Movie, PathSeedKind::Special, PathSeedKind::Confuser, ];
fn synthetic_kind(self) -> &'static str { match self { PathSeedKind::Series => "path_series", PathSeedKind::Movie => "path_movie", PathSeedKind::Special => "path_special", PathSeedKind::Confuser => "path_confuser", } }
fn source(self) -> &'static str { match self { PathSeedKind::Series => "schema_v2_synthetic_path_series", PathSeedKind::Movie => "schema_v2_synthetic_path_movie", PathSeedKind::Special => "schema_v2_synthetic_path_special", PathSeedKind::Confuser => "schema_v2_synthetic_path_confuser", } }}
#[derive(Debug, Clone, Copy, Eq, PartialEq)]enum BaseMediaKind { SeriesEpisode, Movie, Special, Unknown,}
#[derive(Debug, Clone)]struct PathSeed { template: String, kind: PathSeedKind,}
#[derive(Debug, Clone, Copy, Eq, PartialEq)]enum Entity { TitleLatin, PathTitleLatin, PathSeason, Season, Episode, Special, Group, Resolution, Source, Tag,}
impl Entity { fn b_label(self) -> &'static str { match self { Entity::TitleLatin => "B-TITLE_LATIN", Entity::PathTitleLatin => "B-PATH_TITLE_LATIN", Entity::PathSeason => "B-PATH_SEASON", Entity::Season => "B-SEASON", Entity::Episode => "B-EPISODE", Entity::Special => "B-SPECIAL", Entity::Group => "B-GROUP", Entity::Resolution => "B-RESOLUTION", Entity::Source => "B-SOURCE", Entity::Tag => "B-TAG", } }
fn i_label(self) -> &'static str { match self { Entity::TitleLatin => "I-TITLE_LATIN", Entity::PathTitleLatin => "I-PATH_TITLE_LATIN", Entity::PathSeason => "I-PATH_SEASON", Entity::Season => "I-SEASON", Entity::Episode => "I-EPISODE", Entity::Special => "I-SPECIAL", Entity::Group => "I-GROUP", Entity::Resolution => "I-RESOLUTION", Entity::Source => "I-SOURCE", Entity::Tag => "I-TAG", } }}
#[derive(Debug, Default, Clone)]struct CharBuilder { filename: String, tokens: Vec<String>, labels: Vec<String>,}
impl CharBuilder { fn append_o(&mut self, text: &str) { self.append(text, None); }
fn append_entity(&mut self, text: &str, entity: Entity) { self.append(text, Some(entity)); }
fn append(&mut self, text: &str, entity: Option<Entity>) { let mut first = true; for ch in text.chars() { self.filename.push(ch); self.tokens.push(ch.to_string()); let label = match entity { None => "O", Some(value) => { if first { value.b_label() } else { value.i_label() } } }; self.labels.push(label.to_string()); first = false; } }
fn into_parts(self) -> (String, Vec<String>, Vec<String>) { (self.filename, self.tokens, self.labels) }}
fn main() -> Result<()> { let args = Args::parse(); if args.max_rows == 0 { bail!("--max-rows must be positive"); } if args.threads > 0 { ThreadPoolBuilder::new() .num_threads(args.threads) .build_global() .context("failed to configure rayon thread pool")?; }
let label_set = load_label_set(&args.label_schema_file)?; let recipes = load_recipes(&args.recipes, args.limit_templates)?; let numeric_titles = load_seed_lines(&args.numeric_title_seeds)?; let path_prefixes = load_path_seed_lines(&args.path_prefix_seeds)?; if numeric_titles.is_empty() { bail!("numeric title seed file is empty"); } if path_prefixes.is_empty() { bail!("path prefix seed file is empty"); }
let mut records = Vec::with_capacity(args.max_rows); let mut seen = HashSet::new(); let mut stats = BuildStats::default(); let numeric_quota = (args.max_rows * NUMERIC_RATIO_PERCENT / 100).max(1); let path_quota = args.max_rows.saturating_sub(numeric_quota).max(1); let special_ratio = args.path_special_ratio_percent.min(100); let mut path_special_quota = path_quota * special_ratio / 100; let mut path_series_quota = path_quota.saturating_sub(path_special_quota); let path_series_seed_count = path_seed_count(&path_prefixes, PathSeedKind::Series); let path_movie_seed_count = path_seed_count(&path_prefixes, PathSeedKind::Movie); let path_special_seed_count = path_seed_count(&path_prefixes, PathSeedKind::Special); let path_confuser_seed_count = path_seed_count(&path_prefixes, PathSeedKind::Confuser); let non_series_kind_count = [ path_movie_seed_count, path_special_seed_count, path_confuser_seed_count, ] .into_iter() .filter(|count| *count > 0) .count(); if path_series_seed_count == 0 { path_series_quota = 0; path_special_quota = path_quota; } else if non_series_kind_count == 0 { path_series_quota = path_quota; path_special_quota = 0; }
for recipe in &recipes { if stats.numeric_title_rows >= numeric_quota { break; } if !recipe.roles.iter().any(|role| role == "TITLE") { stats.dropped_conflicting_templates += 1; continue; } for (seed_idx, title) in numeric_titles.iter().enumerate() { if stats.numeric_title_rows >= numeric_quota { break; } match build_numeric_record(recipe, title, seed_idx) { Some(record) => { push_record(record, &mut records, &mut seen, &mut stats, &label_set)? } None => stats.dropped_conflicting_templates += 1, } } }
let base_files = path_base_records(&records); 'path_kind: for kind in PathSeedKind::ALL { let seed_count = path_seed_count(&path_prefixes, kind); if seed_count == 0 { continue; } let kind_quota = path_kind_quota( kind, path_series_quota, path_special_quota, non_series_kind_count, ); if kind_quota == 0 { continue; } for (base_idx, base) in base_files.iter().enumerate() { for (prefix_idx, prefix) in path_prefixes .iter() .filter(|seed| seed.kind == kind) .enumerate() { if path_kind_rows(&stats, kind) >= kind_quota || stats.path_rows >= path_quota { continue 'path_kind; } let title = path_title_for(prefix_idx + base_idx, &numeric_titles); let season_dir = path_season_dir_for(prefix_idx + base_idx); match build_path_record(&prefix.template, kind, &title, season_dir, base) { Some(record) => { push_record(record, &mut records, &mut seen, &mut stats, &label_set)?; } None => { if !path_seed_compatible_with_base(kind, classify_base_media_kind(base)) { stats.dropped_media_kind_mismatch += 1; } else { stats.dropped_conflicting_templates += 1; } } } } } }
if records.is_empty() { bail!("no synthetic rows were generated"); } if let Some(parent) = args.output.parent() { fs::create_dir_all(parent) .with_context(|| format!("failed to create output directory {}", parent.display()))?; } let output = File::create(&args.output) .with_context(|| format!("failed to create {}", args.output.display()))?; let mut writer = BufWriter::new(output); for record in &records { serde_json::to_writer(&mut writer, record)?; writer.write_all(b"\n")?; }
if let Some(parent) = args.manifest_output.parent() { fs::create_dir_all(parent) .with_context(|| format!("failed to create manifest directory {}", parent.display()))?; } let manifest = Manifest { generated_rows: records.len(), dropped_conflicting_templates: stats.dropped_conflicting_templates, deduped_rows: stats.deduped_rows, numeric_title_rows: stats.numeric_title_rows, path_rows: stats.path_rows, path_series_rows: stats.path_series_rows, path_movie_rows: stats.path_movie_rows, path_special_rows: stats.path_special_rows, path_confuser_rows: stats.path_confuser_rows, dropped_media_kind_mismatch: stats.dropped_media_kind_mismatch, recipes: args.recipes.display().to_string(), label_schema_file: args.label_schema_file.display().to_string(), numeric_title_seeds: args.numeric_title_seeds.display().to_string(), path_prefix_seeds: args.path_prefix_seeds.display().to_string(), limit_templates: args.limit_templates, max_rows: args.max_rows, templates_loaded: recipes.len(), numeric_seed_count: numeric_titles.len(), path_seed_count: path_prefixes.len(), path_series_seed_count, path_movie_seed_count, path_special_seed_count, path_confuser_seed_count, }; fs::write( &args.manifest_output, serde_json::to_string_pretty(&manifest)?, ) .with_context(|| format!("failed to write {}", args.manifest_output.display()))?; println!("{}", serde_json::to_string_pretty(&manifest)?); Ok(())}
fn load_label_set(path: &Path) -> Result<HashSet<String>> { let text = fs::read_to_string(path).with_context(|| format!("failed to read {}", path.display()))?; let schema: LabelSchema = serde_json::from_str(&text).with_context(|| format!("invalid {}", path.display()))?; Ok(schema.labels.into_iter().collect())}
fn load_seed_lines(path: &Path) -> Result<Vec<String>> { let file = File::open(path).with_context(|| format!("failed to open {}", path.display()))?; let reader = BufReader::new(file); let mut lines = Vec::new(); let mut seen = HashSet::new(); for line in reader.lines() { let line = line?; let Some(seed) = parse_seed_line(&line) else { continue; }; if seen.insert(seed.clone()) { lines.push(seed); } } Ok(lines)}
fn load_path_seed_lines(path: &Path) -> Result<Vec<PathSeed>> { let file = File::open(path).with_context(|| format!("failed to open {}", path.display()))?; let reader = BufReader::new(file); let mut lines = Vec::new(); let mut seen = HashSet::new(); for line in reader.lines() { let line = line?; let Some(seed) = parse_path_seed_line(&line) else { continue; }; let key = format!("{}|{}", seed.kind.synthetic_kind(), seed.template); if seen.insert(key) { lines.push(seed); } } Ok(lines)}
fn parse_path_seed_line(line: &str) -> Option<PathSeed> { let mut trimmed = line.trim(); if trimmed.is_empty() { return None; } if let Some(comment_body) = trimmed.strip_prefix('#') { trimmed = comment_body.trim(); if !trimmed.contains('|') { return None; } }
let mut kind = PathSeedKind::Series; if let Some((kind_text, value)) = trimmed.split_once('|') { match kind_text.trim() { "series" | "path" => { kind = PathSeedKind::Series; trimmed = value.trim(); } "movie" | "film" | "theatrical" => { kind = PathSeedKind::Movie; trimmed = value.trim(); } "special" => { kind = PathSeedKind::Special; trimmed = value.trim(); } "confuser" => { kind = PathSeedKind::Confuser; trimmed = value.trim(); } _ => {} } } if trimmed.is_empty() || trimmed.starts_with('#') { None } else { Some(PathSeed { template: trimmed.to_string(), kind, }) }}
fn parse_seed_line(line: &str) -> Option<String> { let mut trimmed = line.trim(); if trimmed.is_empty() { return None; } if let Some(comment_body) = trimmed.strip_prefix('#') { trimmed = comment_body.trim(); if !trimmed.contains('|') { return None; } } if let Some((kind, value)) = trimmed.split_once('|') { let known_kind = matches!( kind.trim(), "series" | "movie" | "film" | "theatrical" | "special" | "confuser" | "path" | "numeric" ); if known_kind { trimmed = value.trim(); } } if trimmed.is_empty() || trimmed.starts_with('#') { None } else { Some(trimmed.to_string()) }}
fn path_seed_count(path_prefixes: &[PathSeed], kind: PathSeedKind) -> usize { path_prefixes .iter() .filter(|seed| seed.kind == kind) .count()}
fn path_kind_quota( kind: PathSeedKind, series_quota: usize, non_series_quota: usize, non_series_kind_count: usize,) -> usize { match kind { PathSeedKind::Series => series_quota, PathSeedKind::Movie | PathSeedKind::Special | PathSeedKind::Confuser => { if non_series_kind_count == 0 { 0 } else { (non_series_quota / non_series_kind_count).max(1) } } }}
fn path_kind_rows(stats: &BuildStats, kind: PathSeedKind) -> usize { match kind { PathSeedKind::Series => stats.path_series_rows, PathSeedKind::Movie => stats.path_movie_rows, PathSeedKind::Special => stats.path_special_rows, PathSeedKind::Confuser => stats.path_confuser_rows, }}
fn load_recipes(path: &Path, limit_templates: usize) -> Result<Vec<Recipe>> { let file = File::open(path).with_context(|| format!("failed to open {}", path.display()))?; let reader = BufReader::new(file); let mut recipes = Vec::new(); for (idx, line) in reader.lines().enumerate() { if recipes.len() >= limit_templates { break; } let line = line.with_context(|| format!("failed reading recipe line {}", idx + 1))?; if line.trim().is_empty() { continue; } let recipe: Recipe = serde_json::from_str(&line) .with_context(|| format!("invalid recipe JSONL line {}", idx + 1))?; if recipe.confidence.as_deref() != Some("high") { continue; } if recipe.template.split_whitespace().count() != recipe.roles.len() { continue; } recipes.push(recipe); } Ok(recipes)}
fn push_record( record: Record, records: &mut Vec<Record>, seen: &mut HashSet<String>, stats: &mut BuildStats, label_set: &HashSet<String>,) -> Result<()> { validate_record_labels(&record, label_set)?; let key = format!("{}\u{1f}{}", record.filename, record.labels.join("\u{1f}")); if !seen.insert(key) { stats.deduped_rows += 1; return Ok(()); } match record.synthetic_kind.as_str() { "numeric_title" => stats.numeric_title_rows += 1, "path_series" => { stats.path_rows += 1; stats.path_series_rows += 1; } "path_movie" => { stats.path_rows += 1; stats.path_movie_rows += 1; } "path_special" => { stats.path_rows += 1; stats.path_special_rows += 1; } "path_confuser" => { stats.path_rows += 1; stats.path_confuser_rows += 1; } other => bail!("unknown synthetic_kind {other}"), } records.push(record); Ok(())}
fn validate_record_labels(record: &Record, label_set: &HashSet<String>) -> Result<()> { if record.tokens.len() != record.labels.len() { bail!("tokens/labels mismatch for {}", record.filename); } if record.tokens != record .filename .chars() .map(|ch| ch.to_string()) .collect::<Vec<_>>() { bail!("tokens are not char-level for {}", record.filename); }
let mut prev_entity: Option<&str> = None; let mut has_title = false; for (idx, label) in record.labels.iter().enumerate() { if !label_set.contains(label) { bail!("label {label} is not present in label schema"); } if label == "O" { prev_entity = None; continue; } let Some((prefix, entity)) = label.split_once('-') else { bail!( "malformed BIO label {label} at {idx} for {}", record.filename ); }; if prefix != "B" && prefix != "I" { bail!( "invalid BIO prefix {prefix} at {idx} for {}", record.filename ); } if entity.is_empty() { bail!("empty BIO entity at {idx} for {}", record.filename); } if prefix == "I" && prev_entity != Some(entity) { bail!("orphan I-tag {label} at {idx} for {}", record.filename); } if entity.contains("TITLE") { has_title = true; } prev_entity = Some(entity); } if !has_title { bail!("missing title span for {}", record.filename); } Ok(())}
fn build_numeric_record(recipe: &Recipe, title: &str, variant: usize) -> Option<Record> { let classes: Vec<&str> = recipe.template.split_whitespace().collect(); if classes.len() != recipe.roles.len() { return None; } let mut builder = CharBuilder::default(); let mut previous_role = ""; for (class_name, role) in classes.iter().zip(recipe.roles.iter()) { let special_number = role == "EPISODE" && previous_role == "SPECIAL"; let role_for_label = if special_number { "SPECIAL" } else { role.as_str() }; append_template_group( &mut builder, class_name, role, role_for_label, title, variant, special_number, )?; if role != "O" { previous_role = role; } } let (filename, tokens, labels) = builder.into_parts(); if has_entity(&labels, "EPISODE") && title_has_episode_label(&filename, &labels, title) { return None; } Some(Record { filename, tokens, labels, source: "schema_v2_synthetic_numeric_title".to_string(), template_id: recipe.template_id.clone(), template: recipe.template.clone(), synthetic_kind: "numeric_title".to_string(), tokenizer_variant: "char".to_string(), })}
fn append_template_group( builder: &mut CharBuilder, class_name: &str, content_role: &str, role: &str, title: &str, variant: usize, special_number: bool,) -> Option<()> { if class_name == "SEP" { builder.append_o(separator_for(variant)); return Some(()); } if class_name == "SXE" { append_sxe(builder); return Some(()); }
let entity = entity_for_role(role, class_name); let content = if special_number { "01".to_string() } else { content_for_role(content_role, class_name, title, variant) }; if class_name.starts_with("BRACKET_") { builder.append_o("["); builder.append(&content, entity); builder.append_o("]"); } else { builder.append(&content, entity); } Some(())}
fn separator_for(variant: usize) -> &'static str { match variant % 5 { 0 => " ", 1 => " - ", 2 => ".", 3 => "_", _ => " ", }}
fn entity_for_role(role: &str, class_name: &str) -> Option<Entity> { match role { "TITLE" => Some(Entity::TitleLatin), "GROUP" => Some(Entity::Group), "SEASON" => Some(Entity::Season), "EPISODE" | "EPISODE_VERSION" | "EPISODE_RANGE" => Some(Entity::Episode), "SPECIAL" | "VOLUME" => Some(Entity::Special), "RESOLUTION" => Some(Entity::Resolution), "SOURCE" | "HASH" => Some(Entity::Source), "TAG" => Some(Entity::Tag), "O" => { if class_name.contains("HASH") { Some(Entity::Source) } else { None } } _ => None, }}
fn content_for_role(role: &str, class_name: &str, title: &str, variant: usize) -> String { match role { "TITLE" => title.to_string(), "GROUP" => group_for(variant).to_string(), "SEASON" => season_for(variant).to_string(), "EPISODE" => episode_for(variant).to_string(), "EPISODE_VERSION" => format!("{}v2", episode_for(variant)), "EPISODE_RANGE" => "01-12".to_string(), "SPECIAL" => special_for(variant).to_string(), "VOLUME" => format!("Vol.{}", (variant % 6) + 1), "RESOLUTION" => resolution_for(variant).to_string(), "SOURCE" => source_for(class_name, variant).to_string(), "HASH" => "A1B2C3D4".to_string(), "TAG" => tag_for(variant).to_string(), _ => neutral_for_class(class_name, variant).to_string(), }}
fn group_for(variant: usize) -> &'static str { const GROUPS: [&str; 8] = [ "DBD-Raws", "VCB-Studio", "A.I.Raws", "Lilith-Raws", "ANi", "Nekomoe", "Baha", "Skytree", ]; GROUPS[variant % GROUPS.len()]}
fn season_for(variant: usize) -> &'static str { const SEASONS: [&str; 6] = ["S2", "Season 2", "S01", "2nd Season", "第2季", "Part 2"]; SEASONS[variant % SEASONS.len()]}
fn episode_for(variant: usize) -> &'static str { const EPISODES: [&str; 8] = ["01", "02", "03", "12", "24", "087", "100", "S01E03"]; EPISODES[variant % EPISODES.len()]}
fn special_for(variant: usize) -> &'static str { const SPECIALS: [&str; 12] = [ "NCED", "NCOP2", "PV", "CM", "Menu", "Trailer", "SP", "SP01", "OVA", "OAD", "OP2", "ED1", ]; SPECIALS[variant % SPECIALS.len()]}
fn resolution_for(variant: usize) -> &'static str { const RESOLUTIONS: [&str; 5] = ["1080p", "720P", "2160p", "1920x1080", "4K"]; RESOLUTIONS[variant % RESOLUTIONS.len()]}
fn source_for(class_name: &str, variant: usize) -> &'static str { if class_name.contains("MEDIA_BLOCK") { return "WEB-DL 1080p AVC AAC"; } const SOURCES: [&str; 10] = [ "WEB-DL", "BDRip", "HEVC", "AAC", "FLAC", "CHS", "JPSC", "NF", "Baha", "x264", ]; SOURCES[variant % SOURCES.len()]}
fn tag_for(variant: usize) -> &'static str { const TAGS: [&str; 6] = ["Gekijouban", "Movie", "TV", "2004", "Extras", "SPs"]; TAGS[variant % TAGS.len()]}
fn neutral_for_class(class_name: &str, variant: usize) -> &'static str { if class_name.contains("RESOLUTION") { resolution_for(variant) } else if class_name.contains("MEDIA") || class_name.contains("LANG") { source_for(class_name, variant) } else if class_name.contains("SPECIAL") { special_for(variant) } else if class_name.contains("EPISODE") { episode_for(variant) } else if class_name.contains("SEASON") { season_for(variant) } else if class_name.contains("HASH") { "A1B2C3D4" } else if class_name.contains("DATE") { "2024" } else { "v2" }}
fn append_sxe(builder: &mut CharBuilder) { builder.append_o("S"); builder.append_entity("01", Entity::Season); builder.append_o("E"); builder.append_entity("03", Entity::Episode);}
fn title_has_episode_label(filename: &str, labels: &[String], title: &str) -> bool { let Some(start) = filename.find(title) else { return false; }; let end = start + title.len(); let char_starts = char_byte_offsets(filename); char_starts .iter() .enumerate() .filter(|(_, byte_idx)| **byte_idx >= start && **byte_idx < end) .any(|(idx, _)| labels[idx].contains("EPISODE") || labels[idx].contains("SEASON"))}
fn char_byte_offsets(text: &str) -> Vec<usize> { text.char_indices().map(|(idx, _)| idx).collect()}
fn has_entity(labels: &[String], entity: &str) -> bool { labels.iter().any(|label| { label .strip_prefix("B-") .is_some_and(|value| value == entity) })}
fn path_base_records(records: &[Record]) -> Vec<Record> { let mut bases = Vec::new(); bases.extend(simple_path_leaf_records()); bases.extend( records .iter() .filter(|record| record.synthetic_kind == "numeric_title") .take(256) .cloned(), ); bases}
fn classify_base_media_kind(record: &Record) -> BaseMediaKind { let has_episode = has_entity(&record.labels, "EPISODE"); let has_special = has_entity(&record.labels, "SPECIAL"); if has_special { return BaseMediaKind::Special; } if has_episode { return BaseMediaKind::SeriesEpisode; } let lower = record.filename.to_ascii_lowercase(); if ["movie", "gekijouban", "the movie", "film", "劇場版"] .iter() .any(|needle| lower.contains(&needle.to_ascii_lowercase())) { return BaseMediaKind::Movie; } BaseMediaKind::Unknown}
fn path_seed_compatible_with_base(kind: PathSeedKind, base_kind: BaseMediaKind) -> bool { match kind { PathSeedKind::Series => base_kind == BaseMediaKind::SeriesEpisode, PathSeedKind::Movie => base_kind == BaseMediaKind::Movie, PathSeedKind::Special => base_kind == BaseMediaKind::Special, PathSeedKind::Confuser => true, }}
fn simple_path_leaf_records() -> Vec<Record> { vec![ char_record_from_spans( "03.mkv", &[(0, 2, Entity::Episode)], "schema_v2_synthetic_path_leaf", "path_leaf_episode", "path_leaf_episode", "path_aug", ), char_record_from_spans( "file.mkv", &[], "schema_v2_synthetic_path_leaf", "path_leaf_file", "path_leaf_file", "path_aug", ), char_record_from_spans( "S01E03.mkv", &[(1, 3, Entity::Season), (4, 6, Entity::Episode)], "schema_v2_synthetic_path_leaf", "path_leaf_sxe", "path_leaf_sxe", "path_aug", ), char_record_from_spans( "Movie.mkv", &[(0, 5, Entity::Tag)], "schema_v2_synthetic_path_leaf", "path_leaf_movie", "path_leaf_movie", "path_aug", ), char_record_from_spans( "NCOP2.mkv", &[(0, 5, Entity::Special)], "schema_v2_synthetic_path_leaf", "path_leaf_special", "path_leaf_special", "path_aug", ), ]}
fn char_record_from_spans( filename: &str, spans: &[(usize, usize, Entity)], source: &str, template_id: &str, template: &str, synthetic_kind: &str,) -> Record { let mut char_entities: Vec<Option<Entity>> = vec![None; filename.chars().count()]; let byte_offsets = char_byte_offsets(filename); for (start, end, entity) in spans { for (char_idx, byte_idx) in byte_offsets.iter().enumerate() { if byte_idx >= start && byte_idx < end { char_entities[char_idx] = Some(*entity); } } } let mut tokens = Vec::new(); let mut labels = Vec::new(); let mut active_entity = None; for (ch, entity) in filename.chars().zip(char_entities) { tokens.push(ch.to_string()); let label = match entity { None => { active_entity = None; "O".to_string() } Some(value) => { let prefix = if active_entity == Some(value) { "I" } else { "B" }; active_entity = Some(value); format!( "{}-{}", prefix, value .b_label() .strip_prefix("B-") .expect("entity label has B- prefix") ) } }; labels.push(label); } Record { filename: filename.to_string(), tokens, labels, source: source.to_string(), template_id: template_id.to_string(), template: template.to_string(), synthetic_kind: synthetic_kind.to_string(), tokenizer_variant: "char".to_string(), }}
fn path_title_for(index: usize, numeric_titles: &[String]) -> String { const GENERIC: [&str; 8] = [ "Title", "Naruto", "Sousou no Frieren", "Generic 2001 Story", "Yamada-kun to 7-nin no Majo", "91 Days", "Area 88", "No.6", ]; if index % 3 == 0 { GENERIC[index % GENERIC.len()].to_string() } else { numeric_titles[index % numeric_titles.len()].clone() }}
fn path_season_dir_for(index: usize) -> &'static str { const SEASON_DIRS: [&str; 10] = [ "Season 01", "S01", "01", "第2季", "Season 2", "S2", "Gekijouban", "Movie", "2004", "TV", ]; SEASON_DIRS[index % SEASON_DIRS.len()]}
fn build_path_record( prefix: &str, kind: PathSeedKind, title: &str, season_dir: &str, base: &Record,) -> Option<Record> { if !prefix.contains("{filename}") { return None; } if !path_seed_compatible_with_base(kind, classify_base_media_kind(base)) { return None; } let mut builder = CharBuilder::default(); let mut remaining = prefix; while !remaining.is_empty() { if let Some(rest) = remaining.strip_prefix("{title}") { builder.append_entity(title, Entity::PathTitleLatin); remaining = rest; } else if let Some(rest) = remaining.strip_prefix("{filename}") { append_existing_record(&mut builder, base); remaining = rest; } else if let Some(rest) = remaining.strip_prefix("{season_dir}") { append_path_segment(&mut builder, season_dir); remaining = rest; } else { let next = next_placeholder_index(remaining).unwrap_or(remaining.len()); let literal = &remaining[..next]; append_path_literal(&mut builder, literal); remaining = &remaining[next..]; } } let (filename, tokens, labels) = builder.into_parts(); Some(Record { filename, tokens, labels, source: kind.source().to_string(), template_id: format!("path::{}", base.template_id), template: prefix.to_string(), synthetic_kind: kind.synthetic_kind().to_string(), tokenizer_variant: "char".to_string(), })}
fn next_placeholder_index(text: &str) -> Option<usize> { ["{title}", "{filename}", "{season_dir}"] .iter() .filter_map(|needle| text.find(needle)) .min()}
fn append_existing_record(builder: &mut CharBuilder, record: &Record) { for (token, label) in record.tokens.iter().zip(record.labels.iter()) { builder.filename.push_str(token); builder.tokens.push(token.clone()); builder.labels.push(label.clone()); }}
fn append_path_literal(builder: &mut CharBuilder, literal: &str) { let mut segment = String::new(); for ch in literal.chars() { if ch == '/' || ch == '\\' { if !segment.is_empty() { append_path_segment(builder, &segment); segment.clear(); } builder.append_o(&ch.to_string()); } else { segment.push(ch); } } if !segment.is_empty() { append_path_segment(builder, &segment); }}
fn append_path_segment(builder: &mut CharBuilder, segment: &str) { if segment.is_empty() { return; } if is_path_season_segment(segment) { builder.append_entity(segment, Entity::PathSeason); } else if is_path_tag_segment(segment) { builder.append_entity(segment, Entity::Tag); } else { builder.append_o(segment); }}
fn is_path_season_segment(segment: &str) -> bool { static RE: OnceLock<Regex> = OnceLock::new(); let trimmed = segment.trim(); let re = RE.get_or_init(|| { Regex::new(r"(?i)^(?:season\s*0?\d{1,2}|s0?\d{1,2}|0?[1-9]|1[0-9]|第[一二三四五六七八九十\d]+[季期部])$") .expect("path season regex compiles") }); re.is_match(trimmed)}
fn is_path_tag_segment(segment: &str) -> bool { static YEAR_RE: OnceLock<Regex> = OnceLock::new(); let trimmed = segment.trim(); if matches!( trimmed.to_ascii_lowercase().as_str(), "gekijouban" | "movie" | "movies" | "anime movies" | "films" | "bdmovie" | "tv" | "extras" | "sps" | "specials" | "ova" | "oad" | "ncop" | "nced" | "pv" | "cm" | "trailer" | "menu" ) || matches!(trimmed, "劇場版") { return true; } YEAR_RE .get_or_init(|| Regex::new(r"^(?:19|20)\d{2}$").expect("year regex compiles")) .is_match(trimmed)}
#[allow(dead_code)]fn entities_for_text<'a>(record: &'a Record, needle: &str) -> Vec<&'a str> { let Some(start) = record.filename.find(needle) else { return Vec::new(); }; let end = start + needle.len(); char_byte_offsets(&record.filename) .iter() .enumerate() .filter(|(_, byte_idx)| **byte_idx >= start && **byte_idx < end) .map(|(idx, _)| record.labels[idx].as_str()) .collect()}
#[allow(dead_code)]fn fixture_record(filename: &str, spans: &[(&str, Entity)]) -> Record { let mut byte_spans = Vec::new(); for (needle, entity) in spans { let start = filename .find(needle) .unwrap_or_else(|| panic!("fixture missing span {needle} in {filename}")); byte_spans.push((start, start + needle.len(), *entity)); } char_record_from_spans( filename, &byte_spans, "test", "test", "test", "numeric_title", )}
#[cfg(test)]mod tests { use super::*;
fn assert_all_entity(record: &Record, needle: &str, entity: &str) { let labels = entities_for_text(record, needle); assert!(!labels.is_empty(), "missing text span {needle}"); assert!( labels.iter().all(|label| label.ends_with(entity)), "{needle} labels were {labels:?}, expected {entity}" ); }
fn assert_no_entity(record: &Record, needle: &str, entity: &str) { let labels = entities_for_text(record, needle); assert!(!labels.is_empty(), "missing text span {needle}"); assert!( labels.iter().all(|label| !label.ends_with(entity)), "{needle} labels unexpectedly included {entity}: {labels:?}" ); }
fn all_test_labels() -> HashSet<String> { let mut labels = HashSet::from(["O".to_string()]); for entity in [ Entity::TitleLatin, Entity::PathTitleLatin, Entity::PathSeason, Entity::Season, Entity::Episode, Entity::Special, Entity::Group, Entity::Resolution, Entity::Source, Entity::Tag, ] { labels.insert(entity.b_label().to_string()); labels.insert(entity.i_label().to_string()); } labels }
#[test] fn numeric_title_7_nin_nced_keeps_number_in_title() { let record = fixture_record( "Yamada-kun to 7-nin no Majo [NCED]", &[ ("Yamada-kun to 7-nin no Majo", Entity::TitleLatin), ("NCED", Entity::Special), ], ); assert_all_entity(&record, "7-nin", "TITLE_LATIN"); assert_all_entity(&record, "NCED", "SPECIAL"); assert!(!record.labels.iter().any(|label| label.ends_with("EPISODE"))); }
#[test] fn numeric_title_91_days_ncop2_keeps_number_in_title() { let record = fixture_record( "91 Days [NCOP2]", &[("91 Days", Entity::TitleLatin), ("NCOP2", Entity::Special)], ); assert_all_entity(&record, "91 Days", "TITLE_LATIN"); assert_all_entity(&record, "NCOP2", "SPECIAL"); assert_no_entity(&record, "91", "EPISODE"); }
#[test] fn special_number_after_pv_is_special_not_episode() { let recipe = Recipe { template_id: "tpl_test".to_string(), template: "TEXT SEP SEASON SEP BRACKET_SPECIAL BRACKET_EPISODE".to_string(), roles: vec![ "TITLE".to_string(), "O".to_string(), "SEASON".to_string(), "O".to_string(), "SPECIAL".to_string(), "EPISODE".to_string(), ], confidence: Some("high".to_string()), _count: Some(1), }; let record = build_numeric_record(&recipe, "100-nin no Kanojo", 2).unwrap(); assert_all_entity(&record, "100-nin", "TITLE_LATIN"); assert_all_entity(&record, "S01", "SEASON"); assert_all_entity(&record, "PV", "SPECIAL"); let pv_start = record.filename.find("PV").unwrap(); let special_number_labels = entities_for_text_after(&record, "01", pv_start); assert!( special_number_labels .iter() .all(|label| label.ends_with("SPECIAL")), "special number labels were {special_number_labels:?}" ); }
#[test] fn path_title_season_episode_labels_are_projected() { let base = char_record_from_spans( "03.mkv", &[(0, 2, Entity::Episode)], "test", "leaf", "leaf", "path_aug", ); let record = build_path_record( "/mnt/media/anime/{title}/Season 01/{filename}", PathSeedKind::Series, "Title", "Season 01", &base, ) .unwrap(); assert_eq!(record.filename, "/mnt/media/anime/Title/Season 01/03.mkv"); assert_all_entity(&record, "Title", "PATH_TITLE_LATIN"); assert_all_entity(&record, "Season 01", "PATH_SEASON"); assert_all_entity(&record, "03", "EPISODE"); }
#[test] fn confusing_path_dirs_are_tags_not_path_season() { let base = char_record_from_spans("file.mkv", &[], "test", "leaf", "leaf", "path_aug"); let record = build_path_record( "/mnt/media/anime/{title}/Gekijouban/2004/{filename}", PathSeedKind::Confuser, "Naruto", "Season 01", &base, ) .unwrap(); assert_eq!( record.filename, "/mnt/media/anime/Naruto/Gekijouban/2004/file.mkv" ); assert_all_entity(&record, "Naruto", "PATH_TITLE_LATIN"); assert_all_entity(&record, "Gekijouban", "TAG"); assert_all_entity(&record, "2004", "TAG"); assert_no_entity(&record, "2004", "PATH_SEASON"); }
#[test] fn movie_path_rejects_series_episode_base_and_accepts_movie_base() { let series_base = char_record_from_spans( "03.mkv", &[(0, 2, Entity::Episode)], "test", "leaf", "leaf", "path_aug", ); assert!(build_path_record( "Movies/{title}/{filename}", PathSeedKind::Movie, "Area 88", "Season 01", &series_base, ) .is_none());
let movie_base = char_record_from_spans( "Movie.mkv", &[(0, 5, Entity::Tag)], "test", "leaf_movie", "leaf_movie", "path_aug", ); let record = build_path_record( "Movies/{title}/{filename}", PathSeedKind::Movie, "Area 88", "Season 01", &movie_base, ) .unwrap(); assert_eq!(record.synthetic_kind, "path_movie"); assert_all_entity(&record, "Area 88", "PATH_TITLE_LATIN"); assert_all_entity(&record, "Movie", "TAG"); assert!(!record.filename.contains("Season 01")); }
#[test] fn series_path_rejects_movie_base() { let movie_base = char_record_from_spans( "Gekijouban.mkv", &[(0, 10, Entity::Tag)], "test", "leaf_movie", "leaf_movie", "path_aug", ); assert!(build_path_record( "Anime/{title}/Season 01/{filename}", PathSeedKind::Series, "No.6", "Season 01", &movie_base, ) .is_none()); }
#[test] fn typed_path_seed_parser_distinguishes_movie_special_and_confuser() { assert_eq!( parse_path_seed_line("movie|Movies/{title}/{filename}") .unwrap() .kind, PathSeedKind::Movie ); assert_eq!( parse_path_seed_line("special|SPs/{title}/{filename}") .unwrap() .kind, PathSeedKind::Special ); assert_eq!( parse_path_seed_line("# confuser|Bangumi/{title}/2004/{filename}") .unwrap() .kind, PathSeedKind::Confuser ); }
#[test] fn path_kind_stats_increment_separate_manifest_buckets() { let mut stats = BuildStats::default(); let mut records = Vec::new(); let mut seen = HashSet::new(); let label_set = all_test_labels(); let movie = char_record_from_spans( "Movies/Area 88/Movie.mkv", &[(7, 14, Entity::PathTitleLatin), (15, 20, Entity::Tag)], "test", "movie", "movie", "path_movie", ); push_record(movie, &mut records, &mut seen, &mut stats, &label_set).unwrap(); assert_eq!(stats.path_rows, 1); assert_eq!(stats.path_movie_rows, 1); assert_eq!(stats.path_series_rows, 0); assert_eq!(stats.path_special_rows, 0); }
#[test] fn rust_record_validation_rejects_orphan_i_tag_and_missing_title() { let label_set = all_test_labels(); let mut orphan = fixture_record("No.6.mkv", &[("No.6", Entity::TitleLatin)]); orphan.labels[0] = "I-TITLE_LATIN".to_string(); assert!(validate_record_labels(&orphan, &label_set) .unwrap_err() .to_string() .contains("orphan I-tag"));
let missing_title = char_record_from_spans( "03.mkv", &[(0, 2, Entity::Episode)], "test", "episode", "episode", "path_series", ); assert!(validate_record_labels(&missing_title, &label_set) .unwrap_err() .to_string() .contains("missing title span")); }
#[test] fn manifest_rows_round_trip_json_shape() { let record = fixture_record( "86 [01][1080p]", &[ ("86", Entity::TitleLatin), ("01", Entity::Episode), ("1080p", Entity::Resolution), ], ); let encoded = serde_json::to_value(&record).unwrap(); assert_eq!( encoded["filename"], Value::String("86 [01][1080p]".to_string()) ); assert_eq!( encoded["tokenizer_variant"], Value::String("char".to_string()) ); }}
#[cfg(test)]fn entities_for_text_after<'a>(record: &'a Record, needle: &str, start_at: usize) -> Vec<&'a str> { let Some(start) = record.filename[start_at..].find(needle) else { return Vec::new(); }; let start = start + start_at; let end = start + needle.len(); char_byte_offsets(&record.filename) .iter() .enumerate() .filter(|(_, byte_idx)| **byte_idx >= start && **byte_idx < end) .map(|(idx, _)| record.labels[idx].as_str()) .collect()}AGENTS.md+35-2
data/synthetic_numeric_titles.txtAdded+148
data/synthetic_path_prefixes.txtAdded+154
tools/schema_v2_synthetic_augment/Cargo.lockAdded+664
tools/schema_v2_synthetic_augment/Cargo.tomlAdded+15
tools/schema_v2_synthetic_augment/README.mdAdded+151
tools/schema_v2_synthetic_augment/src/bin/validate_synthetic_aug_jsonl.rsAdded+251
tools/schema_v2_synthetic_augment/src/main.rsAdded+1573