Sanatbek_Matlatipov
commited on
Commit
·
c111fdf
1
Parent(s):
ef58454
jsonL file is added. XML TO jsonl Converter is added
Browse files
aspect-based-sentiment-analysis-uzbek.jsonl
ADDED
The diff for this file is too large to render.
See raw diff
|
|
aspect-based-sentiment-analysis-uzbek1.py → data/aspect-based-sentiment-analysis-uzbek1.py
RENAMED
File without changes
|
data/xml_to_jsonl.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import xml.etree.ElementTree as ET
|
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: Save as JSONL
|
43 |
+
with open("../aspect-based-sentiment-analysis-uzbek.jsonl", "w") as outfile:
|
44 |
+
for entry in xml_data:
|
45 |
+
json_str = json.dumps(entry)
|
46 |
+
outfile.write(json_str + "\n")
|