shivangibithel commited on
Commit
39ddb78
1 Parent(s): 822fdb5

Update sotab.py

Browse files
Files changed (1) hide show
  1. sotab.py +28 -2
sotab.py CHANGED
@@ -17,6 +17,8 @@ import os
17
 
18
  import datasets
19
 
 
 
20
 
21
  # Find for instance the citation on arxiv or on the dataset repo/website
22
  _CITATION = """\
@@ -99,17 +101,41 @@ class WikiTableQuestions(datasets.GeneratorBasedBuilder):
99
 
100
  def _read_table_from_file(self, table_name: str, root_dir: str):
101
  def _extract_table_content(_line: str):
102
- _vals = [_.replace("\n", " ").strip() for _ in _line.strip("\n").split("\t")]
 
103
  return _vals
104
 
105
  rows = []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  # assert ".csv" in _wtq_table_name
107
  # use the normalized table file
108
  table_name = table_name.replace(".csv", ".tsv")
109
  with open(os.path.join(root_dir, table_name), "r", encoding="utf8") as table_f:
110
  table_lines = table_f.readlines()
111
  # the first line is header
112
- header = _extract_table_content(table_lines[0])
113
  for line in table_lines[1:]:
114
  rows.append(_extract_table_content(line))
115
  return {"header": header, "rows": rows, "name": table_name}
 
17
 
18
  import datasets
19
 
20
+ import pandas as pd
21
+
22
 
23
  # Find for instance the citation on arxiv or on the dataset repo/website
24
  _CITATION = """\
 
101
 
102
  def _read_table_from_file(self, table_name: str, root_dir: str):
103
  def _extract_table_content(_line: str):
104
+ _vals =
105
+ # _vals = [_.replace("\n", " ").strip() for _ in _line.strip("\n").split("\t")]
106
  return _vals
107
 
108
  rows = []
109
+ df_gt = pd.read_csv('CTA_Test_MusicRecording.csv', encoding="utf8")
110
+ df = pd.read_json("./MusicRecording/"+df_gt.loc[i]["table_name"], compression='gzip', lines=True)
111
+ df = df.dropna().reset_index(drop=True)
112
+ correct_label = df_gt.loc[i]["label"]
113
+
114
+ if df.empty:
115
+ op = "None"
116
+ output_list.append(op)
117
+ continue
118
+
119
+ col = []
120
+ for j in range(len(df.loc[0])):
121
+ col.append("col" + str(j+1))
122
+
123
+ row = []
124
+ for index in range(len(df)):
125
+ row.append(df.loc[index, :].values.tolist())
126
+
127
+ # {"header": ["col1", "col2", "col3"], "rows": [["row11", "row12", "row13"], ["row21", "row22", "row23"]]}
128
+ table_context = {}
129
+ table_context["header"] = col
130
+ table_context["rows"] = row
131
+
132
  # assert ".csv" in _wtq_table_name
133
  # use the normalized table file
134
  table_name = table_name.replace(".csv", ".tsv")
135
  with open(os.path.join(root_dir, table_name), "r", encoding="utf8") as table_f:
136
  table_lines = table_f.readlines()
137
  # the first line is header
138
+ # header = _extract_table_content(table_lines[0])
139
  for line in table_lines[1:]:
140
  rows.append(_extract_table_content(line))
141
  return {"header": header, "rows": rows, "name": table_name}