File size: 2,348 Bytes
a4092e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

"""
""" # TODO
try:
    import ir_datasets
except ImportError as e:
    raise ImportError('ir-datasets package missing; `pip install ir-datasets`')
import datasets

IRDS_ID = 'wikiclir/ca'
IRDS_ENTITY_TYPES = {'docs': {'doc_id': 'string', 'title': 'string', 'text': 'string'}, 'queries': {'query_id': 'string', 'text': 'string'}, 'qrels': {'query_id': 'string', 'doc_id': 'string', 'relevance': 'int64', 'iteration': 'string'}}

_CITATION = '@inproceedings{sasaki-etal-2018-cross,\n    title = "Cross-Lingual Learning-to-Rank with Shared Representations",\n    author = "Sasaki, Shota  and\n      Sun, Shuo  and\n      Schamoni, Shigehiko  and\n      Duh, Kevin  and\n      Inui, Kentaro",\n    booktitle = "Proceedings of the 2018 Conference of the North {A}merican Chapter of the Association for Computational Linguistics: Human Language Technologies, Volume 2 (Short Papers)",\n    month = jun,\n    year = "2018",\n    address = "New Orleans, Louisiana",\n    publisher = "Association for Computational Linguistics",\n    url = "https://aclanthology.org/N18-2073",\n    doi = "10.18653/v1/N18-2073",\n    pages = "458--463"\n}'

_DESCRIPTION = "" # TODO

class wikiclir_ca(datasets.GeneratorBasedBuilder):
    BUILDER_CONFIGS = [datasets.BuilderConfig(name=e) for e in IRDS_ENTITY_TYPES]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features({k: datasets.Value(v) for k, v in IRDS_ENTITY_TYPES[self.config.name].items()}),
            homepage=f"https://ir-datasets.com/wikiclir#wikiclir/ca",
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        return [datasets.SplitGenerator(name=self.config.name)]

    def _generate_examples(self):
        dataset = ir_datasets.load(IRDS_ID)
        for i, item in enumerate(getattr(dataset, self.config.name)):
            key = i
            if self.config.name == 'docs':
                key = item.doc_id
            elif self.config.name == 'queries':
                key = item.query_id
            yield key, item._asdict()

    def as_dataset(self, split=None, *args, **kwargs):
        split = self.config.name # always return split corresponding with this config to avid returning a redundant DatasetDict layer
        return super().as_dataset(split, *args, **kwargs)