File size: 972 Bytes
0416ac9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import csv 
import xml.etree.ElementTree as ET 
import glob, os

rootFolder = "c:/317"

file = open(rootFolder + "/result.csv", "w", encoding="utf-8")
file.write("prompt,text,rejected_text\n")

def parseXML(xmlFile):

    prompt = xmlFile.replace("Using_", "").replace(".xml", "").replace(".", " ").replace("_", " ")
    text  = ""

    try:
        tree = ET.parse(rootFolder + "/" + xmlFile)
        root = tree.getroot()

        for item in root.findall(".//text"):
            text += item.text

        if text.find("а") == -1:
            #file.write("### prompt\n")
            file.write(prompt + "," + text.replace(",", " ") + "\n")
            #file.write("### text\n")
            #file.write(text.replace(",", " "))

    except:
        print("=======")


os.chdir(rootFolder)
for xmlFile in glob.glob("*.xml"):
    print(xmlFile)
    parseXML(xmlFile)


## parseXML('Using_WinRT_Viewer.Search_Panel.xml')

file.close()