twl-generator 1.4.15 → 1.4.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "twl-generator",
3
- "version": "1.4.15",
3
+ "version": "1.4.16",
4
4
  "description": "Generate term-to-article lists from unfoldingWord en_tw archive for Bible books. Works in both Node.js (CLI) and React.js (browser) environments.",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -924,8 +924,10 @@ export async function generateTwlByBook(bookCode, options = {}) {
924
924
  else if (primaryArticle.startsWith('names/')) tag = 'name';
925
925
  const twLink = primaryArticle ? `rc://*/tw/dict/bible/${primaryArticle}` : '';
926
926
 
927
- // Variant of: only if beyond plural/-ed/-ing differences
928
- const variantOf = allowNoVariant(m.term, glq) ? '' : m.term;
927
+ // Variant of: only if beyond plural/-ed/-ing differences. Compare on the
928
+ // brace-free reading so a supplied-morpheme brace (e.g. "creature{s}")
929
+ // isn't itself counted as a difference from the term.
930
+ const variantOf = allowNoVariant(m.term, glq.replace(/[{}]/g, '')) ? '' : m.term;
929
931
  // Disambiguation: list all candidate articles for this match
930
932
  const disamb = (m.articles && m.articles.length > 1) ? `(${m.articles.join(', ')})` : '';
931
933
 
@@ -137,6 +137,15 @@ class PrefixTrie {
137
137
  while (currentPos < searchText.length) {
138
138
  const char = searchText[currentPos];
139
139
 
140
+ // Curly braces wrap "supplied" words/morphemes in the ULT (e.g.
141
+ // "creature{s}"). Match through them transparently (they never appear in
142
+ // a trie term) so "creature{s}" matches the term "creatures"; the braces
143
+ // are re-included when the matched span is extracted below.
144
+ if ((char === '{' || char === '}') && currentPos > startPos) {
145
+ currentPos++;
146
+ continue;
147
+ }
148
+
140
149
  if (!node[char]) {
141
150
  break; // No more matches possible
142
151
  }
@@ -192,14 +201,42 @@ class PrefixTrie {
192
201
  originalMatchedText = originalText.substring(extendedStartPos, extendedEndPos);
193
202
  }
194
203
 
195
- // Check if this is a valid word boundary match (both start and end)
196
- const isStartBoundary = extendedStartPos === 0 ||
197
- /[\s\p{P}]/u.test(originalText[extendedStartPos - 1]) ||
198
- !/[\w]/.test(originalText[extendedStartPos - 1]);
204
+ // Balance curly braces so a brace split across the match boundary keeps
205
+ // its partner. Matching "creature{s}" through the brace stops the span
206
+ // at "creature{s" (open '{' with no '}'); pull in the trailing '}' so
207
+ // OrigWords becomes "creature{s}". Symmetric for a leading '{'.
208
+ let open = 0, close = 0;
209
+ for (const ch of originalText.substring(extendedStartPos, extendedEndPos)) {
210
+ if (ch === '{') open++;
211
+ else if (ch === '}') close++;
212
+ }
213
+ while (open > close && extendedEndPos < originalText.length && originalText[extendedEndPos] === '}') {
214
+ extendedEndPos++; close++;
215
+ }
216
+ while (close > open && extendedStartPos > 0 && originalText[extendedStartPos - 1] === '{') {
217
+ extendedStartPos--; open++;
218
+ }
219
+ if (extendedStartPos < startPos || extendedEndPos > currentPos) {
220
+ originalMatchedText = originalText.substring(extendedStartPos, extendedEndPos);
221
+ }
199
222
 
200
- const isEndBoundary = extendedEndPos >= originalText.length ||
201
- /[\s\p{P}]/u.test(originalText[extendedEndPos]) ||
202
- !/[\w]/.test(originalText[extendedEndPos]);
223
+ // Check if this is a valid word boundary match (both start and end).
224
+ // Skip past any braces when locating the neighbouring character so a
225
+ // supplied-word brace does not act as a false word boundary: the
226
+ // brace-free reading ("creatures") must be treated as one word, so a
227
+ // bare "creature" before the "{s}" is correctly rejected.
228
+ let beforePos = extendedStartPos - 1;
229
+ while (beforePos >= 0 && (originalText[beforePos] === '{' || originalText[beforePos] === '}')) beforePos--;
230
+ let afterPos = extendedEndPos;
231
+ while (afterPos < originalText.length && (originalText[afterPos] === '{' || originalText[afterPos] === '}')) afterPos++;
232
+
233
+ const isStartBoundary = beforePos < 0 ||
234
+ /[\s\p{P}]/u.test(originalText[beforePos]) ||
235
+ !/[\w]/.test(originalText[beforePos]);
236
+
237
+ const isEndBoundary = afterPos >= originalText.length ||
238
+ /[\s\p{P}]/u.test(originalText[afterPos]) ||
239
+ !/[\w]/.test(originalText[afterPos]);
203
240
 
204
241
  const isWordBoundary = isStartBoundary && isEndBoundary;
205
242
 
@@ -51,7 +51,12 @@ export const removeAllTagsExceptChapterVerse = (usfmContent) => {
51
51
  cleanContent = cleanContent.replace(/ +/g, ' ');
52
52
  cleanContent = cleanContent.replace(/^ +$/g, '');
53
53
  cleanContent = cleanContent.replace(/\\f .*?\\f\*/g, ' ');
54
- cleanContent = cleanContent.replace(/[\{\}]/g, ''); // Remove any curly braces
54
+ // NOTE: Curly braces ({ }) wrap "supplied" words/morphemes in the ULT (e.g.
55
+ // "creature{s}") that the matcher must see through but must NOT discard. They
56
+ // are preserved here so the matcher can match the brace-free reading
57
+ // ("creatures") yet retain the braces in OrigWords ("creature{s}"), which is
58
+ // what tsv-quote-converters needs to align the quote back to the original
59
+ // language. Brace-transparency lives in twl-matcher.js (findMatches).
55
60
 
56
61
  // Remove all lines before the first \c marker, keeping the \c line
57
62
  const lines = cleanContent.split('\n');