Created
March 23, 2019 12:28
-
-
Save shubham0204/f1fdad7a910fe17064752affaef474cb 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
import os | |
import yaml | |
dir_path = 'raw_data' | |
files_list = os.listdir(dir_path + os.sep) | |
questions = list() | |
answers = list() | |
for filepath in files_list: | |
stream = open( dir_path + os.sep + filepath , 'rb') | |
docs = yaml.safe_load(stream) | |
conversations = docs['conversations'] | |
for con in conversations: | |
if len( con ) > 2 : | |
questions.append(con[0]) | |
replies = con[ 1 : ] | |
ans = '' | |
for rep in replies: | |
ans += ' ' + rep | |
answers.append( ans ) | |
elif len( con )> 1: | |
questions.append(con[0]) | |
answers.append(con[1]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment