forked from Sefaria/Sefaria-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_parsha_structs.py
71 lines (61 loc) · 1.84 KB
/
set_parsha_structs.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
# -*- coding: utf-8 -*-
from sefaria.model import *
import json
import pprint
pset = {}
pfile = "../tmp/parshiot.json"
with open(pfile, 'rb') as parshiot_json:
parshiot = json.load(parshiot_json)
for parsha in parshiot:
name = parsha["parasha"]
if name in pset:
continue
if u"-" in name and name != "Lech-Lecha":
continue
if name == "Lech-Lecha":
name = "Lech Lecha"
refs = parsha["aliyot"][0:7]
start = Ref(refs[0])
end = Ref(refs[6])
book = start.book
whole_ref = start.to(end).normal()
pset[name] = {
"refs": refs,
"book": book,
"whole_ref": whole_ref
}
pset[u"V'Zot HaBerachah"] = {
"refs": ["Deuteronomy 33:1–7",
"Deuteronomy 33:8–12",
"Deuteronomy 33:13–17",
"Deuteronomy 33:18–21",
"Deuteronomy 33:22–26",
"Deuteronomy 33:27–29",
"Deuteronomy 34:1-12"],
"book": "Deuteronomy",
"whole_ref": "Deuteronomy 33:8-34:12"
}
structs = {}
terms = TermSet({"scheme": "Parasha"})
for term in terms:
oref = Ref(term.ref)
if not structs.get(oref.index.title):
structs[oref.index.title] = {
"nodes": []
}
structs[oref.index.title]["nodes"].append({
'sharedTitle': term.name,
"nodeType": "ArrayMapNode",
"depth": 1,
"addressTypes": ["Aliyah"],
"sectionNames": ["Aliyah"],
'wholeRef': pset[term.name]["whole_ref"],
'refs': pset[term.name]["refs"]
})
for name, struct in structs.items():
i = get_index(name)
obj = deserialize_tree(struct, index=i, struct_class=TitledTreeNode)
obj.title_group = i.nodes.title_group
obj.validate()
i.set_alt_structure("Parasha", obj)
i.save()