Datasets:

dfki-nlp commited on
Commit
5aaf8e4
1 Parent(s): d58cc5b

Create scidtb.py

Browse files
Files changed (1) hide show
  1. scidtb.py +97 -0
scidtb.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import glob
2
+ import json
3
+ import os
4
+ from dataclasses import dataclass
5
+
6
+ import datasets
7
+ from datasets import BuilderConfig, SplitGenerator
8
+
9
+ _CITATION = """\
10
+ @article{yang2018scidtb,
11
+ title={Scidtb: Discourse dependency treebank for scientific abstracts},
12
+ author={Yang, An and Li, Sujian},
13
+ journal={arXiv preprint arXiv:1806.03653},
14
+ year={2018}
15
+ }
16
+ """
17
+
18
+ _DESCRIPTION = """Annotation corpus for discourse relations benefits NLP tasks such as machine translation and question
19
+ answering. SciDTB is a domain-specific discourse treebank annotated on scientific articles.
20
+ Different from widely-used RST-DT and PDTB, SciDTB uses dependency trees to represent discourse structure, which is
21
+ flexible and simplified to some extent but do not sacrifice structural integrity. We discuss the labeling framework,
22
+ annotation workflow and some statistics about SciDTB. Furthermore, our treebank is made as a benchmark for evaluating
23
+ discourse dependency parsers, on which we provide several baselines as fundamental work."""
24
+
25
+ _URL = "https://codeload.github.com/PKU-TANGENT/SciDTB/zip/refs/heads/master"
26
+ _HOMEPAGE = "https://github.com/PKU-TANGENT/SciDTB"
27
+
28
+
29
+ @dataclass
30
+ class SciDTBConfig(BuilderConfig):
31
+ """BuilderConfig for SciDTB."""
32
+
33
+ def __init__(self, subdirectory_mapping, encoding, **kwargs):
34
+ super(SciDTBConfig, self).__init__(**kwargs)
35
+ self.subdirectory_mapping = subdirectory_mapping
36
+ self.encoding = encoding
37
+
38
+
39
+ class SciDTBDataset(datasets.GeneratorBasedBuilder):
40
+ """Scientific Discourse Treebank Dataset"""
41
+
42
+ BUILDER_CONFIGS = [
43
+ SciDTBConfig(
44
+ name="SciDTB",
45
+ version=datasets.Version("1.0.0", ""),
46
+ description=_DESCRIPTION,
47
+ subdirectory_mapping={
48
+ "train": "SciDTB-master/dataset/train",
49
+ "dev": "SciDTB-master/dataset/dev/gold",
50
+ "test": "SciDTB-master/dataset/test/gold",
51
+ },
52
+ encoding="utf-8-sig",
53
+ ),
54
+ ]
55
+
56
+ def _info(self):
57
+ features = datasets.Features(
58
+ {
59
+ "root": datasets.Sequence(
60
+ {
61
+ "id": datasets.Value("int32"),
62
+ "parent": datasets.Value("int32"),
63
+ "text": datasets.Value("string"),
64
+ "relation": datasets.Value("string"),
65
+ }
66
+ ),
67
+ "file_name": datasets.Value("string"),
68
+ }
69
+ )
70
+
71
+ return datasets.DatasetInfo(
72
+ description=_DESCRIPTION,
73
+ features=features,
74
+ homepage=_HOMEPAGE,
75
+ citation=_CITATION,
76
+ )
77
+
78
+ def _split_generators(self, dl_manager):
79
+ data_dir = dl_manager.download_and_extract(_URL)
80
+ return [
81
+ SplitGenerator(
82
+ name=split,
83
+ # These kwargs will be passed to _generate_examples
84
+ gen_kwargs={
85
+ "dir_path": os.path.join(data_dir, subdir),
86
+ },
87
+ )
88
+ for split, subdir in self.config.subdirectory_mapping.items()
89
+ ]
90
+
91
+ def _generate_examples(self, dir_path):
92
+ _files = glob.glob(f"{dir_path}/*.dep")
93
+ for file_path in _files:
94
+ with open(file_path, mode="r", encoding=self.config.encoding) as f:
95
+ annotations = json.load(f)
96
+ annotations["file_name"] = os.path.basename(file_path)
97
+ yield annotations["file_name"], annotations