def load_sling_mappings(sling_kb_file, sling_wiki_mapping_file):
  """Loads entity names, number of facts and wiki page titles from SLING.

  Args:
    sling_kb_file: kb.sling file generated from SLING wikidata processor.
    sling_wiki_mapping_file: mapping.sling file generated from SLING 'en'
      wikipedia processor.

  Returns:
    qid_names: dict mapping wikidata QIDs to canonical names.
    qid_mapping: dict mapping wikidata QIDs to wikipedia page titles.
    qid_numfacts: dict mapping wikidata QIDs to number of facts.
  """
  # Load QID names.
  logging.info("Extracting entity names and num-facts from SLING KB.")
  commons = sling.Store()
  commons.load(sling_kb_file)
  commons.freeze()
  qid_names = {}
  qid_numfacts = {}
  total = 0
  for f in commons:
    total += 1
    if "name" in f:
      if isinstance(f.name, sling.String):
        qid_names[f.id] = f.name.text()
      elif isinstance(f.name, bytes):
        qid_names[f.id] = f.name.decode("utf-8", errors="ignore")
      elif isinstance(f.name, str):
        qid_names[f.id] = f.name
      else:
        logging.warn("Could not read name of type %r", type(f.name))
    ln = len(f)
    qid_numfacts[f.id] = ln
  logging.info("Processed %d QIDs out of %d", len(qid_names), total)
  # Load QID mapping.
  logging.info("Extracting entity mapping to Wikipedia from SLING.")
  commons = sling.Store()
  commons.load(sling_wiki_mapping_file)
  commons.freeze()
  qid_mapping = {}
  for f in commons:
    try:
      if "/w/item/qid" in f:
        pg = f.id[len(WIKI_PRE):] if f.id.startswith(WIKI_PRE) else f.id
        qid_mapping[f["/w/item/qid"].id] = pg
    except UnicodeDecodeError:
      continue
  logging.info("Extracted %d mappings", len(qid_mapping))
  return qid_names, qid_mapping, qid_numfacts
Loads entity names, number of facts and wiki page titles from SLING.

  Args:
    sling_kb_file: kb.sling file generated from SLING wikidata processor.
    sling_wiki_mapping_file: mapping.sling file generated from SLING 'en'
      wikipedia processor.

  Returns:
    qid_names: dict mapping wikidata QIDs to canonical names.
    qid_mapping: dict mapping wikidata QIDs to wikipedia page titles.
    qid_numfacts: dict mapping wikidata QIDs to number of facts.
  
language/templama/templama.py