class_docstr: Generate new examples by replacing words in examples.
  
  Substitutions must be of the form 'foo -> bar, spam -> eggs'.
class_docstr_tok: ["Generate","new","examples","by","replacing","words","in","examples",".","Substitutions","must","be","of","the","form","'foo","-",">","bar",",","spam","-",">","eggs","'","."]
docstr: Parse a substitutions list of the form 'foo -> bar, spam -> eggs' .
docstr_tok: ["Parse","a","substitutions","list","of","the","form","'foo","-",">","bar",",","spam","-",">","eggs","'","."]
code: def parse_subs_string(
      self, subs_string: str, ignore_casing: bool = True
  ) -> dict[str, list[str]]:
      """Parse a substitutions list of the form 'foo -> bar, spam -> eggs' ."""
      replacements = {}
      # TODO(lit-dev) Use pyparsing if the pattern gets more complicated.
      rules = subs_string.split(",")
      for rule in rules:
          segments = re.split(r"\s*->\s*", rule)
          if len(segments) != 2:
              logging.warning("Malformed rule: '%s'", rule)
              continue
          src, tgt_str = segments
          tgts = re.split(r"\s*\|\s*", tgt_str)
          if ignore_casing:
              src = src.lower()
          replacements[src.strip()] = [tgt.strip() for tgt in tgts]
      return replacements
  
file_path: lit/lit_nlp/components/word_replacer.py
imports: from collections.abc import Iterator, Sequence
  import re
  from typing import Optional
  from absl import logging
  from lit_nlp.api import components
  from lit_nlp.api import dataset
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.lib import utils
label_desc: Use image node_id 2 for calling the WordReplacer obj's underlying member method code with example usage: obj.parse_subs_string(subs_string, ignore_casing) and returns: replacements