Created
November 13, 2017 08:20
-
-
Save hiropppe/11bd94ec3fb2c331cccf6003fd14774e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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