Spaces:
Running
Running
Lookup by ref
Browse files
app.py
CHANGED
|
@@ -548,3 +548,23 @@ def passage(seg: int):
|
|
| 548 |
def root():
|
| 549 |
return {"ok": True, "see": "/api/status"}
|
| 550 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 548 |
def root():
|
| 549 |
return {"ok": True, "see": "/api/status"}
|
| 550 |
|
| 551 |
+
|
| 552 |
+
|
| 553 |
+
def ref_index():
|
| 554 |
+
if "refidx" not in X:
|
| 555 |
+
d = {}
|
| 556 |
+
for i in range(X["n"]):
|
| 557 |
+
d.setdefault(refs(i)[0].lower(), i)
|
| 558 |
+
X["refidx"] = d
|
| 559 |
+
return X["refidx"]
|
| 560 |
+
|
| 561 |
+
|
| 562 |
+
@app.get("/api/ref")
|
| 563 |
+
def by_ref(r: str):
|
| 564 |
+
"""A Sefaria-style ref ("Rashi on Chullin 59a:14:1") -> its segment and its link count."""
|
| 565 |
+
need_ready()
|
| 566 |
+
s = ref_index().get(r.strip().lower())
|
| 567 |
+
if s is None:
|
| 568 |
+
raise HTTPException(404)
|
| 569 |
+
return {"seg": s, "ref": refs(s)[0], "he": refs(s)[1], "links": int(X["lptr"][s + 1] - X["lptr"][s]),
|
| 570 |
+
"twin": X["twin"].get(s), "cls": int(X["cls"][s])}
|