parent
3fe33ab51a
commit
0577f982a2
@ -0,0 +1,19 @@
|
||||
import csv
|
||||
from utils.models import DataInstance
|
||||
|
||||
|
||||
def read_csv_file(csv_file_path, delimiter='\t'):
|
||||
"""
|
||||
This function takes file path as an argument, reads the data file and
|
||||
returns a list of DataInstance objects with text and true labels
|
||||
|
||||
:param delimiter: Delimiter for the file. Default is Tab(\t)
|
||||
:param csv_file_path: path to the TSV/CSV file
|
||||
:return: returns a list of DataInstance class objects. <utils.models.DataInstance>
|
||||
"""
|
||||
with open(csv_file_path, 'r') as file:
|
||||
file_data = csv.reader(file, delimiter=delimiter)
|
||||
data = []
|
||||
for row in file_data:
|
||||
data.append(DataInstance(row[0], row[2], row[3]))
|
||||
return data
|
||||
@ -0,0 +1,13 @@
|
||||
|
||||
class DataInstance:
|
||||
"""
|
||||
Model Class for carrying Training and Testing data from tsc/csv file
|
||||
"""
|
||||
|
||||
def __init__(self, r_id, text, true_label):
|
||||
self.did = r_id
|
||||
self.text = text
|
||||
self.true_label = true_label
|
||||
|
||||
def print(self):
|
||||
print('True Label :: ', self.true_label, ' Text :: ', self.text)
|
||||
Loading…
Reference in new issue