shivangibithel commited on
Commit
49066ef
1 Parent(s): fb7e9df

Update SOTAB.py

Browse files
Files changed (1) hide show
  1. SOTAB.py +195 -80
SOTAB.py CHANGED
@@ -1,47 +1,50 @@
1
- # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- """The SOTAB dataset is a large-scale dataset for the task of column type annotation on semi-structured tables."""
15
-
16
  import os
17
- import datasets
18
- import pandas as pd
19
- import gzip
20
  import pandas as pd
21
- from ast import literal_eval
22
 
 
23
 
24
  # Find for instance the citation on arxiv or on the dataset repo/website
25
- _CITATION = """\
26
- @inproceedings{madoc63868, pages = {14--19}, booktitle = {SemTab 2022 : Proceedings of the Semantic Web Challenge on Tabular Data to Knowledge Graph Matching, co-located with the 21st International semantic Web Conference (ISWC 2022), virtual conference, October 23-27, 2022}, address = {Aachen, Germany}, editor = {Vasilis Efthymiou and Ernesto Jim{\'e}nez-Ruiz and Jiaoyan Chen and Vincenzo Cutrona and Oktie Hassanzadeh and Juan Sequeda and Kavitha Srinivas and Nora Abdelmageed and Madelon Hulsebos}, journal = {CEUR Workshop Proceedings}, year = {2022}, title = {SOTAB: The WDC Schema.org table annotation benchmark}, publisher = {RWTH Aachen}, language = {Englisch}, author = {Keti Korini and Ralph Peeters and Christian Bizer}, volume = {3320}, abstract = {Understanding the semantics of table elements is a prerequisite for many data integration and data discovery tasks. Table annotation is the task of labeling table elements with terms from a given vocabulary. This paper presents the WDC Schema.org Table Annotation Benchmark (SOTAB) for comparing the performance of table annotation systems. SOTAB covers the column type annotation (CTA) and columns property annotation (CPA) tasks. SOTAB provides {$\sim$}50,000 annotated tables for each of the tasks containing Schema.org data from different websites. The tables cover 17 different types of entities such as movie, event, local business, recipe, job posting, or product. The tables stem from the WDC Schema.org Table Corpus which was created by extracting Schema.org annotations from the Common Crawl. Consequently, the labels used for annotating columns in SOTAB are part of the Schema.org vocabulary. The benchmark covers 91 types for CTA and 176 properties for CPA distributed across textual, numerical and date/time columns. The tables are split into fixed training, validation and test sets. The test sets are further divided into subsets focusing on specific challenges, such as columns with missing values or different value formats, in order to allow a more fine-grained comparison of annotation systems. The evaluation of SOTAB using Doduo and TURL shows that the benchmark is difficult to solve for current state-of-the-art systems.}, url = {https://madoc.bib.uni-mannheim.de/63868/} }
27
- """
28
 
29
- # You can copy an official description
30
- _DESCRIPTION = """\
31
- Understanding the semantics of table elements is a prerequisite for many data integration and data discovery tasks. Table annotation is the task of labeling table elements with terms from a given vocabulary. This paper presents the WDC Schema.org Table Annotation Benchmark (SOTAB) for comparing the performance of table annotation systems. SOTAB covers the column type annotation (CTA) and columns property annotation (CPA) tasks. SOTAB provides ∼50,000 annotated tables for each of the tasks containing Schema.org data from different websites. The tables cover 17 different types of entities such as movie, event, local business, recipe, job posting, or product. The tables stem from the WDC Schema.org Table Corpus which was created by extracting Schema.org annotations from the Common Crawl. Consequently, the labels used for annotating columns in SOTAB are part of the Schema.org vocabulary. The benchmark covers 91 types for CTA and 176 properties for CPA distributed across textual, numerical and date/time columns. The tables are split into fixed training, validation and test sets. The test sets are further divided into subsets focusing on specific challenges, such as columns with missing values or different value formats, in order to allow a more fine-grained comparison of annotation systems. The evaluation of SOTAB using Doduo and TURL shows that the benchmark is difficult to solve for current state-of-the-art systems.
32
- """
33
 
34
- _HOMEPAGE = "https://webdatacommons.org/structureddata/sotab/"
35
 
36
- _LICENSE = ""
37
 
