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
Tighten DMHY template label heuristics
Browse files200 unmodified lines2012022032042052062072082092101553 unmodified lines176417651766176717681769177012 unmodified lines178317841785178617871788446 unmodified lines223522362237223822392240464 unmodified lines270527062707270827092710328 unmodified lines30393040304130423043304421 unmodified lines306630673068306930703071155 unmodified lines32273228322932303231323232333234323532363237323832393240324132423243324438 unmodified lines3283328432853286328732882 unmodified lines329132923293329432953296329713 unmodified lines3311331233133314331533163 unmodified lines332033213322332333243325332633272 unmodified lines3330333133323333333433353336333733383339334025 unmodified lines3366336733683369337033713372478 unmodified lines385138523853385438553856234 unmodified lines40914092409340944095409613 unmodified lines4110411141124113411441156 unmodified lines41224123412441254126412715 unmodified lines414341444145414641474148200 unmodified linesstatic CJK_SEASON_EMBEDDED_RE: Lazy<Regex> = Lazy::new(|| {Regex::new(r"^(.+?)(第[一二三四五六七八九十\d]+[季期部])(.{0,12})$").unwrap()});static ASCII_SEASON_SUFFIX_RE: Lazy<Regex> =Lazy::new(|| Regex::new(r"(?i)^(.+?)[\s_.-]+(S\d{1,2})$").unwrap());static ORDINAL_SEASON_TOKEN_RE: Lazy<Regex> =Lazy::new(|| Regex::new(r"(?i)^\d{1,2}(?:st|nd|rd|th)$").unwrap());static SEASON_WORD_RE: Lazy<Regex> =Lazy::new(|| Regex::new(r"(?i)^(?:Season|Saison)$").unwrap());static CJK_TITLE_LANG_PREFIX_RE: Lazy<Regex> =1553 unmodified lineslet markers = ["譁", "蜈", "螟", "蟄", "謇", "邱", "荳", "縺", "繧", "莨", "鬆", "髯", "瀛","楀", "箷", "绲", "刔", "鏃", "湪", "鏍", "犲", "儚", "鐗", "吀", "铦", "躲","伄", "椋", "伓", "姘", "帽",];let marker_hits = markers.iter()12 unmodified linesfn has_non_anime_noise(value: &str) -> bool {let normalized = value.replace('\\', "/").trim().to_ascii_lowercase();normalized == "mtv" || normalized.starts_with("mtv/") || normalized.contains("/mtv/")}fn normalized_path_segment(value: &str) -> String {446 unmodified lines&["Phantasy", "Star", "Online", "2", "Episode", "Oracle"],&["Durarara", "2", "Ketsu"],&["Ghiblies", "Episode", "2"],&["Lupin The Thrid Jigen Daisuke no Bohyou"],&["Lupin The Third Jigen Daisuke no Bohyou"],];464 unmodified linesoutput[index] = "O".to_string();continue;}if roles[index] == "TITLE" && matches!(text.as_str(), "第" | "話" | "话" | "回" | "集"){output[index] = "O".to_string();328 unmodified lineslabels.push("B-SEASON".to_string());continue;}if let Some(caps) = ASCII_SEASON_SUFFIX_RE.captures(&piece) {let before = caps.get(1).map(|m| m.as_str()).unwrap_or_default();let season = caps.get(2).map(|m| m.as_str()).unwrap_or_default();21 unmodified lines}continue;}output_pieces.push(piece);labels.push("B-TITLE".to_string());}155 unmodified lineslet joiners = [" ", ".", "-", "_", "·", "・", "×", "/", "/", "'", "’", ":", ":", "!", "!", "?","?", ";", ";", ",", ",", "、", "。", "~", "~", "-", "+", "+", "(", ")","(", ")", "[", "]", "【", "】", "<", ">", "<", ">", "「", "」", "「", "」","☆", "♪", "`", "@",];let title_terminal_punctuation = ["!", "!", "?", "?"];let entity_joiners = [" ", ".", "-", "_", "·", "・", "×", "/", "/", "'", "’", ":", ":", "!", "!", "?","?", ";", ";", ",", ",", "、", "。", "~", "~", "-", "+", "+", "(", ")","(", ")", "[", "]", "【", "】", "<", ">", "<", ">", "「", "」", "「", "」","☆", "♪", "`", "@", "&", "&",];let mut output = labels.to_vec();for (index, (token, label)) in tokens.iter().zip(labels.iter()).enumerate() {if label == "B-TITLE"&& token.chars().all(|ch| ch.is_ascii_digit())&& token.len() == 338 unmodified lines.chars().any(|ch| ch.is_alphanumeric() || ('\u{4e00}'..='\u{9fff}').contains(&ch))});let previous_word = previous_title_word.map(|cursor| tokens[cursor].to_ascii_lowercase());if previous_title_word.is_some()&& !matches!(previous_word.as_deref(), Some("lupin"))2 unmodified linescontinue;}}if label == "B-TITLE" && ORDINAL_SEASON_TOKEN_RE.is_match(token) {let next_word = (index + 1..tokens.len()).find(|&cursor| {!joiners.contains(&tokens[cursor].as_str())&& tokens[cursor].chars().any(|ch| ch.is_alphabetic())13 unmodified linescontinue;}}if label == "O"&& token.chars().all(|ch| ch.is_ascii_digit())&& token.len() <= 33 unmodified lines.find(|&cursor| !tokens[cursor].chars().all(char::is_whitespace));let next_non_space = (index + 1..tokens.len()).find(|&cursor| !tokens[cursor].chars().all(char::is_whitespace));if previous_non_space.is_some_and(|cursor| tokens[cursor] == "[")&& next_non_space.is_some_and(|cursor| tokens[cursor] == "]")&& output[..index].iter().any(|label| label == "B-TITLE")&& output[index + 1..].iter()2 unmodified linesoutput[index] = "B-EPISODE".to_string();continue;}}if label == "B-EPISODE" && token.chars().all(|ch| ch.is_ascii_digit()) {let previous_non_space = (0..index).rev().find(|&cursor| !tokens[cursor].chars().all(char::is_whitespace));if previous_non_space.is_some_and(|cursor| matches!(tokens[cursor].as_str(), "×" | "x" | "X")){25 unmodified lines}break;}if matches!(previous_word.as_deref(), Some("lesson" | "part" | "no")) {output[index] = "O".to_string();continue;}478 unmodified linesassert!(has_encoding_noise("[4K_SDR][DBD-Raws&HKG瀛楀箷绲刔[鏃ュ湪鏍″湌][01][2160P]"));let tintin = "Adventures of Tintin (1991) Season 1-3 S01-S03 (1080p BluRay x265 HEVC 10bit EAC3 2.0 Garshasp)/Season 1/Adventures of Tintin (1991) - S01E06 - Cigars of the Pharaoh (Part 1) (1080p BluRay x265 Garshasp)";let (trimmed, was_trimmed) = training_filename_for(tintin);234 unmodified linesassert!(bleach_movie.contains(&("3".to_string(), "B-TITLE".to_string())));assert!(!bleach_movie.contains(&("3".to_string(), "B-EPISODE".to_string())));let no_number = labels_for("[甜甜圈字幕组] 小讨厌 081「爷爷的礼物 No.1」");assert!(no_number.contains(&("081".to_string(), "B-EPISODE".to_string())));assert!(!no_number.contains(&("1".to_string(), "B-EPISODE".to_string())));13 unmodified linesassert!(hayate.contains(&("Season".to_string(), "B-SEASON".to_string())));assert!(hayate.contains(&("23".to_string(), "B-EPISODE".to_string())));let jade = labels_for("[GM-Team][国漫][诛仙 第2季][Jade Dynasty Ⅱ][2024][12][AVC][GB][1080P]");assert!(jade.contains(&("Jade".to_string(), "B-TITLE".to_string())));assert!(jade.contains(&("Dynasty".to_string(), "B-TITLE".to_string())));6 unmodified linesassert!(yu_no.contains(&("NO".to_string(), "B-TITLE".to_string())));assert!(yu_no.contains(&("23".to_string(), "B-EPISODE".to_string())));let fox = labels_for("[GM-Team][国漫][狐妖小红娘 尾生篇][Fox Spirit Matchmaker Ⅷ][2019][05][AVC][GB][1080P]",);15 unmodified linesassert!(date_live_special.contains(&("Ⅱ".to_string(), "B-SEASON".to_string())));assert!(date_live_special.contains(&("CM01".to_string(), "B-SPECIAL".to_string())));let ep_only = dmhy_record("Ep.25", "tpl_test", &suggested_roles("TEXT SEP EPISODE")).unwrap();assert!(audit_warnings(&ep_only).contains(&"no_title".to_string()));}200 unmodified lines2012022032042052062072082092102112122132142152162172181553 unmodified lines177217731774177517761777177812 unmodified lines17911792179317941795179617971798179918001801446 unmodified lines2248224922502251225222532254464 unmodified lines2719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743328 unmodified lines3072307330743075307630773078307930803081308221 unmodified lines310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136155 unmodified lines329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334938 unmodified lines338833893390339133923393339433953396339733982 unmodified lines340134023403340434053406340734083409341013 unmodified lines34243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593 unmodified lines356335643565356635673568356935702 unmodified lines35733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361725 unmodified lines3643364436453646364736483649365036513652365336543655478 unmodified lines4134413541364137413841394140414141424143234 unmodified lines437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442613 unmodified lines44404441444244434444444544464447444844494450445144524453445444556 unmodified lines4462446344644465446644674468446944704471447215 unmodified lines44884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555200 unmodified linesstatic CJK_SEASON_EMBEDDED_RE: Lazy<Regex> = Lazy::new(|| {Regex::new(r"^(.+?)(第[一二三四五六七八九十\d]+[季期部])(.{0,12})$").unwrap()});static CJK_EPISODE_EMBEDDED_RE: Lazy<Regex> =Lazy::new(|| Regex::new(r"^(.+?)(第?\d{1,4}[话話回集])(.{0,32})$").unwrap());static CJK_TITLE_TRAILING_EPISODE_RE: Lazy<Regex> =Lazy::new(|| Regex::new(r"^(.+[\p{Han}\p{Hiragana}\p{Katakana}])(\d{2,3})$").unwrap());static ASCII_SEASON_SUFFIX_RE: Lazy<Regex> =Lazy::new(|| Regex::new(r"(?i)^(.+?)[\s_.-]+(S\d{1,2})$").unwrap());static ORDINAL_SEASON_TOKEN_RE: Lazy<Regex> =Lazy::new(|| Regex::new(r"(?i)^\d{1,2}(?:st|nd|rd|th)$").unwrap());static WORD_ORDINAL_SEASON_TOKEN_RE: Lazy<Regex> = Lazy::new(|| {Regex::new(r"(?i)^(?:First|Second|Third|Fourth|Fifth|Sixth|Seventh|Eighth|Ninth|Tenth)$").unwrap()});static SEASON_WORD_RE: Lazy<Regex> =Lazy::new(|| Regex::new(r"(?i)^(?:Season|Saison)$").unwrap());static CJK_TITLE_LANG_PREFIX_RE: Lazy<Regex> =1553 unmodified lineslet markers = ["譁", "蜈", "螟", "蟄", "謇", "邱", "荳", "縺", "繧", "莨", "鬆", "髯", "瀛","楀", "箷", "绲", "刔", "鏃", "湪", "鏍", "犲", "儚", "鐗", "吀", "铦", "躲","伄", "椋", "伓", "姘", "帽", "娆", "洖", "浜", "堝", "澶", "湴", "鐒",];let marker_hits = markers.iter()12 unmodified linesfn has_non_anime_noise(value: &str) -> bool {let normalized = value.replace('\\', "/").trim().to_ascii_lowercase();normalized == "mtv" || normalized.starts_with("mtv/") || normalized.contains("/mtv/")|| value.contains("[旅游")|| value.contains("[旅游番")|| normalized.contains("tokyo deep")|| value.contains("日本不思议铁路之旅")|| value.contains("ニッポンぶらり鉄道旅")}fn normalized_path_segment(value: &str) -> String {446 unmodified lines&["Phantasy", "Star", "Online", "2", "Episode", "Oracle"],&["Durarara", "2", "Ketsu"],&["Ghiblies", "Episode", "2"],&["Eien", "no", "831"],&["Lupin The Thrid Jigen Daisuke no Bohyou"],&["Lupin The Third Jigen Daisuke no Bohyou"],];464 unmodified linesoutput[index] = "O".to_string();continue;}if roles[index] == "TITLE"&& matches!(text.as_str(), "TVアニメ" | "テレビアニメ")&& output.iter().enumerate().any(|(other, role)| other != index && role == "TITLE"){output[index] = "O".to_string();continue;}if output[index] == "TITLE" && text.eq_ignore_ascii_case("Creditless") {let later_special = output[index + 1..].iter().any(|role| role == "SPECIAL");if later_special {output[index] = "SPECIAL".to_string();continue;}}if roles[index] == "TITLE" && matches!(text.as_str(), "第" | "話" | "话" | "回" | "集"){output[index] = "O".to_string();328 unmodified lineslabels.push("B-SEASON".to_string());continue;}if EPISODE_CJK_RE.is_match(&piece) {output_pieces.push(piece);labels.push("B-EPISODE".to_string());continue;}if let Some(caps) = ASCII_SEASON_SUFFIX_RE.captures(&piece) {let before = caps.get(1).map(|m| m.as_str()).unwrap_or_default();let season = caps.get(2).map(|m| m.as_str()).unwrap_or_default();21 unmodified lines}continue;}if let Some(caps) = CJK_EPISODE_EMBEDDED_RE.captures(&piece) {let before = caps.get(1).map(|m| m.as_str()).unwrap_or_default();let episode = caps.get(2).map(|m| m.as_str()).unwrap_or_default();let after = caps.get(3).map(|m| m.as_str()).unwrap_or_default();if !before.is_empty() {output_pieces.push(before.to_string());labels.push("B-TITLE".to_string());}output_pieces.push(episode.to_string());labels.push("B-EPISODE".to_string());if !after.is_empty() {output_pieces.push(after.to_string());labels.push("O".to_string());}continue;}if let Some(caps) = CJK_TITLE_TRAILING_EPISODE_RE.captures(&piece) {let before = caps.get(1).map(|m| m.as_str()).unwrap_or_default();let episode = caps.get(2).map(|m| m.as_str()).unwrap_or_default();if !before.is_empty() {output_pieces.push(before.to_string());labels.push("B-TITLE".to_string());}output_pieces.push(episode.to_string());labels.push("B-EPISODE".to_string());continue;}output_pieces.push(piece);labels.push("B-TITLE".to_string());}155 unmodified lineslet joiners = [" ", ".", "-", "_", "·", "・", "×", "/", "/", "'", "’", ":", ":", "!", "!", "?","?", ";", ";", ",", ",", "、", "。", "~", "~", "-", "+", "+", "(", ")","(", ")", "[", "]", "【", "】", "<", ">", "<", ">", "「", "」", "「", "」", "《", "》","☆", "♪", "`", "@", "‐", "‑", "–", "—", "−", "$", "$", "∽", "꞉", "♥",];let title_terminal_punctuation = ["!", "!", "?", "?"];let entity_joiners = [" ", ".", "-", "_", "·", "・", "×", "/", "/", "'", "’", ":", ":", "!", "!", "?","?", ";", ";", ",", ",", "、", "。", "~", "~", "-", "+", "+", "(", ")","(", ")", "[", "]", "【", "】", "<", ">", "<", ">", "「", "」", "「", "」", "《", "》","☆", "♪", "`", "@", "&", "&", "‐", "‑", "–", "—", "−", "$", "$", "∽", "꞉", "♥",];let mut output = labels.to_vec();for (index, (token, label)) in tokens.iter().zip(labels.iter()).enumerate() {if label == "B-TITLE"&& token == "TV"&& index + 1 < tokens.len()&& tokens[index + 1] == "アニメ"&& output[index + 2..].iter().any(|label| label == "B-TITLE"){output[index] = "O".to_string();output[index + 1] = "O".to_string();continue;}if label == "B-TITLE"&& token == "アニメ"&& output[index + 1..].iter().any(|label| label == "B-TITLE"){output[index] = "O".to_string();continue;}if label == "B-TITLE" && token.eq_ignore_ascii_case("part") {let next_number = (index + 1..tokens.len()).find(|&cursor| {!joiners.contains(&tokens[cursor].as_str())&& !tokens[cursor].chars().all(char::is_whitespace)});let nearby_lupin = tokens[..index].iter().rev().take(8).any(|item| item.eq_ignore_ascii_case("lupin"))|| tokens[index + 1..].iter().take(12).any(|item| item.eq_ignore_ascii_case("lupin"));if nearby_lupin&& next_number.is_some_and(|cursor| {tokens[cursor].chars().all(|ch| ch.is_ascii_digit()) && tokens[cursor].len() <= 2}){output[index] = "B-SEASON".to_string();continue;}}if label == "B-TITLE"&& token.chars().all(|ch| ch.is_ascii_digit())&& token.len() == 338 unmodified lines.chars().any(|ch| ch.is_alphanumeric() || ('\u{4e00}'..='\u{9fff}').contains(&ch))});let later_episode = (index + 1..tokens.len()).any(|cursor| labels[cursor] == "B-EPISODE");if previous_title_word.is_none() && later_episode {output[index] = "B-SEASON".to_string();continue;}let previous_word = previous_title_word.map(|cursor| tokens[cursor].to_ascii_lowercase());if previous_title_word.is_some()&& !matches!(previous_word.as_deref(), Some("lupin"))2 unmodified linescontinue;}}if label == "B-TITLE"&& (ORDINAL_SEASON_TOKEN_RE.is_match(token)|| WORD_ORDINAL_SEASON_TOKEN_RE.is_match(token)){let next_word = (index + 1..tokens.len()).find(|&cursor| {!joiners.contains(&tokens[cursor].as_str())&& tokens[cursor].chars().any(|ch| ch.is_alphabetic())13 unmodified linescontinue;}}if label == "O"&& (EPISODE_CJK_RE.is_match(token)|| EPISODE_VALUE_RE.is_match(token)|| EPISODE_RANGE_RE.is_match(token)){output[index] = "B-EPISODE".to_string();continue;}if label == "O" && token.chars().all(|ch| ch.is_ascii_digit()) {let previous_non_space = (0..index).rev().find(|&cursor| !tokens[cursor].chars().all(char::is_whitespace));let next_non_space = (index + 1..tokens.len()).find(|&cursor| !tokens[cursor].chars().all(char::is_whitespace));if previous_non_space.is_some_and(|cursor| tokens[cursor] == "#") {output[index] = "B-EPISODE".to_string();if next_non_space.is_some_and(|cursor| matches!(tokens[cursor].as_str(), "-" | "~")){if let Some(separator) = next_non_space {output[separator] = "B-EPISODE".to_string();if let Some(right) = (separator + 1..tokens.len()).find(|&cursor| !tokens[cursor].chars().all(char::is_whitespace)){if tokens[right].chars().all(|ch| ch.is_ascii_digit()) {output[right] = "B-EPISODE".to_string();}}}}continue;}if previous_non_space.is_some_and(|cursor| tokens[cursor] == "第")&& next_non_space.is_some_and(|cursor| {matches!(tokens[cursor].as_str(), "话" | "話" | "回" | "集")|| tokens[cursor].starts_with('话')|| tokens[cursor].starts_with('話')|| tokens[cursor].starts_with('回')|| tokens[cursor].starts_with('集')}){if let Some(cursor) = previous_non_space {output[cursor] = "B-EPISODE".to_string();}output[index] = "B-EPISODE".to_string();if let Some(cursor) = next_non_space {if matches!(tokens[cursor].as_str(), "话" | "話" | "回" | "集") {output[cursor] = "B-EPISODE".to_string();}}continue;}}if matches!(label.as_str(), "B-TITLE" | "O")&& token.chars().all(|ch| ch.is_ascii_digit())&& token.len() <= 3{let previous_word = (0..index).rev().find(|&cursor| {!joiners.contains(&tokens[cursor].as_str())&& tokens[cursor].chars().any(|ch| ch.is_alphabetic())}).map(|cursor| tokens[cursor].to_ascii_lowercase());let next_structural = (index + 1..tokens.len()).find(|&cursor| !joiners.contains(&tokens[cursor].as_str())).map(|cursor| tokens[cursor].as_str());let next_non_space = (index + 1..tokens.len()).find(|&cursor| !tokens[cursor].chars().all(char::is_whitespace)).map(|cursor| tokens[cursor].as_str());let later_technical_block = output[index + 1..].iter().any(|label| matches!(label.as_str(), "B-SOURCE" | "B-RESOLUTION"));let nearby_lupin_part = previous_word.as_deref() == Some("part")&& (tokens[..index].iter().rev().take(8).any(|item| item.eq_ignore_ascii_case("lupin"))|| tokens[index + 1..].iter().take(12).any(|item| item.eq_ignore_ascii_case("lupin")));if nearby_lupin_part {output[index] = "B-SEASON".to_string();continue;}let followed_by_title_word = (index + 1..tokens.len()).find(|&cursor| {!joiners.contains(&tokens[cursor].as_str())&& !matches!(tokens[cursor].as_str(), "-" | "-" | "," | "," | ":" | ":")}).is_some_and(|cursor| {!matches!(tokens[cursor].as_str(), "[" | "【" | "(" | "(" | "]" | "】")&& output.get(cursor).is_some_and(|label| label == "B-TITLE")&& tokens[cursor].chars().any(|ch| ch.is_alphabetic())});if followed_by_title_word && matches!(previous_word.as_deref(), Some("movie" | "part")){output[index] = "B-TITLE".to_string();continue;}if (later_technical_block|| next_non_space.is_some_and(|token| matches!(token, "[" | "【" | "(" | "("))|| next_structural.is_some_and(|token| matches!(token, "[" | "【" | "(" | "(")))&& matches!(previous_word.as_deref(), Some("movie" | "part")){output[index] = "B-SPECIAL".to_string();continue;}let eien_title_number = token == "831"&& previous_word.as_deref() == Some("no")&& (0..index).any(|cursor| {output[cursor] == "B-TITLE" && tokens[cursor].eq_ignore_ascii_case("Eien")});if eien_title_number {for joiner_index in (0..index).rev() {if tokens[joiner_index].eq_ignore_ascii_case("no") {break;}if joiners.contains(&tokens[joiner_index].as_str()) {output[joiner_index] = "B-TITLE".to_string();}}output[index] = "B-TITLE".to_string();continue;}}if label == "O"&& token.chars().all(|ch| ch.is_ascii_digit())&& token.len() <= 33 unmodified lines.find(|&cursor| !tokens[cursor].chars().all(char::is_whitespace));let next_non_space = (index + 1..tokens.len()).find(|&cursor| !tokens[cursor].chars().all(char::is_whitespace));if previous_non_space.is_some_and(|cursor| matches!(tokens[cursor].as_str(), "[" | "【"))&& next_non_space.is_some_and(|cursor| matches!(tokens[cursor].as_str(), "]" | "】"))&& output[..index].iter().any(|label| label == "B-TITLE")&& output[index + 1..].iter()2 unmodified linesoutput[index] = "B-EPISODE".to_string();continue;}if previous_non_space.is_some_and(|cursor| matches!(tokens[cursor].as_str(), "-" | "-"))&& output[..index].iter().any(|label| label == "B-TITLE")&& output[index + 1..].iter().any(|label| matches!(label.as_str(), "B-SOURCE" | "B-RESOLUTION")){output[index] = "B-EPISODE".to_string();continue;}if next_non_space.is_none()&& previous_non_space.is_some_and(|cursor| {output[cursor] == "B-TITLE"&& tokens[cursor].chars().any(|ch| {('\u{4e00}'..='\u{9fff}').contains(&ch)|| ('\u{3040}'..='\u{30ff}').contains(&ch)})}){output[index] = "B-EPISODE".to_string();continue;}}if label == "B-EPISODE" && token.chars().all(|ch| ch.is_ascii_digit()) {let previous_non_space = (0..index).rev().find(|&cursor| !tokens[cursor].chars().all(char::is_whitespace));let next_non_space = (index + 1..tokens.len()).find(|&cursor| !tokens[cursor].chars().all(char::is_whitespace));if previous_non_space.is_some_and(|cursor| tokens[cursor] == "第")&& next_non_space.is_some_and(|cursor| matches!(tokens[cursor].as_str(), "话" | "話" | "回" | "集")){if let Some(cursor) = previous_non_space {output[cursor] = "B-EPISODE".to_string();}if let Some(cursor) = next_non_space {output[cursor] = "B-EPISODE".to_string();}}if previous_non_space.is_some_and(|cursor| matches!(tokens[cursor].as_str(), "×" | "x" | "X")){25 unmodified lines}break;}let previous_non_space = (0..index).rev().find(|&cursor| !tokens[cursor].chars().all(char::is_whitespace)).map(|cursor| tokens[cursor].as_str());if matches!(previous_word.as_deref(), Some("lesson" | "part"))|| (previous_word.as_deref() == Some("no") && previous_non_space == Some(".")){output[index] = "O".to_string();continue;}478 unmodified linesassert!(has_encoding_noise("[4K_SDR][DBD-Raws&HKG瀛楀箷绲刔[鏃ュ湪鏍″湌][01][2160P]"));assert!(has_encoding_noise("ATRI -My Dear Moments-/娆″洖浜堝憡 EP01 Log01"));assert!(has_non_anime_noise("13-[旅游番][花丸字幕组][日本不思议铁路之旅][15.03.19-16.02.03][720&1080][中日双语]/铁道旅 15.03.19 720"));let tintin = "Adventures of Tintin (1991) Season 1-3 S01-S03 (1080p BluRay x265 HEVC 10bit EAC3 2.0 Garshasp)/Season 1/Adventures of Tintin (1991) - S01E06 - Cigars of the Pharaoh (Part 1) (1080p BluRay x265 Garshasp)";let (trimmed, was_trimmed) = training_filename_for(tintin);234 unmodified linesassert!(bleach_movie.contains(&("3".to_string(), "B-TITLE".to_string())));assert!(!bleach_movie.contains(&("3".to_string(), "B-EPISODE".to_string())));let conan_movie =labels_for("[DBD-Raws][Detective Conan Movie 27 The Million-Dollar Pentagram][PV][01][1080P]");assert!(conan_movie.contains(&("27".to_string(), "B-TITLE".to_string())));assert!(conan_movie.contains(&("PV".to_string(), "B-SPECIAL".to_string())));let madoka_movie =labels_for("[DBD-Raws][Puella Magi Madoka Magica the Movie 01 Beginnings][NCED][1080P]");assert!(madoka_movie.contains(&("01".to_string(), "B-TITLE".to_string())));assert!(madoka_movie.contains(&("Beginnings".to_string(), "B-TITLE".to_string())));let fate_first_order =labels_for("[DBD-Raws][Fate Grand Order ‐First Order‐][PV][01][1080P]");assert!(fate_first_order.contains(&("Fate".to_string(), "B-TITLE".to_string())));assert!(fate_first_order.contains(&("‐".to_string(), "B-TITLE".to_string())));assert!(fate_first_order.contains(&("First".to_string(), "B-TITLE".to_string())));let trillion_game = labels_for("[ANi] 一兆$遊戲 - 03 [1080P][Baha][WEB-DL][AAC AVC][CHT]");assert!(trillion_game.contains(&("一兆".to_string(), "B-TITLE".to_string())));assert!(trillion_game.contains(&("$".to_string(), "B-TITLE".to_string())));assert!(trillion_game.contains(&("遊戲".to_string(), "B-TITLE".to_string())));let lapis = labels_for("[Nekomoe kissaten&LoliHouse] Lapis Re꞉LiGHTs - PV01 [BDRip 1080p]");assert!(lapis.contains(&("Re".to_string(), "B-TITLE".to_string())));assert!(lapis.contains(&("꞉".to_string(), "B-TITLE".to_string())));assert!(lapis.contains(&("LiGHTs".to_string(), "B-TITLE".to_string())));let rezero = labels_for("TVアニメ『Re:ゼロから始める異世界生活』第10話「鬼がかったやり方」予告");assert!(!rezero.contains(&("TV".to_string(), "B-TITLE".to_string())));assert!(!rezero.contains(&("アニメ".to_string(), "B-TITLE".to_string())));assert!(rezero.contains(&("Re".to_string(), "B-TITLE".to_string())));assert!(rezero.contains(&("第".to_string(), "B-EPISODE".to_string())));assert!(rezero.contains(&("話".to_string(), "B-EPISODE".to_string())));let shark = labels_for("アニメ『おでかけ子ザメ』第10話「かじゅえん」");assert!(!shark.contains(&("アニメ".to_string(), "B-TITLE".to_string())));assert!(shark.contains(&("おでかけ子ザメ".to_string(), "B-TITLE".to_string())));let creditless = labels_for("[ANK-Raws] デート・ア・ライブⅡ Creditless ED (Bdrip 1920x1080 HEVC FLAC)",);assert!(creditless.contains(&("Creditless".to_string(), "B-SPECIAL".to_string())));assert!(creditless.contains(&("ED".to_string(), "B-SPECIAL".to_string())));let no_number = labels_for("[甜甜圈字幕组] 小讨厌 081「爷爷的礼物 No.1」");assert!(no_number.contains(&("081".to_string(), "B-EPISODE".to_string())));assert!(!no_number.contains(&("1".to_string(), "B-EPISODE".to_string())));13 unmodified linesassert!(hayate.contains(&("Season".to_string(), "B-SEASON".to_string())));assert!(hayate.contains(&("23".to_string(), "B-EPISODE".to_string())));let yama = labels_for("[A.I.R.nesSub][Yama_no_Susume_Second_Season][08][720p]");assert!(yama.contains(&("Yama".to_string(), "B-TITLE".to_string())));assert!(yama.contains(&("Second".to_string(), "B-SEASON".to_string())));assert!(yama.contains(&("Season".to_string(), "B-SEASON".to_string())));let one_room = labels_for("[DMG][One Room Second Season][00][1080P][BIG5]");assert!(one_room.contains(&("One".to_string(), "B-TITLE".to_string())));assert!(one_room.contains(&("Second".to_string(), "B-SEASON".to_string())));assert!(one_room.contains(&("Season".to_string(), "B-SEASON".to_string())));let jade = labels_for("[GM-Team][国漫][诛仙 第2季][Jade Dynasty Ⅱ][2024][12][AVC][GB][1080P]");assert!(jade.contains(&("Jade".to_string(), "B-TITLE".to_string())));assert!(jade.contains(&("Dynasty".to_string(), "B-TITLE".to_string())));6 unmodified linesassert!(yu_no.contains(&("NO".to_string(), "B-TITLE".to_string())));assert!(yu_no.contains(&("23".to_string(), "B-EPISODE".to_string())));let yu_no_dash =labels_for("[LowPower-Raws] この世の果てで恋を唄う少女YU-NO - 01 (BD 1080P x264 FLAC)");assert!(yu_no_dash.contains(&("NO".to_string(), "B-TITLE".to_string())));assert!(yu_no_dash.contains(&("01".to_string(), "B-EPISODE".to_string())));let fox = labels_for("[GM-Team][国漫][狐妖小红娘 尾生篇][Fox Spirit Matchmaker Ⅷ][2019][05][AVC][GB][1080P]",);15 unmodified linesassert!(date_live_special.contains(&("Ⅱ".to_string(), "B-SEASON".to_string())));assert!(date_live_special.contains(&("CM01".to_string(), "B-SPECIAL".to_string())));let lupin_part =labels_for("[SnowDream][Part 5_Lupin Sansei Part 5][01][BIG5][720P]");assert!(lupin_part.contains(&("Lupin".to_string(), "B-TITLE".to_string())));assert!(lupin_part.contains(&("Sansei".to_string(), "B-TITLE".to_string())));assert!(!lupin_part.contains(&("Part".to_string(), "B-TITLE".to_string())));assert!(lupin_part.contains(&("5".to_string(), "B-SEASON".to_string())));assert!(!lupin_part.contains(&("5".to_string(), "B-SPECIAL".to_string())));let roman_leaf = dmhy_record("Ⅰ 001 魯邦燃起了鬥志", "tpl_test", &suggested_roles("TEXT SEP EPISODE SEP TEXT")).unwrap();assert!(roman_leaf.tokens.iter().zip(roman_leaf.labels.iter()).any(|(token, label)| token == "Ⅰ" && label == "B-SEASON"));assert!(audit_warnings(&roman_leaf).contains(&"no_title".to_string()));let hallow = labels_for("[c.c动漫 ccwzz.cc][驱魔少年HALLOW][第09话][GB][720p]");assert!(hallow.contains(&("驱魔少年HALLOW".to_string(), "B-TITLE".to_string())));assert!(hallow.contains(&("第09话".to_string(), "B-EPISODE".to_string())));let fairy = labels_for("[魔導少年 最終章][EP35][繁体][1080P]");assert!(fairy.contains(&("魔導少年".to_string(), "B-TITLE".to_string())));assert!(fairy.contains(&("EP35".to_string(), "B-EPISODE".to_string())));let mebius = labels_for("【CXRAW】【ウルトラマンメビウス】【22】【日々の未来】【DVDrip】【x264 Hi10P AAC】【MP4】");assert!(mebius.contains(&("ウルトラマンメビウス".to_string(), "B-TITLE".to_string())));assert!(mebius.contains(&("22".to_string(), "B-EPISODE".to_string())));let battle = labels_for("斗破苍穹三年之约第01话");assert!(battle.contains(&("斗破苍穹三年之约".to_string(), "B-TITLE".to_string())));assert!(battle.contains(&("第".to_string(), "B-EPISODE".to_string())));assert!(battle.contains(&("01".to_string(), "B-EPISODE".to_string())));assert!(battle.contains(&("话".to_string(), "B-EPISODE".to_string())));let hakumei = labels_for("妖精森林的小不点01");assert!(hakumei.contains(&("妖精森林的小不点".to_string(), "B-TITLE".to_string())));assert!(hakumei.contains(&("01".to_string(), "B-EPISODE".to_string())));let decimal_episode_title = labels_for("无限系统树:第1话可能性的起点");assert!(decimal_episode_title.contains(&("无限系统树".to_string(), "B-TITLE".to_string())));assert!(decimal_episode_title.contains(&("第".to_string(), "B-EPISODE".to_string())));assert!(decimal_episode_title.contains(&("1".to_string(), "B-EPISODE".to_string())));let hash_range = labels_for("花田少年史#1-3");assert!(hash_range.contains(&("花田少年史".to_string(), "B-TITLE".to_string())));assert!(hash_range.contains(&("1".to_string(), "B-EPISODE".to_string())));assert!(hash_range.contains(&("-".to_string(), "B-EPISODE".to_string())));assert!(hash_range.contains(&("3".to_string(), "B-EPISODE".to_string())));let movie_number = labels_for("[Kamigami] Haikyuu!! Movie - 01 [BD 1080p x265 Ma10p AAC]");assert!(movie_number.contains(&("Haikyuu".to_string(), "B-TITLE".to_string())));assert!(movie_number.contains(&("01".to_string(), "B-SPECIAL".to_string())));assert!(!movie_number.contains(&("01".to_string(), "B-EPISODE".to_string())));let ajin_movie = labels_for("[Moozzi2] Ajin The Movie - 01 (BD 1920x1080 x.264 FLACx2)");assert!(ajin_movie.contains(&("Ajin".to_string(), "B-TITLE".to_string())));assert!(ajin_movie.contains(&("01".to_string(), "B-SPECIAL".to_string())));let eien = labels_for("[Nekomoe kissaten&LoliHouse] Eien no 831 [WebRip 1080p HEVC-10bit AAC ASSx2]");assert!(eien.contains(&("Eien".to_string(), "B-TITLE".to_string())));assert!(eien.contains(&("831".to_string(), "B-TITLE".to_string())));let ep_only = dmhy_record("Ep.25", "tpl_test", &suggested_roles("TEXT SEP EPISODE")).unwrap();assert!(audit_warnings(&ep_only).contains(&"no_title".to_string()));}
tools/rust_dmhy_template_apply/src/main.rs+416-9