def convert_tsv_to_json(infn, outfn, col=1, answers=None):
  """convert data format for queries and filter queries without answers."""
  data = {}
  fns = infn.split(',')
  for fn in fns:
    for line in open(fn):
      elements = line.split('\t')
      if answers:
        if elements[0] not in answers:
          continue
      if elements[0] not in data:
        data[elements[0]] = elements[col]
      else:
        data[elements[0]] = data[elements[0]] + '\n' + elements[col]

  with open(outfn, 'w') as outfile:
    json.dump(data, outfile)
  print('Processed: ' + infn)
  print('Output to: ' + outfn)
  print('Number of entries: ' + str(len(data)))
  return data
convert data format for queries and filter queries without answers.
language/multivec/utils/convert_tsv_to_json.py