Sanatbek_Matlatipov commited on
Commit
7d27e01
·
1 Parent(s): 22c9353

Parquet file is added. XML TO PARQUET COnverter is added

Browse files
aspect-based-sentiment-analysis-uzbek.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e1b826d220907f9ec5ea83897b2e0b9d6af308699dcd6d690a4355942583394a
3
+ size 330250
data/xml_to_parquet.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import xml.etree.ElementTree as ET
2
+ import pandas as pd
3
+
4
+
5
+ # Step 1: Parse XML
6
+ def xml_to_list(filepath):
7
+ tree = ET.parse(filepath)
8
+ root = tree.getroot()
9
+
10
+ data = []
11
+ for sentence in root.findall("sentence"):
12
+ sentence_id = sentence.get("ID")
13
+ text = sentence.find("text").text
14
+
15
+ aspect_terms = []
16
+ for aspect_term in sentence.findall("./aspectTerms/aspectTerm"):
17
+ aspect_terms.append({
18
+ "term": aspect_term.get("term"),
19
+ "polarity": aspect_term.get("polarity"),
20
+ "from": int(aspect_term.get("from")),
21
+ "to": int(aspect_term.get("to")),
22
+ })
23
+
24
+ aspect_categories = []
25
+ for aspect_category in sentence.findall("./aspectCategories/aspectCategory"):
26
+ aspect_categories.append({
27
+ "category": aspect_category.get("category"),
28
+ "polarity": aspect_category.get("polarity"),
29
+ })
30
+
31
+ data.append({
32
+ "sentence_id": sentence_id,
33
+ "text": text,
34
+ "aspect_terms": aspect_terms,
35
+ "aspect_categories": aspect_categories,
36
+ })
37
+ return data
38
+
39
+
40
+ xml_data = xml_to_list("absa_uz_all.xml")
41
+
42
+ # Step 2: Convert to DataFrame
43
+ df = pd.DataFrame(xml_data)
44
+
45
+ # Step 3: Save as Parquet
46
+ df.to_parquet("../aspect-based-sentiment-analysis-uzbek.parquet", index=False)