Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hiropppe/11bd94ec3fb2c331cccf6003fd14774e to your computer and use it in GitHub Desktop.
Save hiropppe/11bd94ec3fb2c331cccf6003fd14774e to your computer and use it in GitHub Desktop.
# -*- coding:utf-8 -*-
import codecs
import json
import os
import sys
if __name__ == '__main__':
def walk_json(path):
for root, _, files in os.walk(path):
for f in files:
if f.endswith('.json'):
yield os.path.join(root, f)
for json_name in walk_json(sys.argv[1]):
speeches = []
with codecs.open(json_name, 'r', 'utf8') as json_file:
dialog_data = json.load(json_file)
turns = dialog_data['turns']
for turn in turns:
speeches.append(turn['utterance'].encode('utf8'))
if speeches:
for i in range(len(speeches) - 1):
sys.stdout.write("{:s}\n".format(speeches[i]))
sys.stderr.write("{:s}\n".format(speeches[i+1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment