모든 질문과 답변을 CSV 또는 Excel 파일로 내보내는 방법은 무엇입니까?
대화 흐름 에이전트를 zip 파일로 내 보냈고 각 질문 또는 의도에 대해 두 개의 json 파일을 얻었습니다.
CSV 또는 Excel 파일에서 질문 및 답변 쌍을 만드는 방법이 있습니까?
zip 파일에는 두 개의 디렉토리 인 텐트 및 엔티티가 포함됩니다. 인 텐트 디렉터리에는 Dialogflow 각 인 텐트의 응답 및 학습 문구가 포함됩니다. JSON 파일의 패턴을 관찰하고 스크립트를 작성하여 CSV 파일을 만들 수 있습니다.
import os
import csv
import json
all_intents = os.listdir('intents')
with open('agent.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["Response", "Questions"])
for intent in all_intents:
write = []
if intent.find('_usersays_en.json') == -1:
try:
with open('intents/' + intent) as f:
data = json.load(f)
resp = ''
try:
resp = data['responses'][0]['messages'][0]['speech'][0]
except:
print(intent)
write.append(resp)
except:
print(intent)
try:
with open('intents/' + intent.replace(".json", "") + '_usersays_en.json') as f:
data = json.load(f)
for d in data:
qn = (d['data'][0]['text'])
write.append(qn)
except:
print(intent.replace(".json", "") + '_usersays_en.json')
writer.writerow(write)
코드 실행 지침 :
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다