kakooch commited on
Commit
e063983
1 Parent(s): 5261790

Upload persian_poetry.py

Browse files
Files changed (1) hide show
  1. persian_poetry.py +48 -0
persian_poetry.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ from datasets import DatasetBuilder, SplitGenerator, Split, Features, Value, DownloadConfig
3
+
4
+ class PersianPoetry(DatasetBuilder):
5
+ VERSION = "1.0.0"
6
+
7
+ def _info(self):
8
+ return datasets.DatasetInfo(
9
+ description="This dataset contains a rich collection of Persian poems along with metadata about the poets and the verses.",
10
+ features=Features({
11
+ 'poet': Value('string'),
12
+ 'title': Value('string'),
13
+ 'content': datasets.Sequence({
14
+ 'hemistich': {
15
+ 'verse0': Value('string'),
16
+ 'verse1': Value('string')
17
+ },
18
+ 'verse': {
19
+ 'text': Value('string')
20
+ }
21
+ })
22
+ }),
23
+ homepage="https://github.com/ganjoor/desktop/releases/tag/v2.81",
24
+ citation="""Persian Poetry Dataset. Collected by Kakooch from the Ganjoor Project. Available at: https://huggingface.co/datasets/persian_poetry""",
25
+ )
26
+
27
+ def _split_generators(self, dl_manager):
28
+ # You need to download and extract the data manually and place it in the path defined below.
29
+ local_path = "/path/to/your/dataset.jsonl"
30
+ return [
31
+ SplitGenerator(
32
+ name=Split.TRAIN,
33
+ gen_kwargs={
34
+ "filepath": local_path
35
+ }
36
+ ),
37
+ ]
38
+
39
+ def _generate_examples(self, filepath):
40
+ with open(filepath, encoding="utf-8") as f:
41
+ for id_, line in enumerate(f):
42
+ data = json.loads(line.strip())
43
+ yield id_, {
44
+ 'poet': data['poet'],
45
+ 'title': data['title'],
46
+ 'content': data['content']
47
+ }
48
+