38
- class SOTAB(datasets.GeneratorBasedBuilder):
39
- """The SOTAB dataset is a large-scale dataset for the task of column type annotation on semi-structured tables."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
- VERSION = datasets.Version("1.0.0")
 
 
 
 
42
 
43
  def _info(self):
44
- features = datasets.Features(
 
 
45
  {
46
  # "id": datasets.Value("int32"),
47
  "column_index": datasets.Value("string"),
@@ -52,28 +55,15 @@ class SOTAB(datasets.GeneratorBasedBuilder):
52
  "name": datasets.Value("string"),
53
  },
54
  }
55
- )
56
-
57
- # datasets.value -- single value
58
- # datasets.features.Sequence -- list
59
-
60
- return datasets.DatasetInfo(
61
- # This is the description that will appear on the datasets page.
62
- description=_DESCRIPTION,
63
- # This defines the different columns of the dataset and their types
64
- features=features, # Here we define them above because they are different between the two configurations
65
- # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
66
- # specify them. They'll be used if as_supervised=True in builder.as_dataset.
67
- # supervised_keys=("sentence", "label"),
68
- # Homepage of the dataset for documentation
69
  homepage=_HOMEPAGE,
70
- # License for the dataset if available
71
  license=_LICENSE,
72
- # Citation for the dataset
73
  citation=_CITATION,
74
  )
75
 
76
  def _split_generators(self, dl_manager):
 
77
  train_url = "https://data.dws.informatik.uni-mannheim.de/structureddata/sotab/CTA_Training.zip"
78
  dev_url = "https://data.dws.informatik.uni-mannheim.de/structureddata/sotab/CTA_Validation.zip"
79
  test_url = "https://data.dws.informatik.uni-mannheim.de/structureddata/sotab/CTA_Test.zip"
@@ -108,44 +98,169 @@ class SOTAB(datasets.GeneratorBasedBuilder):
108
  ),
109
  ]
110
 
111
- def _read_table_from_file(self, table_name: str, root_dir: str):
112
- # fn = os.path.join(root_dir, table_name)
113
- # with gzip.open(fn, 'rt', encoding='UTF-8') as zipfile:
114
- # data = [literal_eval(v.strip()) for v in zipfile]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
 
116
- # # create the dataframe
117
- # df_ = pd.DataFrame(data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
- df_ = pd.read_json(os.path.join(root_dir, table_name), compression='gzip', lines=True)
120
- df_ = df_.astype(str)
 
 
121
 
122
- col = []
123
- for j in range(len(df_.loc[0])):
124
- col.append("col" + str(j+1))
125
 
126
- row = []
127
- for index in range(len(df_)):
128
- row.append(df_.loc[index, :].values.tolist())
 
 
 
129
 
130
- # {"header": ["col1", "col2", "col3"], "rows": [["row11", "row12", "row13"], ["row21", "row22", "row23"]]}
 
 
 
 
131
 
132
- table_content = {}
133
- table_content["header"] = col
134
- table_content["rows"] = row
135
- table_content["name"] = table_name
136
 
137
- return table_content
138
 
139
- # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
140
- def _generate_examples(self, main_filepath, root_dir):
141
 
142
- df = pd.read_csv(main_filepath, encoding="utf8")
143
- df = df.astype({'table_name':'string','column_index':'string', 'label':'string'})
144
- for ind in df.index:
145
- # example_id = ind
146
- table_name = df['table_name'][ind]
147
- column_index = df['column_index'][ind]
148
- label = df['label'][ind]
149
- table_content = self._read_table_from_file(table_name, root_dir)
150
- yield ind, {"column_index": column_index, "label": label, "table": table_content}
151
- # yield {"id": example_id, "column_index": column_index, "label": label, "table": table_content}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
 
 
 
2
  import pandas as pd
 
3
 
4
+ import datasets
5
 
6
  # Find for instance the citation on arxiv or on the dataset repo/website
7
+ _CITATION = """"""
 
 
8
 
9
+ _DESCRIPTION = """"""
 
 
 
10
 
11
+ _HOMEPAGE = ""
12
 
13
+ _LICENSE = "CC-BY-SA-4.0 License"
14
 
15
+ _URL = ""
16
+
17
+
18
+
19
+ def _read_table_from_file(table_name: str, root_dir: str)-> dict:
20
+ df_ = pd.read_json(os.path.join(root_dir, table_name), compression='gzip', lines=True)
21
+ df_ = df_.astype(str)
22
+
23
+ col = []
24
+ for j in range(len(df_.loc[0])):
25
+ col.append("col" + str(j+1))
26
+
27
+ row = []
28
+ for index in range(len(df_)):
29
+ row.append(df_.loc[index, :].values.tolist())
30
+
31
+ # {"header": ["col1", "col2", "col3"], "rows": [["row11", "row12", "row13"], ["row21", "row22", "row23"]]}
32
+
33
+ table_content = {}
34
+ table_content["header"] = col
35
+ table_content["rows"] = row
36
+ table_content["name"] = table_name
37
 
38
+ return table_content
39
+
40
+
41
+ class SOTAB(datasets.GeneratorBasedBuilder):
42
+ """The sotab dataset"""
43
 
44
  def _info(self):
45
+ return datasets.DatasetInfo(
46
+ description=_DESCRIPTION,
47
+ features = datasets.Features(
48
  {
49
  # "id": datasets.Value("int32"),
50
  "column_index": datasets.Value("string"),
 
55
  "name": datasets.Value("string"),
56
  },
57
  }
58
+ ),
59
+ supervised_keys=None,
 
 
 
 
 
 
 
 
 
 
 
 
60
  homepage=_HOMEPAGE,
 
61
  license=_LICENSE,
 
62
  citation=_CITATION,
63
  )
64
 
65
  def _split_generators(self, dl_manager):
66
+ """Returns SplitGenerators."""
67
  train_url = "https://data.dws.informatik.uni-mannheim.de/structureddata/sotab/CTA_Training.zip"
68
  dev_url = "https://data.dws.informatik.uni-mannheim.de/structureddata/sotab/CTA_Validation.zip"
69
  test_url = "https://data.dws.informatik.uni-mannheim.de/structureddata/sotab/CTA_Test.zip"
 
98
  ),
99
  ]
100
 
101
+ def _generate_examples(self, main_filepath, root_dir):
102
+ with open(main_filepath, encoding="utf-8") as f:
103
+ for idx, line in enumerate(f):
104
+ # skip the header
105
+ if idx == 0:
106
+ continue
107
+ if idx == 100:
108
+ break
109
+ table_name, column_index, label = line.strip("\n").split(",")
110
+ yield idx, {
111
+ "column_index": column_index,
112
+ "label": label,
113
+ "table": _read_table_from_file(table_name, root_dir),
114
+ }
115
+
116
+ # # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
117
+ # #
118
+ # # Licensed under the Apache License, Version 2.0 (the "License");
119
+ # # you may not use this file except in compliance with the License.
120
+ # # You may obtain a copy of the License at
121
+ # #
122
+ # # http://www.apache.org/licenses/LICENSE-2.0
123
+ # #
124
+ # # Unless required by applicable law or agreed to in writing, software
125
+ # # distributed under the License is distributed on an "AS IS" BASIS,
126
+ # # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127
+ # # See the License for the specific language governing permissions and
128
+ # # limitations under the License.
129
+ # """The SOTAB dataset is a large-scale dataset for the task of column type annotation on semi-structured tables."""
130
+
131
+ # import os
132
+ # import datasets
133
+ # import pandas as pd
134
+ # import gzip
135
+ # import pandas as pd
136
+ # from ast import literal_eval
137
+
138
+
139
+ # # Find for instance the citation on arxiv or on the dataset repo/website
140
+ # _CITATION = """\
141
+ # @inproceedings{madoc63868, pages = {14--19}, booktitle = {SemTab 2022 : Proceedings of the Semantic Web Challenge on Tabular Data to Knowledge Graph Matching, co-located with the 21st International semantic Web Conference (ISWC 2022), virtual conference, October 23-27, 2022}, address = {Aachen, Germany}, editor = {Vasilis Efthymiou and Ernesto Jim{\'e}nez-Ruiz and Jiaoyan Chen and Vincenzo Cutrona and Oktie Hassanzadeh and Juan Sequeda and Kavitha Srinivas and Nora Abdelmageed and Madelon Hulsebos}, journal = {CEUR Workshop Proceedings}, year = {2022}, title = {SOTAB: The WDC Schema.org table annotation benchmark}, publisher = {RWTH Aachen}, language = {Englisch}, author = {Keti Korini and Ralph Peeters and Christian Bizer}, volume = {3320}, abstract = {Understanding the semantics of table elements is a prerequisite for many data integration and data discovery tasks. Table annotation is the task of labeling table elements with terms from a given vocabulary. This paper presents the WDC Schema.org Table Annotation Benchmark (SOTAB) for comparing the performance of table annotation systems. SOTAB covers the column type annotation (CTA) and columns property annotation (CPA) tasks. SOTAB provides {$\sim$}50,000 annotated tables for each of the tasks containing Schema.org data from different websites. The tables cover 17 different types of entities such as movie, event, local business, recipe, job posting, or product. The tables stem from the WDC Schema.org Table Corpus which was created by extracting Schema.org annotations from the Common Crawl. Consequently, the labels used for annotating columns in SOTAB are part of the Schema.org vocabulary. The benchmark covers 91 types for CTA and 176 properties for CPA distributed across textual, numerical and date/time columns. The tables are split into fixed training, validation and test sets. The test sets are further divided into subsets focusing on specific challenges, such as columns with missing values or different value formats, in order to allow a more fine-grained comparison of annotation systems. The evaluation of SOTAB using Doduo and TURL shows that the benchmark is difficult to solve for current state-of-the-art systems.}, url = {https://madoc.bib.uni-mannheim.de/63868/} }
142
+ # """
143
+
144
+ # # You can copy an official description
145
+ # _DESCRIPTION = """\
146
+ # Understanding the semantics of table elements is a prerequisite for many data integration and data discovery tasks. Table annotation is the task of labeling table elements with terms from a given vocabulary. This paper presents the WDC Schema.org Table Annotation Benchmark (SOTAB) for comparing the performance of table annotation systems. SOTAB covers the column type annotation (CTA) and columns property annotation (CPA) tasks. SOTAB provides ∼50,000 annotated tables for each of the tasks containing Schema.org data from different websites. The tables cover 17 different types of entities such as movie, event, local business, recipe, job posting, or product. The tables stem from the WDC Schema.org Table Corpus which was created by extracting Schema.org annotations from the Common Crawl. Consequently, the labels used for annotating columns in SOTAB are part of the Schema.org vocabulary. The benchmark covers 91 types for CTA and 176 properties for CPA distributed across textual, numerical and date/time columns. The tables are split into fixed training, validation and test sets. The test sets are further divided into subsets focusing on specific challenges, such as columns with missing values or different value formats, in order to allow a more fine-grained comparison of annotation systems. The evaluation of SOTAB using Doduo and TURL shows that the benchmark is difficult to solve for current state-of-the-art systems.
147
+ # """
148
+
149
+ # _HOMEPAGE = "https://webdatacommons.org/structureddata/sotab/"
150
+
151
+ # _LICENSE = ""
152
+
153
+ # class SOTAB(datasets.GeneratorBasedBuilder):
154
+ # """The SOTAB dataset is a large-scale dataset for the task of column type annotation on semi-structured tables."""
155
+
156
+ # VERSION = datasets.Version("1.0.0")
157
+
158
+ # def _info(self):
159
+ # features = datasets.Features(
160
+ # {
161
+ # # "id": datasets.Value("int32"),
162
+ # "column_index": datasets.Value("string"),
163
+ # "label": datasets.Value("string"),
164
+ # "table": {
165
+ # "header": datasets.features.Sequence(datasets.Value("string")),
166
+ # "rows": datasets.features.Sequence(datasets.features.Sequence(datasets.Value("string"))),
167
+ # "name": datasets.Value("string"),
168
+ # },
169
+ # }
170
+ # )
171
+
172
+ # # datasets.value -- single value
173
+ # # datasets.features.Sequence -- list
174
+
175
+ # return datasets.DatasetInfo(
176
+ # # This is the description that will appear on the datasets page.
177
+ # description=_DESCRIPTION,
178
+ # # This defines the different columns of the dataset and their types
179
+ # features=features, # Here we define them above because they are different between the two configurations
180
+ # # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
181
+ # # specify them. They'll be used if as_supervised=True in builder.as_dataset.
182
+ # # supervised_keys=("sentence", "label"),
183
+ # # Homepage of the dataset for documentation
184
+ # homepage=_HOMEPAGE,
185
+ # # License for the dataset if available
186
+ # license=_LICENSE,
187
+ # # Citation for the dataset
188
+ # citation=_CITATION,
189
+ # )
190
+
191
+ # def _split_generators(self, dl_manager):
192
+ # train_url = "https://data.dws.informatik.uni-mannheim.de/structureddata/sotab/CTA_Training.zip"
193
+ # dev_url = "https://data.dws.informatik.uni-mannheim.de/structureddata/sotab/CTA_Validation.zip"
194
+ # test_url = "https://data.dws.informatik.uni-mannheim.de/structureddata/sotab/CTA_Test.zip"
195
+
196
+ # # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
197
+ # # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
198
+ # # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
199
+
200
+ # CTA_Training = os.path.join(dl_manager.download_and_extract(train_url))
201
+ # CTA_Validation = os.path.join(dl_manager.download_and_extract(dev_url))
202
+ # CTA_Test = os.path.join(dl_manager.download_and_extract(test_url))
203
+
204
+ # train_file = "CTA_training_gt.csv"
205
+ # test_file = "CTA_test_gt.csv"
206
+ # dev_file = "CTA_validation_gt.csv"
207
 
