import xml.etree.ElementTree as ET import pandas as pd # Step 1: Parse XML def xml_to_list(filepath): tree = ET.parse(filepath) root = tree.getroot() data = [] for sentence in root.findall("sentence"): sentence_id = sentence.get("ID") text = sentence.find("text").text aspect_terms = [] for aspect_term in sentence.findall("./aspectTerms/aspectTerm"): aspect_terms.append({ "term": aspect_term.get("term"), "polarity": aspect_term.get("polarity"), "from": int(aspect_term.get("from")), "to": int(aspect_term.get("to")), }) aspect_categories = [] for aspect_category in sentence.findall("./aspectCategories/aspectCategory"): aspect_categories.append({ "category": aspect_category.get("category"), "polarity": aspect_category.get("polarity"), }) data.append({ "sentence_id": sentence_id, "text": text, "aspect_terms": aspect_terms, "aspect_categories": aspect_categories, }) return data xml_data = xml_to_list("absa_uz_all.xml") # Step 2: Convert to DataFrame df = pd.DataFrame(xml_data) # Step 3: Save as Parquet df.to_parquet("../aspect-based-sentiment-analysis-uzbek.parquet", index=False)