patriziobellan commited on
Commit
cb13d61
1 Parent(s): ce0e16e

Upload PET.py

Browse files
Files changed (1) hide show
  1. PET.py +174 -0
PET.py ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # TO CREATE dataset_infos.json use: datasets-cli test PET --save_infos --all_configs
2
+ #
3
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ import csv
18
+ import json
19
+ import os
20
+
21
+ import datasets
22
+
23
+
24
+ # Find for instance the citation on arxiv or on the dataset repo/website
25
+ _CITATION = """\
26
+ @article{DBLP:journals/corr/abs-2203-04860,
27
+ author = {Patrizio Bellan and
28
+ Han van der Aa and
29
+ Mauro Dragoni and
30
+ Chiara Ghidini and
31
+ Simone Paolo Ponzetto},
32
+ title = {{PET:} {A} new Dataset for Process Extraction from Natural Language
33
+ Text},
34
+ journal = {CoRR},
35
+ volume = {abs/2203.04860},
36
+ year = {2022},
37
+ url = {https://doi.org/10.48550/arXiv.2203.04860},
38
+ doi = {10.48550/arXiv.2203.04860},
39
+ eprinttype = {arXiv},
40
+ eprint = {2203.04860},
41
+ biburl = {https://dblp.org/rec/journals/corr/abs-2203-04860.bib}
42
+ }
43
+ """
44
+
45
+ # You can copy an official description
46
+ _DESCRIPTION = """\
47
+ 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.
48
+ """
49
+
50
+ _HOMEPAGE = "https://pdi.fbk.eu/pet-dataset/"
51
+
52
+ _LICENSE = "MIT"
53
+
54
+ _URL = "https://pdi.fbk.eu/pet/PETHuggingFace/"
55
+ # _TRAINING_FILE = "train.json"
56
+ # _DEV_FILE = "dev.json"
57
+ _TEST_FILE = "test.json"
58
+
59
+
60
+
61
+ class PETConfig(datasets.BuilderConfig):
62
+ """The PET Dataset."""
63
+
64
+ def __init__(self, **kwargs):
65
+ """BuilderConfig for PET.
66
+ Args:
67
+ **kwargs: keyword arguments forwarded to super.
68
+ """
69
+ super(PETConfig, self).__init__(**kwargs)
70
+
71
+ class PET(datasets.GeneratorBasedBuilder):
72
+ """PET DATASET."""
73
+ BUILDER_CONFIGS = [
74
+ PETConfig(
75
+ name="PET", version=datasets.Version("1.0.0"), description="The PET Dataset"
76
+ ),
77
+ ]
78
+
79
+ def _info(self):
80
+ features = datasets.Features(
81
+ {
82
+ "document name": datasets.Value("string"),
83
+ "sentence-ID": datasets.Value("int8"),
84
+ "tokens": datasets.Sequence(datasets.Value("string")),
85
+ "ner-tags": datasets.Sequence(
86
+ datasets.features.ClassLabel(
87
+ names=[
88
+ "O",
89
+ "B-Actor",
90
+ "I-Actor",
91
+ "B-Activity",
92
+ "I-Activity",
93
+ "B-Activity Data",
94
+ "I-Activity Data",
95
+ "B-Further Specification",
96
+ "I-Further Specification",
97
+ "B-XOR Gateway",
98
+ "I-XOR Gateway",
99
+ "B-Condition Specification",
100
+ "I-Condition Specification",
101
+ "B-AND Gateway",
102
+ "I-AND Gateway",
103
+ ]
104
+ )
105
+ ),
106
+ }
107
+ )
108
+
109
+ return datasets.DatasetInfo(
110
+ # This is the description that will appear on the datasets page.
111
+ description=_DESCRIPTION,
112
+ # This defines the different columns of the dataset and their types
113
+ features=features, # Here we define them above because they are different between the two configurations
114
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
115
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
116
+ # supervised_keys=("sentence", "label"),
117
+ # Homepage of the dataset for documentation
118
+ homepage=_HOMEPAGE,
119
+ # License for the dataset if available
120
+ license=_LICENSE,
121
+ # Citation for the dataset
122
+ citation=_CITATION,
123
+ )
124
+
125
+ def _split_generators(self, dl_manager):
126
+ urls_to_download = {
127
+ # "train": f"{_URL}{_TRAINING_FILE}",
128
+ # "dev": f"{_URL}{_DEV_FILE}",
129
+ "test": f"{_URL}{_TEST_FILE}",
130
+ }
131
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
132
+
133
+ return [
134
+ # datasets.SplitGenerator(
135
+ # name=datasets.Split.TRAIN,
136
+ # # These kwargs will be passed to _generate_examples
137
+ # gen_kwargs={
138
+ # "filepath": downloaded_files["train"],
139
+ # "split": "train",
140
+ # },
141
+ # ),
142
+ datasets.SplitGenerator(
143
+ name=datasets.Split.TEST,
144
+ # These kwargs will be passed to _generate_examples
145
+ gen_kwargs={
146
+ "filepath": downloaded_files["test"],
147
+ "split": "test"
148
+ },
149
+ ),
150
+ #
151
+ # datasets.SplitGenerator(
152
+ # name=datasets.Split.VALIDATION,
153
+ # # These kwargs will be passed to _generate_examples
154
+ # gen_kwargs={
155
+ # "filepath": os.path.join(data_dir, "dev.jsonl"),
156
+ # "split": "dev",
157
+ # },
158
+ # ),
159
+ ]
160
+
161
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
162
+ def _generate_examples(self, filepath, split):
163
+ # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
164
+ # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
165
+
166
+ with open(filepath, encoding="utf-8", mode='r') as f:
167
+ for key, row in enumerate(f):
168
+ row = json.loads(row)
169
+ yield key, {
170
+ "document name": row["document name"],
171
+ "sentence-ID": row["sentence-ID"],
172
+ "tokens": row["tokens"],
173
+ "ner-tags": row["ner-tags"]
174
+ }