208
+ # return [
209
+ # datasets.SplitGenerator(
210
+ # name=datasets.Split.TRAIN,
211
+ # # These kwargs will be passed to _generate_examples
212
+ # gen_kwargs={"main_filepath": os.path.join(CTA_Training, train_file), "root_dir": os.path.join(CTA_Training, "Train")},
213
+ # ),
214
+ # datasets.SplitGenerator(
215
+ # name=datasets.Split.TEST,
216
+ # # These kwargs will be passed to _generate_examples
217
+ # gen_kwargs={"main_filepath": os.path.join(CTA_Test, test_file), "root_dir": os.path.join(CTA_Test, "Test")},
218
+ # ),
219
+ # datasets.SplitGenerator(
220
+ # name=datasets.Split.VALIDATION,
221
+ # # These kwargs will be passed to _generate_examples
222
+ # gen_kwargs={"main_filepath": os.path.join(CTA_Validation, dev_file), "root_dir": os.path.join(CTA_Validation, "Validation")},
223
+ # ),
224
+ # ]
225
 
226
+ # def _read_table_from_file(self, table_name: str, root_dir: str):
227
+ # # fn = os.path.join(root_dir, table_name)
228
+ # # with gzip.open(fn, 'rt', encoding='UTF-8') as zipfile:
229
+ # # data = [literal_eval(v.strip()) for v in zipfile]
230
 
