|
import csv |
|
import json |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@article{DBLP:journals/corr/abs-2203-04860, |
|
author = {Patrizio Bellan and |
|
Han van der Aa and |
|
Mauro Dragoni and |
|
Chiara Ghidini and |
|
Simone Paolo Ponzetto}, |
|
title = {{PET:} {A} new Dataset for Process Extraction from Natural Language |
|
Text}, |
|
journal = {CoRR}, |
|
volume = {abs/2203.04860}, |
|
year = {2022}, |
|
url = {https://doi.org/10.48550/arXiv.2203.04860}, |
|
doi = {10.48550/arXiv.2203.04860}, |
|
eprinttype = {arXiv}, |
|
eprint = {2203.04860}, |
|
biburl = {https://dblp.org/rec/journals/corr/abs-2203-04860.bib} |
|
} |
|
""" |
|
|
|
|
|
_DESCRIPTION = """\ |
|
Abstract. Although there is a long tradition of work in NLP on extracting entities and relations from text, to date there exists little work on the acquisition of business processes from unstructured data such as textual corpora of process descriptions. With this work we aim at filling this gap and establishing the first steps towards bridging data-driven information extraction methodologies from Natural Language Processing and the model-based formalization that is aimed from Business Process Management. For this, we develop the first corpus of business process descriptions annotated with activities, gateways, actors and flow information. We present our new resource, including a detailed overview of the annotation schema and guidelines, as well as a variety of baselines to benchmark the difficulty and challenges of business process extraction from text. |
|
""" |
|
|
|
_HOMEPAGE = "https://pdi.fbk.eu/pet-dataset/" |
|
|
|
_LICENSE = "MIT" |
|
|
|
_URL = "https://pdi.fbk.eu/pet/PETHuggingFace/" |
|
_TEST_FILE = "test.json" |
|
_TEST_FILE_RELATIONS = 'PETrelations.json' |
|
|
|
_NER = 'token-classification' |
|
_RELATIONS_EXTRACTION = 'relations-extraction' |
|
_NER_TAGS = [ "O", |
|
"B-Actor", |
|
"I-Actor", |
|
"B-Activity", |
|
"I-Activity", |
|
"B-Activity Data", |
|
"I-Activity Data", |
|
"B-Further Specification", |
|
"I-Further Specification", |
|
"B-XOR Gateway", |
|
"I-XOR Gateway", |
|
"B-Condition Specification", |
|
"I-Condition Specification", |
|
"B-AND Gateway", |
|
"I-AND Gateway"] |
|
|
|
_STR_PET = """\n |
|
_______ _ _ _______ _____ _______ _______ ______ _______ _______ _______ _______ _______ _______ |
|
| |_____| |______ |_____] |______ | | \ |_____| | |_____| |______ |______ | |
|
| | | |______ | |______ | |_____/ | | | | | ______| |______ | |
|
|
|
Discover more at: [https://pdi.fbk.eu/pet-dataset/] |
|
""" |
|
|
|
|
|
class PETConfig(datasets.BuilderConfig): |
|
"""The PET Dataset.""" |
|
|
|
def __init__(self, **kwargs): |
|
"""BuilderConfig for PET. |
|
Args: |
|
**kwargs: keyword arguments forwarded to super. |
|
""" |
|
super(PETConfig, self).__init__(**kwargs) |
|
|
|
class PET(datasets.GeneratorBasedBuilder): |
|
"""PET DATASET.""" |
|
|
|
features_ner = { |
|
"document name": datasets.Value("string"), |
|
"sentence-ID": datasets.Value("int8"), |
|
"tokens": datasets.Sequence(datasets.Value("string")), |
|
"ner-tags": datasets.Sequence(datasets.features.ClassLabel(names=_NER_TAGS)), |
|
} |
|
|
|
features_relations = datasets.Sequence( |
|
datasets.Features( |
|
|
|
{ |
|
'source-head-sentence-ID': datasets.Value("int8"), |
|
'source-head-word-ID': datasets.Value("int8"), |
|
'relation-type': datasets.Value("string"), |
|
'target-head-sentence-ID': datasets.Value("int8"), |
|
'target-head-word-ID' : datasets.Value("int8"), |
|
} |
|
)) |
|
BUILDER_CONFIGS = [ PETConfig( |
|
name=_NER, |
|
version=datasets.Version("1.0.1"), |
|
description="The PET Dataset for Token Classification" |
|
), |
|
PETConfig( |
|
name=_RELATIONS_EXTRACTION, |
|
version=datasets.Version("1.0.1"), |
|
description="The PET Dataset for Relation Extraction" |
|
), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = _RELATIONS_EXTRACTION |
|
|
|
def _info(self): |
|
print(_STR_PET) |
|
if self.config.name == _NER: |
|
features = datasets.Features(self.features_ner) |
|
else: |
|
features = datasets.Features( |
|
{ |
|
"document name": datasets.Value("string"), |
|
'tokens':datasets.Sequence(datasets.Value("string")), |
|
'tokens-IDs':datasets.Sequence(datasets.Value("int8")), |
|
'ner_tags': datasets.Sequence(datasets.Value("string")), |
|
'sentence-IDs':datasets.Sequence(datasets.Value("int8")), |
|
"relations": self.features_relations |
|
} |
|
) |
|
|
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=datasets.Features(features), |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
if self.config.name == _NER: |
|
urls_to_download = { |
|
"test": f"{_URL}{_TEST_FILE}", |
|
} |
|
downloaded_files = dl_manager.download_and_extract(urls_to_download) |
|
return [datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": downloaded_files["test"], |
|
"split": "test" |
|
}, |
|
)] |
|
else: |
|
urls_to_download = { |
|
"test": f"{_URL}{_TEST_FILE_RELATIONS}", |
|
} |
|
downloaded_files = dl_manager.download_and_extract(urls_to_download) |
|
return [datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": downloaded_files["test"], |
|
"split": "test" |
|
}, |
|
)] |
|
|
|
def _generate_examples(self, filepath, split): |
|
if self.config.name == _NER: |
|
with open(filepath, encoding="utf-8", mode='r') as f: |
|
for key, row in enumerate(f): |
|
row = json.loads(row) |
|
yield key, { |
|
"document name": row["document name"], |
|
"sentence-ID": row["sentence-ID"], |
|
"tokens": row["tokens"], |
|
"ner-tags": row["ner-tags"] |
|
} |
|
else: |
|
with open(filepath, encoding="utf-8", mode='r') as f: |
|
for key, row in enumerate(json.load(f)): |
|
yield key, {"document name": row["document name"], |
|
'tokens': row["tokens"], |
|
'tokens-IDs': row["tokens-IDs"], |
|
'ner_tags': row["ner_tags"], |
|
'sentence-IDs': row["sentence-IDs"], |
|
|
|
"relations": row["relations"] |
|
} |
|
|