File size: 3,676 Bytes
cac2b44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49a2cd7
cac2b44
 
 
 
 
 
 
 
 
 
0e472bb
cac2b44
 
 
 
 
 
 
 
 
 
 
 
 
3444049
cac2b44
 
 
 
 
 
 
 
 
988efa8
be37733
cac2b44
988efa8
df9bd1c
 
979140d
 
 
 
b223310
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# coding=utf-8
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Lint as: python3
"""Arabic Poetry Metric dataset."""


import os
import datasets
import pandas as pd

_DESCRIPTION = """\
Masader is the largest public catalogue for Arabic NLP datasets, which consists of more than 200 datasets annotated with 25 attributes. 
"""

_CITATION = """\
@misc{alyafeai2021masader,
      title={Masader: Metadata Sourcing for Arabic Text and Speech Data Resources}, 
      author={Zaid Alyafeai and Maraim Masoud and Mustafa Ghaleb and Maged S. Al-shaibani},
      year={2021},
      eprint={2110.06744},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
      }
"""

columns = ['No.', 'Name', 'Subsets', 'Link', 'License', 'Year', 'Language',
       'Dialect', 'Domain', 'Form', 'Collection Style', 'Description',
       'Volume', 'Unit', 'Ethical Risks', 'Provider', 'Derived From',
       'Paper Title', 'Paper Link', 'Script', 'Tokenized', 'Host', 'Access',
       'Cost', 'Test Split']

class MasaderConfig(datasets.BuilderConfig):
    """BuilderConfig for Masader."""

    def __init__(self, **kwargs):
        """BuilderConfig for MetRec.

        Args:
          **kwargs: keyword arguments forwarded to super.
        """
        super(MasaderConfig, self).__init__(version=datasets.Version("1.0.0", ""), **kwargs)


class Masader(datasets.GeneratorBasedBuilder):
    """Masaderdataset."""

    BUILDER_CONFIGS = [
        MasaderConfig(
            name="plain_text",
            description="Plain text",
        )
    ]

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    columns[i]: datasets.Value("string") for i in range(len(columns))
                }
            ),
            supervised_keys=None,
            homepage="https://github.com/arbml/Masader",
            citation=_CITATION,)

    def _split_generators(self, dl_manager):
        sheet_id = "1YO-Vl4DO-lnp8sQpFlcX1cDtzxFoVkCmU1PVw_ZHJDg"
        sheet_name = "filtered_clean"
        url = f"https://docs.google.com/spreadsheets/d/{sheet_id}/gviz/tq?tqx=out:csv&sheet={sheet_name}"
        
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN, gen_kwargs={"url":url }
            ),
        ]

    def _generate_examples(self, url):
        """Generate examples."""
        # For labeled examples, extract the label from the path.
        
                
        df = pd.read_csv(url, usecols=range(34))
        subsets = {}
        i = 0 
        
        while i < len(df.values):
           
            entry_list = df[i].tolist()
            if str(df.values[i][0]) == "nan":
                subsets[entry_list[2]] = {'Dialect':entry_list[7], 'Volume':entry_list[13], 'Unit':entry_list[14]}
                i += 1 
                continue

            masader_entry = {col:entry_list[i] for i,col in enumerate(columns) if i != 2}
            masader_entry['subsets'] = subsets
            subsets = {}
            yield i, masader_entry