File size: 1,829 Bytes
e063983
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
from datasets import DatasetBuilder, SplitGenerator, Split, Features, Value, DownloadConfig

class PersianPoetry(DatasetBuilder):
    VERSION = "1.0.0"
    
    def _info(self):
        return datasets.DatasetInfo(
            description="This dataset contains a rich collection of Persian poems along with metadata about the poets and the verses.",
            features=Features({
                'poet': Value('string'),
                'title': Value('string'),
                'content': datasets.Sequence({
                    'hemistich': {
                        'verse0': Value('string'),
                        'verse1': Value('string')
                    },
                    'verse': {
                        'text': Value('string')
                    }
                })
            }),
            homepage="https://github.com/ganjoor/desktop/releases/tag/v2.81",
            citation="""Persian Poetry Dataset. Collected by Kakooch from the Ganjoor Project. Available at: https://huggingface.co/datasets/persian_poetry""",
        )

    def _split_generators(self, dl_manager):
        # You need to download and extract the data manually and place it in the path defined below.
        local_path = "/path/to/your/dataset.jsonl"
        return [
            SplitGenerator(
                name=Split.TRAIN,
                gen_kwargs={
                    "filepath": local_path
                }
            ),
        ]

    def _generate_examples(self, filepath):
        with open(filepath, encoding="utf-8") as f:
            for id_, line in enumerate(f):
                data = json.loads(line.strip())
                yield id_, {
                    'poet': data['poet'],
                    'title': data['title'],
                    'content': data['content']
                }