def process_dbs(raw_dbs):
  """Converts database specification directly from Spider to our format."""
  dbs = dict()

  # Should return a list of databases, each which is a dictionary whose keys are
  # table names, and values are columns; columns have 'field name',
  # 'is foreign key', 'is primary key', and 'type' annotations.
  for db in raw_dbs:
    db_dict = dict()
    for table in db['table_names_original']:
      db_dict[table] = list()
    all_foreign_indices = \
      set([k[0] for k in db['foreign_keys']]
          + [k[1] for k in db['foreign_keys']])
    for global_column_idx, (table_idx, column_name) in \
        enumerate(db['column_names_original']):
      if table_idx >= 0:
        is_primary_key = global_column_idx in db['primary_keys']
        is_foreign_key = global_column_idx in all_foreign_indices
        column_dict = {
            'field name': column_name,
            'is primary key': is_primary_key,
            'is foreign key': is_foreign_key,
            'type': db['column_types'][global_column_idx]
        }
        db_dict[db['table_names_original'][table_idx]].append(column_dict)
    dbs[db['db_id']] = db_dict
  return dbs
Converts database specification directly from Spider to our format.
language/xsp/data_preprocessing/spider_preprocessing.py