@@ -37,7 +37,7 @@ def get_simsapa_db(db_path: Path, schema: DbSchemaName, remove_if_exists: bool)
37
37
if remove_if_exists and db_path .exists ():
38
38
db_path .unlink ()
39
39
40
- find_or_create_db (db_path , schema . value )
40
+ find_or_create_db (db_path , schema )
41
41
42
42
try :
43
43
# Create an in-memory database
@@ -47,8 +47,12 @@ def get_simsapa_db(db_path: Path, schema: DbSchemaName, remove_if_exists: bool)
47
47
48
48
if schema == DbSchemaName .AppData :
49
49
db_conn .execute (text (f"ATTACH DATABASE '{ db_path } ' AS appdata;" ))
50
- else :
50
+ elif schema == DbSchemaName . UserData :
51
51
db_conn .execute (text (f"ATTACH DATABASE '{ db_path } ' AS userdata;" ))
52
+ elif schema == DbSchemaName .Dpd :
53
+ db_conn .execute (text (f"ATTACH DATABASE '{ db_path } ' AS dpd;" ))
54
+ else :
55
+ raise Exception (f"Unknown schema_name: { schema } " )
52
56
53
57
Session = sessionmaker (engine )
54
58
Session .configure (bind = engine )
@@ -78,6 +82,10 @@ def uid_to_ref(uid: str) -> str:
78
82
79
83
return uid
80
84
85
+ def uid_to_nikaya (uid : str ) -> str :
86
+ '''sn12.23 to sn'''
87
+ nikaya = re .sub (r'^([a-z]+).*' , r'\1' , uid )
88
+ return nikaya
81
89
82
90
def text_to_multi_ref (collection : str , ref_text : str , schema : DbSchemaName ) -> Optional [UMultiRef ]:
83
91
ref_text = ref_text .lower ()
@@ -133,13 +141,15 @@ def text_to_multi_ref(collection: str, ref_text: str, schema: DbSchemaName) -> O
133
141
edition = "1st ed. Feer (1884)" ,
134
142
)
135
143
136
- else :
144
+ elif schema == DbSchemaName . UserData :
137
145
item = Um .MultiRef (
138
146
collection = collection ,
139
147
ref_type = "pts" ,
140
148
ref = normalize_sutta_ref (ref_text ),
141
149
edition = "1st ed. Feer (1884)" ,
142
150
)
151
+ else :
152
+ raise Exception ("Only appdata and userdata schema are allowed." )
143
153
144
154
return item
145
155
@@ -154,14 +164,17 @@ def text_to_multi_ref(collection: str, ref_text: str, schema: DbSchemaName) -> O
154
164
edition = "2nd ed. Somaratne (1998)" ,
155
165
)
156
166
157
- else :
167
+ elif schema == DbSchemaName . UserData :
158
168
item = Um .MultiRef (
159
169
collection = collection ,
160
170
ref_type = "pts" ,
161
171
ref = normalize_sutta_ref (ref_text ),
162
172
edition = "2nd ed. Somaratne (1998)" ,
163
173
)
164
174
175
+ else :
176
+ raise Exception ("Only appdata and userdata schema are allowed." )
177
+
165
178
return item
166
179
167
180
refs = []
@@ -184,13 +197,16 @@ def text_to_multi_ref(collection: str, ref_text: str, schema: DbSchemaName) -> O
184
197
ref = ", " .join (refs ),
185
198
)
186
199
187
- else :
200
+ elif schema == DbSchemaName . UserData :
188
201
item = Um .MultiRef (
189
202
collection = collection ,
190
203
ref_type = "pts" ,
191
204
ref = ", " .join (refs ),
192
205
)
193
206
207
+ else :
208
+ raise Exception ("Only appdata and userdata schema are allowed." )
209
+
194
210
return item
195
211
196
212
# Ref may contain roman numerals.
@@ -210,13 +226,16 @@ def text_to_multi_ref(collection: str, ref_text: str, schema: DbSchemaName) -> O
210
226
ref = ", " .join (refs ),
211
227
)
212
228
213
- else :
229
+ elif schema == DbSchemaName . UserData :
214
230
item = Um .MultiRef (
215
231
collection = collection ,
216
232
ref_type = "pts" ,
217
233
ref = ", " .join (refs ),
218
234
)
219
235
236
+ else :
237
+ raise Exception ("Only appdata and userdata schema are allowed." )
238
+
220
239
return item
221
240
222
241
return None
0 commit comments