phusroyal commited on
Commit
57a8f7a
·
1 Parent(s): 36ba043

Update ViHOS.py

Browse files
Files changed (1) hide show
  1. ViHOS.py +23 -7
ViHOS.py CHANGED
@@ -1,6 +1,6 @@
1
  """ViHOS - Vietnamese Hate and Offensive Spans dataset"""
2
 
3
- import pandas as pd
4
 
5
  import datasets
6
 
@@ -48,14 +48,30 @@ class ViHOS(datasets.GeneratorBasedBuilder):
48
  },
49
  )
50
  ]
51
-
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  def _generate_examples(self, filepath, split):
53
- colnames=['id', 'Content', 'Span ids']
 
 
 
54
 
55
- with open(filepath, 'r', encoding="utf-8") as f:
56
- for i, line in enumerate(f):
57
- data = pd.read_csv(f, names=colnames, header = None)
58
- yield i, data
59
 
60
  # data = pd.read_csv(filepath, colnames=colnames, header = None)
61
  # yield data.iloc[:, 0], dataframe.iloc[:, 1], dataframe.iloc[:, 2]
 
1
  """ViHOS - Vietnamese Hate and Offensive Spans dataset"""
2
 
3
+ from csv import reader
4
 
5
  import datasets
6
 
 
48
  },
49
  )
50
  ]
51
+ def load_csv(filename):
52
+ data = list()
53
+ # Open file in read mode
54
+ file = open(filename,"r")
55
+ # Reading file
56
+ lines = reader(file)
57
+ csv_reader = reader(file)
58
+ for row in csv_reader:
59
+ if not row:
60
+ continue
61
+ data.append(row)
62
+
63
+ return data
64
+
65
  def _generate_examples(self, filepath, split):
66
+ # colnames=['id', 'Content', 'Span ids']
67
+
68
+ data = load_csv(filepath)
69
+ yield data
70
 
71
+ # with open(filepath, 'r', encoding="utf-8") as f:
72
+ # for i, line in enumerate(f):
73
+ # data = pd.read_csv(f, names=colnames, header = None)
74
+ # yield i, data
75
 
76
  # data = pd.read_csv(filepath, colnames=colnames, header = None)
77
  # yield data.iloc[:, 0], dataframe.iloc[:, 1], dataframe.iloc[:, 2]