-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathData.py
84 lines (69 loc) · 2.12 KB
/
Data.py
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
import json
with open('data/poets.json', 'r', encoding="utf-8") as f:
poets = json.load(f)['poets']
with open('data/bohour.json', 'r', encoding='utf-8') as f:
bohours = json.load(f)['data']
with open('data/qawafi.json', 'r', encoding='utf-8') as f:
qafiyah = json.load(f)['data']
def merge_dicts_by_name(dict_list):
merged_dict = {}
for item in dict_list:
name = item.get('name')
if name:
merged_dict[name] = item
return merged_dict
poets = merge_dicts_by_name(poets)
bohours = merge_dicts_by_name(bohours)
def load_poets():
'''
returns a dictionary of poets, structured as follows:
Key: "name"
Value: A dictionary containing the following keys:
- "name": The poet's name in Arabic.
- "name_en": The poet's name in English.
- "description": Instructions for generating prompts.
- "poems": A nested dictionary where each key represents a bahr (in English)
{
'<bahr1>': [
['<poem1-line1>', '<poem1-line2>', ...],
...
],
...
}
Example output:
{
"name": "نزار قباني",
"name_en": "Nizar Qabbani",
"description": "أنت نزار قباني، ...",
"poems": {
"baseet": [
['في الحب', 'في الفراق', ...],
...
]
}
}
'''
return poets
def load_bohours():
'''
Returns a dictionary of bohours, structured as follows:
Key: "name"
Value: A dictionary containing:
- "name": Bahr's name in Arabic (string).
- "name_en": Bahr's name in English (string).
- "wazn": Bahr's wazn in Arabic (string, e.g., "mustaf3loun mustaf3loun mustaf3loun").
- "pattern": Bahr's pattern represented in 0s and 1s (string).
Example output:
{
"name": "الطويل",
"name_en": "Musta'filun",
"wazn": "فعولن مفاعيلن فعولن مفاعيلن",
"pattern": "110111010101101110110"
}
'''
return bohours
def load_qafiyas():
'''
Returns a list of words
'''
return qafiyah