def read_facts(facts_file, qid_mapping, min_year):
  """Loads facts and filters them using simple criteria.

  Args:
    facts_file: File containing wikidata facts with qualifiers.
    qid_mapping: dict mapping wikidata QIDs to wikipedia page titles.
    min_year: An int. Only facts with a start / end year greater than this will
      be kept.

  Returns:
    all_facts: list of tuples, where each tuple is a fact with
      (relation, subject, object, start, end).
  """
  logging.info("Reading facts from %s", facts_file)
  all_facts = []
  with tf.io.gfile.GFile(facts_file) as f:
    for line in tqdm(f):
      fact = line.strip().split("\t")
      # Skip boring properties.
      if not fact[0].startswith("P"):
        continue
      # Skip instance of facts.
      if fact[0] == "P31":
        continue
      # Skip facts where object is not an entity.
      if not fact[2].startswith("Q"):
        continue
      # Skip facts whose subject and objects are not wiki pages.
      if fact[1] not in qid_mapping or fact[2] not in qid_mapping:
        continue
      # Get date qualifiers.
      start, end = None, None
      for qual in fact[3:]:
        if not qual:
          continue
        elems = qual.split("=")
        # Skip inherited qualifier.
        if elems[0].endswith("*"):
          continue
        if len(elems) != 2:
          continue
        if elems[0].startswith("P580"):
          start = parse_date(elems[1])
        elif elems[0].startswith("P582"):
          end = parse_date(elems[1])
      if start is None and end is None:
        continue
      # Skip facts whose start and end are both before min_date.
      if ((start is None or start[0] < min_year) and
          (end is None or end[0] < min_year)):
        continue
      all_facts.append(fact[:3] + [start, end])
  logging.info("Loaded total %d facts", len(all_facts))
  return all_facts
Loads facts and filters them using simple criteria.

  Args:
    facts_file: File containing wikidata facts with qualifiers.
    qid_mapping: dict mapping wikidata QIDs to wikipedia page titles.
    min_year: An int. Only facts with a start / end year greater than this will
      be kept.

  Returns:
    all_facts: list of tuples, where each tuple is a fact with
      (relation, subject, object, start, end).
  
language/templama/templama.py