Sanatbek_Matlatipov commited on
Commit
0f86d75
1 Parent(s): 4747b67

changed the GeneratorBasedBuilder

Browse files
aspect-based-sentiment-analysis-uzbek.py CHANGED
@@ -2,22 +2,18 @@ import os
2
  import xml.etree.ElementTree as ET
3
 
4
  import datasets
5
- from datasets import Features, Value, Sequence, DatasetInfo
6
 
7
 
8
- class UZABSAConfig(datasets.BuilderConfig):
9
- def __init__(self, **kwargs):
10
- super(UZABSAConfig, self).__init__(version="1.0.0", **kwargs)
11
 
12
-
13
- class UzABSA(datasets.DatasetBuilder):
14
- BUILDER_CONFIG_CLASS = UZABSAConfig
15
  BUILDER_CONFIGS = [
16
- UZABSAConfig(name="uzabsa", description="Uzbek ABSA data"),
 
17
  ]
18
 
19
  def _info(self):
20
- # Define the data features
21
  return DatasetInfo(
22
  features=Features({
23
  "sentence_id": Value("string"),
@@ -36,15 +32,9 @@ class UzABSA(datasets.DatasetBuilder):
36
  )
37
 
38
  def _split_generators(self, dl_manager):
39
- # Use os.path.join to find the XML file path
40
- filepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "data/absa_uz_all.xml")
41
  return [
42
- datasets.SplitGenerator(
43
- name=datasets.Split.TRAIN,
44
- gen_kwargs={
45
- "filepath": filepath,
46
- },
47
- ),
48
  ]
49
 
50
  def _generate_examples(self, filepath):
@@ -52,32 +42,28 @@ class UzABSA(datasets.DatasetBuilder):
52
  root = tree.getroot()
53
 
54
  for sentence in root.findall("sentence"):
55
- sentence_id = sentence.attrib["ID"]
56
  text = sentence.find("text").text
57
 
58
  aspect_terms = []
59
- for aspect_term in sentence.findall(".//aspectTerms/aspectTerm"):
60
- aspect_terms.append(
61
- {
62
- "term": aspect_term.attrib["term"],
63
- "polarity": aspect_term.attrib["polarity"],
64
- "from": int(aspect_term.attrib["from"]),
65
- "to": int(aspect_term.attrib["to"]),
66
- }
67
- )
68
 
69
  aspect_categories = []
70
- for aspect_category in sentence.findall(".//aspectCategories/aspectCategory"):
71
- aspect_categories.append(
72
- {
73
- "category": aspect_category.attrib["category"],
74
- "polarity": aspect_category.attrib["polarity"],
75
- }
76
- )
77
 
78
  yield sentence_id, {
79
  "sentence_id": sentence_id,
80
  "text": text,
81
  "aspect_terms": aspect_terms,
82
  "aspect_categories": aspect_categories,
83
- }
 
2
  import xml.etree.ElementTree as ET
3
 
4
  import datasets
5
+ from datasets import GeneratorBasedBuilder, DatasetInfo, Split, SplitGenerator, Features, Value, Sequence
6
 
7
 
8
+ class UzABSA(GeneratorBasedBuilder):
9
+ VERSION = datasets.Version("1.0.0")
 
10
 
 
 
 
11
  BUILDER_CONFIGS = [
12
+ datasets.BuilderConfig(name="uzabsa", version=VERSION,
13
+ description="UZABSA dataset for sentiment analysis in Uzbek"),
14
  ]
15
 
16
  def _info(self):
 
17
  return DatasetInfo(
18
  features=Features({
19
  "sentence_id": Value("string"),
 
32
  )
33
 
34
  def _split_generators(self, dl_manager):
35
+ filepath = os.path.join(self.config.data_dir, "/datasets/uzabsa_all.xml")
 
36
  return [
37
+ SplitGenerator(name=Split.TRAIN, gen_kwargs={"filepath": filepath}),
 
 
 
 
 
38
  ]
39
 
40
  def _generate_examples(self, filepath):
 
42
  root = tree.getroot()
43
 
44
  for sentence in root.findall("sentence"):
45
+ sentence_id = sentence.get("ID")
46
  text = sentence.find("text").text
47
 
48
  aspect_terms = []
49
+ for aspect_term in sentence.findall("./aspectTerms/aspectTerm"):
50
+ aspect_terms.append({
51
+ "term": aspect_term.get("term"),
52
+ "polarity": aspect_term.get("polarity"),
53
+ "from": int(aspect_term.get("from")),
54
+ "to": int(aspect_term.get("to")),
55
+ })
 
 
56
 
57
  aspect_categories = []
58
+ for aspect_category in sentence.findall("./aspectCategories/aspectCategory"):
59
+ aspect_categories.append({
60
+ "category": aspect_category.get("category"),
61
+ "polarity": aspect_category.get("polarity"),
62
+ })
 
 
63
 
64
  yield sentence_id, {
65
  "sentence_id": sentence_id,
66
  "text": text,
67
  "aspect_terms": aspect_terms,
68
  "aspect_categories": aspect_categories,
69
+ }