231
+ # # # create the dataframe
232
+ # # df_ = pd.DataFrame(data)
 
233
 
234
+ # df_ = pd.read_json(os.path.join(root_dir, table_name), compression='gzip', lines=True)
235
+ # df_ = df_.astype(str)
236
+
237
+ # col = []
238
+ # for j in range(len(df_.loc[0])):
239
+ # col.append("col" + str(j+1))
240
 
241
+ # row = []
242
+ # for index in range(len(df_)):
243
+ # row.append(df_.loc[index, :].values.tolist())
244
+
245
+ # # {"header": ["col1", "col2", "col3"], "rows": [["row11", "row12", "row13"], ["row21", "row22", "row23"]]}
246
 
247
+ # table_content = {}
248
+ # table_content["header"] = col
249
+ # table_content["rows"] = row
250
+ # table_content["name"] = table_name
251
 
252
+ # return table_content
253
 
254
+ # # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
255
+ # def _generate_examples(self, main_filepath, root_dir):
256
 
257
+ # df = pd.read_csv(main_filepath, encoding="utf8")
258
+ # df = df.astype({'table_name':'string','column_index':'string', 'label':'string'})
259
+ # for ind in df.index:
260
+ # # example_id = ind
261
+ # table_name = df['table_name'][ind]
262
+ # column_index = df['column_index'][ind]
263
+ # label = df['label'][ind]
264
+ # table_content = self._read_table_from_file(table_name, root_dir)
265
+ # yield ind, {"column_index": column_index, "label": label, "table": table_content}
266
+ # # yield {"id": example_id, "column_index": column_index, "label": label, "table": table_content}