def compute_spider_coverage(spider_examples_json, spider_tables_json):
  """Prints out statistics for asql conversions."""
  table_json = _load_json(spider_tables_json)
  # Map of database id to a list of ForiegnKeyRelation tuples.
  foreign_key_map = abstract_sql_converters.spider_foreign_keys_map(table_json)
  table_schema_map = abstract_sql_converters.spider_table_schemas_map(
      table_json)
  examples = _load_json(spider_examples_json)
  num_examples = 0
  num_conversion_failures = 0
  num_reconstruction_failtures = 0
  for example in examples:
    num_examples += 1
    print('Parsing example number %s: %s' % (num_examples, example['query']))
    gold_sql_query = example['query']
    foreign_keys = foreign_key_map[example['db_id']]
    table_schema = table_schema_map[example['db_id']]
    try:
      sql_spans = abstract_sql.sql_to_sql_spans(gold_sql_query, table_schema)
      sql_spans = abstract_sql.replace_from_clause(sql_spans)
    except abstract_sql.UnsupportedSqlError as e:
      print('Error converting:\n%s\n%s' % (gold_sql_query, e))
      num_conversion_failures += 1
    else:
      try:
        sql_spans = abstract_sql.restore_from_clause(sql_spans, foreign_keys)
      except abstract_sql.UnsupportedSqlError as e:
        print('Error recontructing:\n%s\n%s' % (gold_sql_query, e))
        num_reconstruction_failtures += 1
  print('Examples: %s' % num_examples)
  print('Failed conversions: %s' % num_conversion_failures)
  print('Failed reconstructions: %s' % num_reconstruction_failtures)
Prints out statistics for asql conversions.
language/xsp/data_preprocessing/compute_asql_coverage_spider.py