code: def apply_rule(word_str_ser, rule, w_in_c_flag):
      """Applies the first applicable suffix-removal rule to the word
  
      Takes a word and a list of suffix-removal rules represented as
      3-tuples, with the first element being the suffix to remove,
      the second element being the string to replace it with, and the
      final element being the condition for the rule to be applicable,
      or None if the rule is unconditional.
      """
      suffix, replacement, condition = rule
      if suffix == "*d":
          double_consonant_mask = ends_with_double_constant(
              word_str_ser
          )
          # all flags needed  here
          # with **d in nltk we pass word_series rather than stem_series
          # see below:
          # lambda stem: intermediate_stem[-1] not in ('l', 's', 'z'),
          # condition is on  intermediate_stem
          intermediate_stem = word_str_ser.str.slice(stop=-1)
          condition_mask = get_condition_flag(
              intermediate_stem, condition
          )
  
          # mask where replacement will happen
          valid_mask = (
              double_consonant_mask & condition_mask & w_in_c_flag
          )
  
          # new series with updated valid_mask
          word_str_ser = replace_suffix(
              word_str_ser, suffix, replacement, valid_mask
          )
          w_in_c_flag &= ~double_consonant_mask
  
      else:
          suffix_mask = ends_with_suffix(word_str_ser, suffix)
          valid_mask = suffix_mask & w_in_c_flag
  
          stem_ser = replace_suffix(
              word_str_ser, suffix, "", valid_mask
          )
  
          condition_mask = get_condition_flag(stem_ser, condition)
          # mask where replacement will happen
          valid_mask = condition_mask & suffix_mask & w_in_c_flag
          word_str_ser = replace_suffix(
              word_str_ser, suffix, replacement, valid_mask
          )
  
          # we wont apply further rules if it has a matching suffix
          w_in_c_flag &= ~suffix_mask
  
      return word_str_ser, w_in_c_flag
  
imports: from .porter_stemmer_utils.measure_utils import has_positive_measure, measure_gt_n, measure_eq_n
  from .porter_stemmer_utils.len_flags_utils import len_eq_n, len_gt_n
  from .porter_stemmer_utils.consonant_vowel_utils import contains_vowel, is_consonant
  from .porter_stemmer_utils.porter_stemmer_rules import ends_with_suffix, ends_with_double_constant, last_char_not_in, last_char_in, ends_cvc
  from .porter_stemmer_utils.suffix_utils import get_stem_series, get_str_replacement_series, replace_suffix
  from cuml.internals.safe_imports import gpu_only_import
label_desc: Use image node_id 3 for calling a global function with example usage: apply_rule(word_str_ser, rule, w_in_c_flag) and returns: word_str_ser,  w_in_c_flag