def replace_entities(funql, utterance, geobase_entities):
  """Replace entity references with something more copy friendly."""
  # Order entities by longest identifier, since some can be nested
  # in others.
  geobase_entities = sorted(geobase_entities, key=lambda x: -len(x.identifier))
  mention_map = {}
  for geobase_entity in geobase_entities:
    normalized_identifier = geobase_entity.identifier.replace("'", "")
    if normalized_identifier in funql:
      funql, utterance, mention_map = _maybe_replace_entity(
          funql, utterance, mention_map, geobase_entity)
  return funql, utterance, mention_map
Replace entity references with something more copy friendly.
language/compgen/nqg/tasks/geoquery/entity_utils.py