[英]Export/convert Dialogflow agent to csv or excel file using python
如何將所有問題和答案導出到 csv 或 excel 文件?
我已將 dialogflow 代理導出到 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)
運行代碼的說明:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.