Datasets:

Languages:
English
Tags:
Not-For-All-Audiences
License:
Gaeros commited on
Commit
aa1f6cd
1 Parent(s): 8b15883

normalize: replace remove_parens_suffix_for_categories with remove_parens

Browse files
Files changed (2) hide show
  1. normalize.toml +5 -10
  2. normalize_tags.py +6 -9
normalize.toml CHANGED
@@ -54,16 +54,11 @@ blacklist_categories = ["pool"]
54
  # By default, underscores are replaced with spaces unless specified here
55
  keep_underscores = ["rating_explicit", "rating_questionable", "rating_safe"]
56
 
57
- # Remove Parentheses Suffix: Categories where parenthetical suffixes should be removed
58
- # E.g., "character_(series)" becomes just "character" if does not conflicts with
59
- # an existing tag/alias (for on_alias_conflict="ignore")
60
- remove_parens_suffix_for_categories = [
61
- "artist",
62
- "character",
63
- "copyright",
64
- "lore",
65
- "species",
66
- ]
67
 
68
  # On Alias Conflict: How to handle conflicts when creating aliases
69
  # Options: "silent", "overwrite", "overwrite_rarest", "warn", "raise"
 
54
  # By default, underscores are replaced with spaces unless specified here
55
  keep_underscores = ["rating_explicit", "rating_questionable", "rating_safe"]
56
 
57
+ # Remove prentheses suffixes that matches the tag's category like _(species) or
58
+ # _(character) if it doesn't conflict with another tag (when
59
+ # on_alias_conflict="ignore")
60
+ # Default: true
61
+ remove_parens = true
 
 
 
 
 
62
 
63
  # On Alias Conflict: How to handle conflicts when creating aliases
64
  # Options: "silent", "overwrite", "overwrite_rarest", "warn", "raise"
normalize_tags.py CHANGED
@@ -115,18 +115,14 @@ def make_tagset_normalizer(config: dict) -> TagSetNormalizer:
115
  tag_normalizer.remove_input_mappings(tag)
116
 
117
  # Apply rule based output renames
118
- remove_suffix_for_cats = config.get(
119
- "remove_parens_suffix_for_categories",
120
- ["artist", "character", "copyright", "lore", "species"],
121
- )
122
- remove_suffix_for_cats = {tag_category2id[c] for c in remove_suffix_for_cats}
123
  artist_by_prefix = config.get("artist_by_prefix", True)
124
 
125
  def map_output(tag, tid):
126
  cat = tagid2cat[tid] if tid is not None else -1
127
- if cat in remove_suffix_for_cats:
128
- without_suffix = RE_PARENS_SUFFIX.sub("", tag)
129
- if tag != without_suffix and tag2id.get(without_suffix) == tid:
130
  tag = without_suffix
131
  if cat == cat_artist and artist_by_prefix and not tag.startswith("by_"):
132
  tag_wby = f"by_{tag}"
@@ -403,7 +399,8 @@ def main():
403
  help="Don't ask for confirmation for clobbering input files",
404
  )
405
  parser.add_argument(
406
- "-b", "--print-blacklist",
 
407
  action="store_true",
408
  help="Print the effective list of blacklisted tags",
409
  )
 
115
  tag_normalizer.remove_input_mappings(tag)
116
 
117
  # Apply rule based output renames
118
+ remove_parens = config.get("remove_parens", True)
 
 
 
 
119
  artist_by_prefix = config.get("artist_by_prefix", True)
120
 
121
  def map_output(tag, tid):
122
  cat = tagid2cat[tid] if tid is not None else -1
123
+ if remove_parens:
124
+ without_suffix = tag.removesuffix(f"_({tag_categories[cat]})")
125
+ if without_suffix != tag and tag2id.get(without_suffix) == tid:
126
  tag = without_suffix
127
  if cat == cat_artist and artist_by_prefix and not tag.startswith("by_"):
128
  tag_wby = f"by_{tag}"
 
399
  help="Don't ask for confirmation for clobbering input files",
400
  )
401
  parser.add_argument(
402
+ "-b",
403
+ "--print-blacklist",
404
  action="store_true",
405
  help="Print the effective list of blacklisted tags",
406
  )