File size: 10,308 Bytes
8d1b163 2ee35ff 8d1b163 39ddb78 386aedc ec08338 39ddb78 8d1b163 822fdb5 8d1b163 822fdb5 8d1b163 822fdb5 8d1b163 2ee35ff 8d1b163 2ee35ff 8d1b163 822fdb5 8d1b163 c610d58 f0682b0 acfc6f0 8d1b163 fd15dd8 8d1b163 5b4ddef 2c87312 a752839 5094fd8 4d22557 5094fd8 8d1b163 e3bbe00 8d1b163 e4da4a9 8d1b163 e4da4a9 8d1b163 f0682b0 ec08338 f0682b0 ec08338 f0682b0 0f3b578 39ddb78 a2e43c2 39ddb78 a2e43c2 b797b99 39ddb78 a2e43c2 2c87312 a2e43c2 2c87312 8d1b163 a2e43c2 0c8405f a2e43c2 c610d58 a2e43c2 02ac618 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The SOTAB dataset is a large-scale dataset for the task of column type annotation on semi-structured tables."""
import os
import datasets
import pandas as pd
import gzip
import pandas as pd
from ast import literal_eval
# Find for instance the citation on arxiv or on the dataset repo/website
_CITATION = """\
@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/} }
"""
# You can copy an official description
_DESCRIPTION = """\
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.
"""
_HOMEPAGE = "https://webdatacommons.org/structureddata/sotab/"
_LICENSE = ""
class WikiTableQuestions(datasets.GeneratorBasedBuilder):
"""The SOTAB dataset is a large-scale dataset for the task of column type annotation on semi-structured tables."""
VERSION = datasets.Version("1.0.0")
def _info(self):
features = datasets.Features(
{
# "id": datasets.Value("int32"),
"column_index": datasets.Value("string"),
"label": datasets.Value("string"),
"table": {
"header": datasets.features.Sequence(datasets.Value("string")),
"rows": datasets.features.Sequence(datasets.features.Sequence(datasets.Value("string"))),
"name": datasets.Value("string"),
},
}
)
# datasets.value -- single value
# datasets.features.Sequence -- list
return datasets.DatasetInfo(
# This is the description that will appear on the datasets page.
description=_DESCRIPTION,
# This defines the different columns of the dataset and their types
features=features, # Here we define them above because they are different between the two configurations
# If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
# supervised_keys=("sentence", "label"),
# Homepage of the dataset for documentation
homepage=_HOMEPAGE,
# License for the dataset if available
license=_LICENSE,
# Citation for the dataset
citation=_CITATION,
)
def _split_generators(self, dl_manager):
train_url = "https://data.dws.informatik.uni-mannheim.de/structureddata/sotab/CTA_Training.zip"
dev_url = "https://data.dws.informatik.uni-mannheim.de/structureddata/sotab/CTA_Validation.zip"
test_url = "https://data.dws.informatik.uni-mannheim.de/structureddata/sotab/CTA_Test.zip"
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
# 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.
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
CTA_Training = os.path.join(dl_manager.download_and_extract(train_url))
CTA_Validation = os.path.join(dl_manager.download_and_extract(dev_url))
CTA_Test = os.path.join(dl_manager.download_and_extract(test_url))
train_file = "CTA_training_gt.csv"
test_file = "CTA_test_gt.csv"
dev_file = "CTA_validation_gt.csv"
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
# These kwargs will be passed to _generate_examples
gen_kwargs={"main_filepath": os.path.join(CTA_Training, train_file), "root_dir": os.path.join(CTA_Training, "Train")},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
# These kwargs will be passed to _generate_examples
gen_kwargs={"main_filepath": os.path.join(CTA_Test, test_file), "root_dir": os.path.join(CTA_Test, "Test")},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
# These kwargs will be passed to _generate_examples
gen_kwargs={"main_filepath": os.path.join(CTA_Validation, dev_file), "root_dir": os.path.join(CTA_Validation, "Validation")},
),
]
def _read_table_from_file(self, table_name: str, root_dir: str):
# fn = os.path.join(root_dir, table_name)
# with gzip.open(fn, 'rt', encoding='UTF-8') as zipfile:
# data = [literal_eval(v.strip()) for v in zipfile]
# # create the dataframe
# df_ = pd.DataFrame(data)
df_ = pd.read_json(os.path.join(root_dir, table_name), compression='gzip', lines=True)
df_ = df_.astype(str)
col = []
for j in range(len(df_.loc[0])):
col.append("col" + str(j+1))
row = []
for index in range(len(df_)):
row.append(df_.loc[index, :].values.tolist())
# {"header": ["col1", "col2", "col3"], "rows": [["row11", "row12", "row13"], ["row21", "row22", "row23"]]}
table_content = {}
table_content["header"] = col
table_content["rows"] = row
table_content["name"] = table_name
return table_content
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(self, main_filepath, root_dir):
df = pd.read_csv(main_filepath, encoding="utf8")
df = df.astype({'table_name':'string','column_index':'string', 'label':'string'})
for ind in df.index:
# example_id = ind
table_name = df['table_name'][ind]
column_index = df['column_index'][ind]
label = df['label'][ind]
table_content = self._read_table_from_file(table_name, root_dir)
yield ind, {"column_index": column_index, "label": label, "table": table_content}
# yield {"id": example_id, "column_index": column_index, "label": label, "table": table_content}
|