joshruby commited on
Commit
ece64da
·
verified ·
1 Parent(s): 4e3dd3c

Map unmapped link refs (all of Talmud) to segments by their own refs

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -197,8 +197,25 @@ def load():
197
  X["en"] = en
198
 
199
  S["stage"] = "links"
200
- L = {f: hf(f"card/ner/links/{f}") for f in ["refseg.idx", "links.idx", "links.dat"]}
201
  refseg = np.fromfile(L["refseg.idx"], dtype=np.uint32)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  lidx = np.fromfile(L["links.idx"], dtype=np.uint32)
203
  ldat = np.fromfile(L["links.dat"], dtype=np.uint32)
204
  src = np.repeat(np.arange(len(refseg), dtype=np.uint32), np.diff(lidx).astype(np.int64))
 
197
  X["en"] = en
198
 
199
  S["stage"] = "links"
200
+ L = {f: hf(f"card/ner/links/{f}") for f in ["refseg.idx", "links.idx", "links.dat", "refs.txt"]}
201
  refseg = np.fromfile(L["refseg.idx"], dtype=np.uint32)
202
+ # refseg.idx leaves every Talmud ref unmapped (Chullin: 0 of 4,381), so refs
203
+ # without a segment are matched by the segment's own Sefaria-style ref
204
+ own = {}
205
+ for i in range(n):
206
+ own.setdefault(refs(i)[0], i)
207
+ rtxt = L["refs.txt"].read_bytes().decode("utf-8").split("\n")
208
+ filled = 0
209
+ for i in np.flatnonzero(refseg == NONE).tolist():
210
+ if i < len(rtxt):
211
+ t = own.get(rtxt[i])
212
+ if t is not None:
213
+ refseg[i] = t
214
+ filled += 1
215
+ S["refs_filled"] = filled
216
+ S["refs_unmapped"] = int((refseg == NONE).sum())
217
+ S["refs_sample_unmapped"] = [rtxt[i] for i in np.flatnonzero(refseg == NONE)[:: max(1, int((refseg == NONE).sum()) // 12)][:12].tolist()]
218
+ del own, rtxt
219
  lidx = np.fromfile(L["links.idx"], dtype=np.uint32)
220
  ldat = np.fromfile(L["links.dat"], dtype=np.uint32)
221
  src = np.repeat(np.arange(len(refseg), dtype=np.uint32), np.diff(lidx).astype(np.int64))