def col_tab_f1(schema, gold_query, predicted_query):
  """Computes the F1 of tables and columns mentioned in the two queries."""

  # Get the schema entities.
  db_columns = set()
  db_tables = set()
  for name, cols in schema.items():
    for col in cols:
      db_columns.add(col['field name'].lower())
    db_tables.add(name.lower())

  # Heuristically find the entities used in the gold and predicted queries.
  pred_columns, pred_tables = find_used_entities_in_string(
      predicted_query, db_columns, db_tables)
  gold_columns, gold_tables = find_used_entities_in_string(
      gold_query, db_columns, db_tables)

  # Compute and return column and table F1.
  return (compute_set_f1(pred_columns,
                         gold_columns), compute_set_f1(pred_tables,
                                                       gold_tables))
Computes the F1 of tables and columns mentioned in the two queries.
language/xsp/evaluation/official_evaluation.py