code: def get_badwords_filter_fn(
      badwords: Mapping[str, Sequence[str]],
      filter_fraction: float = 1.0,
  ):
      """Filters pages at given rate that contain language-specific bad word(s)."""
      badwords_regex = {}
      for lang, words in badwords.items():
          words = [re.escape(w) for w in words]
          badwords_regex[lang] = (
              # For Japanese, Thai, and Chinese, do not require word separations.
              re.compile("|".join(words))
              if lang in ("ja", "th", "zh")
              # For other languages, match only when flanked by non-word chars.
              else re.compile(
                  r"(?:\W|^)({})(?:\W|$)".format("|".join(words))
              )
          )
  
      filter_ratio = float.as_integer_ratio(filter_fraction)
      keep_badword_page = get_hashed_url_filter_fn(
          lambda x: x % filter_ratio[1] >= filter_ratio[0]
      )
  
      def badwords_filter(page):
          lang = page.language.split("-")[0]  # remove suffix if present
  
          if lang in badwords_regex:
              text = page.text
              badwords_found = badwords_regex[lang].search(text.lower())
              if badwords_found is not None:
                  if keep_badword_page(page):
                      get_counter_inc_fn("badwords-filter")(
                          "soft-passed"
                      )
                      get_counter_inc_fn("badwords-filter-%s" % lang)(
                          "soft-passed"
                      )
                      return True
                  get_counter_inc_fn("badwords-filter")("filtered")
                  get_counter_inc_fn("badwords-filter-%s" % lang)(
                      "filtered"
                  )
                  return False
              get_counter_inc_fn("badwords-filter-%s" % lang)("passed")
  
          get_counter_inc_fn("badwords-filter")("passed")
          return True
  
      return badwords_filter
  
imports: import dataclasses
  import functools
  import gzip
  import hashlib
  import heapq
  import io
  import re
  import threading
  from typing import Collection, Iterable, Mapping, Optional, Sequence, Tuple
  from absl import logging
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
  import tensorflow_datasets.public_api
label_desc: Use image node_id 19 for calling a global function with example usage: get_badwords_filter_fn(badwords, filter_fraction) and returns: badwords_filter, True, False, True