def get_aliases(self, x):
    """Return aliases for given wikidata id."""
    if isinstance(x, int):
      return {}
    aliases = collections.defaultdict(int)
    try:
      alias_raw = self.all_aliases[x]
    except KeyError:
      print("did not find alias:", x)
      return {}
    als = self.store.parse(alias_raw)
    for _, alias in als:
      al_name = alias.name
      if isinstance(al_name, bytes):
        al_name = al_name.decode("utf-8", errors="ignore")
      aliases[al_name.lower()] += alias.count
    sorted_aliases = sorted(aliases.items(), key=lambda x: x[1], reverse=True)
    return {x[0]: x[1] for x in sorted_aliases[:TOP_K]}
Return aliases for given wikidata id.
language/labs/drkit/wikidata/preprocessing/distantly_supervise.py