def f_lossy(self, program, is_rir):
    """Transforms a single program to its lossy IR."""
    var_token = "var"
    lir = str(program)
    if not is_rir:  # Anonymize each token of an entity or variable.
      entities = ["M" + str(i) for i in range(10)]
      variables = ["?x" + str(i) for i in range(10)]
      for entity in entities:  # Anonymize entities.
        lir = lir.replace(entity, var_token)
      for variable in variables:  # Anonymize variables.
        lir = lir.replace(variable, var_token)
      return lir
    else:
      # Anonymize entities and variables, which are possibly merged, to a single
      # "var" token, e.g., "( M1, M2 )" -> "( var )".
      to_be_masked = []  # Strings for entities and variables to anonymize.
      # Parts that should be anonymized are inside parentheses.
      regex = (r"\( ([^ ]+?) a [^ ]+? \)|\( FILTER \( ([^ ]+) != ([^ ]+) \) "
               r"\)|\( ([^ ]+?) \( .+? \) \( (.+?) \) \)")
      matches = re.findall(regex, program)
      for match in matches:
        # Each entry in 'match' corresponds to a different parentheses in regex.
        for group in match:
          # A group contains comma separated entities/variables, e.g., "M1 , M2"
          if group:
            to_be_masked.append(group)
      lir = str(program)
      # Sort to replace larger groups first.
      to_be_masked.sort(key=len, reverse=True)

      for group in to_be_masked:
        lir = lir.replace(group, var_token)
      return lir
Transforms a single program to its lossy IR.
language/compir/dataset_parsers/cfq_parser.py