Datasets:

Modalities:
Text
Formats:
parquet
Languages:
English
Libraries:
Datasets
pandas
License:
sileod commited on
Commit
3c495f2
1 Parent(s): de25180

Create dsr.py

Browse files
Files changed (1) hide show
  1. dsr.py +77 -0
dsr.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import datasets
2
+ import csv
3
+ import requests
4
+
5
+
6
+ citation='''
7
+ '''
8
+
9
+ class Config(datasets.BuilderConfig):
10
+ citation=citation
11
+
12
+ files = [
13
+ "eng.dep.covdtb",
14
+ "eng.dep.scidtb",
15
+ "eng.pdtb.pdtb",
16
+ "eng.pdtb.tedm",
17
+ "eng.rst.gum",
18
+ "eng.rst.rstdt",
19
+ "eng.sdrt.stac",
20
+ "deu.rst.pcc",
21
+ "eus.rst.ert",
22
+ "fas.rst.prstc",
23
+ "fra.sdrt.annodis",
24
+ "ita.pdtb.luna",
25
+ "nld.rst.nldt",
26
+ "por.pdtb.crpc",
27
+ "por.pdtb.tedm",
28
+ "por.rst.cstn",
29
+ "rus.rst.rrt",
30
+ "spa.rst.rststb",
31
+ "spa.rst.sctb",
32
+ "tha.pdtb.tdtb",
33
+ "tur.pdtb.tdb",
34
+ "tur.pdtb.tedm",
35
+ "zho.dep.scidtb",
36
+ "zho.pdtb.cdtb",
37
+ "zho.rst.gcdt",
38
+ "zho.rst.sctb",
39
+ ]
40
+
41
+
42
+ _URLs = {f'{task}-{split}':f"https://raw.githubusercontent.com/disrpt/sharedtask2023/main/data/{task}/{task}_{split}.rels" \
43
+ for task in files for split in 'train dev test'.split()}
44
+ _URLs = {k:v for k,v in _URLs.items() if requests.get(v).status_code!=404}
45
+
46
+ class Dataset(datasets.GeneratorBasedBuilder):
47
+
48
+ BUILDER_CONFIGS = [
49
+ Config(
50
+ name=n,
51
+ data_dir=n
52
+ ) for n in files
53
+ ]
54
+
55
+ def _split_generators(self, dl_manager: datasets.DownloadManager):
56
+ data_file = dl_manager.download(_URLs)
57
+ train_key = self.config.data_dir+'-train'
58
+ if train_key in data_file:
59
+ train=datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": data_file[train_key]})
60
+ else:
61
+ train=[]
62
+ return train+[
63
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": data_file[self.config.data_dir+'-dev']}),
64
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": data_file[self.config.data_dir+'-test']}),
65
+
66
+ ]
67
+
68
+
69
+ def _info(self): return datasets.DatasetInfo()
70
+
71
+ def _generate_examples(self, filepath):
72
+ with open(filepath, encoding="utf-8") as f:
73
+ reader = csv.DictReader(f,delimiter='\t')
74
+ for id_, row in enumerate(reader):
75
+ if id_ == 0:
76
+ continue
77
+ yield id_, row