larsgson commited on
Commit
9841ef4
·
verified ·
1 Parent(s): 69982b2

compact-alignments: batch 1/71 (100 file(s))

Browse files
Files changed (1) hide show
  1. README.md +51 -3
README.md CHANGED
@@ -150,7 +150,7 @@ e.g. `hbo:0430`) `lexeme-alignments` uses, not a bare Strong's number or a raw w
150
  [**lexeme-alignments' "The anchor: lexeme, not Strong's"**](https://huggingface.co/datasets/bcv-commons/lexeme-alignments#the-anchor-lexeme-not-strongs)
151
  section for what that means and why (homonym/sense-split handling, the Strong's rollup, etc.) — this
152
  dataset assumes that anchor as given rather than re-explaining it. (On GitHub, the same section lives at
153
- [`lexeme-alignments/README.md`](https://github.com/bcv-commons/lexeme-aligner/blob/main/lexeme-alignments/README.md#the-anchor-lexeme-not-strongs).)
154
 
155
  | token | meaning |
156
  |---|---|
@@ -163,8 +163,56 @@ dataset assumes that anchor as given rather than re-explaining it. (On GitHub, t
163
  | `""` (empty string) | the verse has no aligned content lexeme, or the edition has no text there (e.g. a non-anchor verse of a pooled translation range) |
164
 
165
  Target token positions are addressed by **position in that verse's own tokenized text** — a consumer
166
- tokenizes the edition's text the same way alignment did (whitespace + punctuation splitting) to resolve
167
- a position back to a word.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
 
169
  ### Worked example — the scattered (comma) case
170
 
 
150
  [**lexeme-alignments' "The anchor: lexeme, not Strong's"**](https://huggingface.co/datasets/bcv-commons/lexeme-alignments#the-anchor-lexeme-not-strongs)
151
  section for what that means and why (homonym/sense-split handling, the Strong's rollup, etc.) — this
152
  dataset assumes that anchor as given rather than re-explaining it. (On GitHub, the same section lives at
153
+ [`lexeme-alignments/README.md`](https://github.com/bcv-commons/lexeme-aligner/blob/main/publish/lexeme-alignments/README.md#the-anchor-lexeme-not-strongs).)
154
 
155
  | token | meaning |
156
  |---|---|
 
163
  | `""` (empty string) | the verse has no aligned content lexeme, or the edition has no text there (e.g. a non-anchor verse of a pooled translation range) |
164
 
165
  Target token positions are addressed by **position in that verse's own tokenized text** — a consumer
166
+ tokenizes the edition's text the SAME way alignment did to resolve a position back to a word, or target
167
+ positions silently point at the wrong words. This is NOT plain whitespace/punctuation splitting — the
168
+ exact rule (`usj_source.tokenize()`) is: **a token is a maximal run of Unicode letters + combining
169
+ marks** (categories `L`/`M`). Everything else — punctuation, whitespace, AND digits (`Nd`, e.g. `40`,
170
+ `3`) — is a separator, producing NO token at all, not even a placeholder. **Numerals in the source text
171
+ are the sharpest gotcha**: a naive re-tokenizer that treats `"Selama 40 hari"` as 3 tokens (`Selama`,
172
+ `40`, `hari`) will be off-by-one from every position onward, compounding for every subsequent number in
173
+ the verse — this alone can look exactly like a systematic alignment bug when it's actually a
174
+ tokenization mismatch (verified against real client feedback on `ACT 1:3`/`ind_ags`: 8 apparent
175
+ "off-by-one" mismatches collapsed to 2 genuine ones once decoded with the correct tokenizer rule).
176
+
177
+ **Reference implementation, both languages** (verified byte-for-byte identical to `usj_source.tokenize()`
178
+ on the real `ind_ags` `ACT 1:3` text above):
179
+
180
+ **Python:**
181
+ ```python
182
+ import unicodedata
183
+
184
+ def tokenize(text: str) -> list[str]:
185
+ toks, cur = [], []
186
+ for ch in unicodedata.normalize("NFC", text):
187
+ if unicodedata.combining(ch): # drop non-spacing combining marks (Hebrew niqqud,
188
+ continue # Arabic harakat, ...) before the letter/mark test below
189
+ if unicodedata.category(ch)[0] in ("L", "M"):
190
+ cur.append(ch)
191
+ elif cur:
192
+ toks.append("".join(cur))
193
+ cur = []
194
+ if cur:
195
+ toks.append("".join(cur))
196
+ return toks
197
+ ```
198
+
199
+ **JavaScript** (covers Latin/Cyrillic/Greek-script targets, which is the large majority — see the
200
+ caveat below for diacritic-heavy scripts):
201
+ ```javascript
202
+ function tokenize(text) {
203
+ const normalized = text.normalize("NFC");
204
+ return normalized.match(/[\p{L}\p{M}]+/gu) || []; // \p{L}=letter, \p{M}=mark (Unicode property escapes)
205
+ }
206
+ ```
207
+
208
+ **Honest caveat on the JS version**: JavaScript has no built-in equivalent to Python's
209
+ `unicodedata.combining()` (canonical combining class), so the snippet above doesn't strip non-spacing
210
+ marks (Mn) the way the Python one does — it's exactly right for scripts without those (Latin, Cyrillic,
211
+ Greek — covers most target languages, including the `ind_ags` case here), but for a diacritic-heavy
212
+ script (Hebrew niqqud, Arabic harakat, Devanagari) it may tokenize slightly differently than
213
+ `usj_source.tokenize()`. Rather than ship a JS mark-stripping table that could itself be subtly wrong,
214
+ if you're decoding one of those scripts, treat `usj_source.py`'s Python implementation as the
215
+ authoritative reference.
216
 
217
  ### Worked example — the scattered (comma) case
218