def resolve_objects(facts):
  """Combine consecutive objects across years into one fact.

  Args:
    facts: A list of fact tuples.

  Returns:
    a list of fact tuples with consecutive facts with the same object merged.
  """

  def _datekey(fact):
    start = _datetup2int(fact[3]) if fact[3] else 0
    end = _datetup2int(fact[4]) if fact[4] else 21000000
    return (start, end)

  # First sort by start time and then by end time.
  sorted_facts = sorted(facts, key=_datekey)
  # Merge repeated objects into one.
  out_facts = [sorted_facts[0]]
  for fact in sorted_facts[1:]:
    if (fact[2] == out_facts[-1][2] and fact[3] != fact[4] and
        out_facts[-1][3] != out_facts[-1][4]):
      out_facts[-1][4] = fact[4]
    else:
      out_facts.append(fact)
  return out_facts
Combine consecutive objects across years into one fact.

  Args:
    facts: A list of fact tuples.

  Returns:
    a list of fact tuples with consecutive facts with the same object merged.
  
language/templama/templama.py