twl-generator 1.2.10 → 1.2.12
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/README.md +55 -103
- package/package.json +1 -1
- package/src/utils/twl-matcher.js +1 -1
package/README.md
CHANGED
|
@@ -11,143 +11,95 @@ Generate term-to-article lists from unfoldingWord en_tw archive for Bible books.
|
|
|
11
11
|
- ✅ **Morphological Variants**: Handles plurals, possessives, verb forms
|
|
12
12
|
- ✅ **Parentheses Normalization**: "Joseph (OT)" → "Joseph" for better coverage
|
|
13
13
|
|
|
14
|
+
---
|
|
15
|
+
|
|
14
16
|
## Usage
|
|
15
17
|
|
|
16
|
-
### CLI
|
|
18
|
+
### CLI
|
|
19
|
+
|
|
20
|
+
Install globally:
|
|
17
21
|
|
|
18
22
|
```bash
|
|
19
|
-
# Install globally
|
|
20
23
|
npm install -g twl-generator
|
|
21
|
-
|
|
22
|
-
# Generate TSV for a Bible book
|
|
23
|
-
twl-generator --book JHN --output john.tsv
|
|
24
|
-
|
|
25
|
-
# Process local USFM file
|
|
26
|
-
twl-generator --usfm my-file.usfm --output results.tsv
|
|
27
24
|
```
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
```jsx
|
|
32
|
-
import { generateTWTerms, getCacheInfo, clearCache } from 'twl-generator/src/utils/zipProcessor.js';
|
|
33
|
-
|
|
34
|
-
function MyTWLComponent() {
|
|
35
|
-
const [terms, setTerms] = useState(null);
|
|
36
|
-
const [loading, setLoading] = useState(false);
|
|
37
|
-
|
|
38
|
-
const loadTerms = async () => {
|
|
39
|
-
setLoading(true);
|
|
40
|
-
try {
|
|
41
|
-
// First load: Downloads and processes (~3-4 seconds)
|
|
42
|
-
// Subsequent loads: Uses browser cache (~instant)
|
|
43
|
-
const termData = await generateTWTerms();
|
|
44
|
-
setTerms(termData);
|
|
45
|
-
|
|
46
|
-
// Debug cache info
|
|
47
|
-
console.log('Cache info:', getCacheInfo());
|
|
48
|
-
} catch (error) {
|
|
49
|
-
console.error('Failed to load terms:', error);
|
|
50
|
-
}
|
|
51
|
-
setLoading(false);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const handleClearCache = async () => {
|
|
55
|
-
await clearCache();
|
|
56
|
-
console.log('Cache cleared - next load will download fresh data');
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return (
|
|
60
|
-
<div>
|
|
61
|
-
{loading && <p>Loading translation words...</p>}
|
|
62
|
-
<button onClick={() => loadTerms()}>Load Terms</button>
|
|
63
|
-
<button onClick={handleClearCache}>Clear Cache</button>
|
|
64
|
-
{terms && <p>Loaded {Object.keys(terms).length} terms</p>}
|
|
65
|
-
</div>
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Node.js Module
|
|
26
|
+
Generate a TWL TSV for a Bible book (downloads USFM from Door43):
|
|
71
27
|
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const result = await generateTWLWithUsfm('RUT');
|
|
76
|
-
console.log(result);
|
|
28
|
+
```bash
|
|
29
|
+
twl-generator --book rut
|
|
77
30
|
```
|
|
78
31
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
The package uses a multi-tier caching approach for optimal performance in React.js:
|
|
82
|
-
|
|
83
|
-
1. **Memory Cache**: Fastest access during current session
|
|
84
|
-
2. **localStorage**: Persistent across browser sessions
|
|
85
|
-
3. **sessionStorage**: Fallback for private browsing mode
|
|
86
|
-
4. **Auto-regeneration**: Downloads fresh data when cache is invalid
|
|
32
|
+
Generate a TWL TSV from a local USFM file:
|
|
87
33
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
- **Warm start** (browser cache): ~50-100ms
|
|
92
|
-
- **Hot start** (memory cache): ~1-5ms
|
|
34
|
+
```bash
|
|
35
|
+
twl-generator --usfm ./myfile.usfm
|
|
36
|
+
```
|
|
93
37
|
|
|
94
|
-
|
|
38
|
+
Specify output file:
|
|
95
39
|
|
|
96
|
-
|
|
40
|
+
```bash
|
|
41
|
+
twl-generator --usfm ./myfile.usfm --output ./output.tsv
|
|
42
|
+
```
|
|
97
43
|
|
|
98
|
-
|
|
44
|
+
You can also combine `--book` and `--usfm` (book is used for output filename and context):
|
|
99
45
|
|
|
100
|
-
|
|
46
|
+
```bash
|
|
47
|
+
twl-generator --usfm ./myfile.usfm --book rut
|
|
48
|
+
```
|
|
101
49
|
|
|
102
|
-
|
|
50
|
+
---
|
|
103
51
|
|
|
104
|
-
|
|
52
|
+
### As a Library (Node.js/ESM/React)
|
|
105
53
|
|
|
106
|
-
|
|
54
|
+
Install as a dependency:
|
|
107
55
|
|
|
108
|
-
|
|
56
|
+
```bash
|
|
57
|
+
npm install twl-generator
|
|
58
|
+
```
|
|
109
59
|
|
|
110
|
-
|
|
60
|
+
#### Example: Generate TWL TSV from USFM string
|
|
111
61
|
|
|
112
|
-
|
|
62
|
+
```js
|
|
63
|
+
import { generateTWLWithUsfm } from 'twl-generator';
|
|
113
64
|
|
|
114
|
-
|
|
65
|
+
// USFM string (can be loaded from file, API, etc.)
|
|
66
|
+
const usfmContent = `
|
|
67
|
+
\\id MAT
|
|
68
|
+
\\c 1
|
|
69
|
+
\\v 1 In the beginning...
|
|
70
|
+
`;
|
|
115
71
|
|
|
116
|
-
|
|
117
|
-
# Global installation (for CLI usage)
|
|
118
|
-
npm install -g twl-generator
|
|
72
|
+
const book = 'mat'; // Book code (optional if USFM contains book info)
|
|
119
73
|
|
|
120
|
-
|
|
121
|
-
|
|
74
|
+
const tsv = await generateTWLWithUsfm(book, usfmContent);
|
|
75
|
+
// tsv is a string in TSV format, ready to save or process
|
|
76
|
+
console.log(tsv);
|
|
122
77
|
```
|
|
123
78
|
|
|
124
|
-
|
|
79
|
+
#### Example: Generate TWL TSV by fetching USFM for a book
|
|
125
80
|
|
|
126
|
-
|
|
81
|
+
```js
|
|
82
|
+
import { generateTWLWithUsfm } from 'twl-generator';
|
|
127
83
|
|
|
128
|
-
|
|
84
|
+
const book = 'rut'; // Book code
|
|
129
85
|
|
|
130
|
-
|
|
86
|
+
const tsv = await generateTWLWithUsfm(book);
|
|
87
|
+
// This will fetch the USFM for the book from Door43 and return the TSV string
|
|
88
|
+
console.log(tsv);
|
|
89
|
+
```
|
|
131
90
|
|
|
132
|
-
|
|
91
|
+
---
|
|
133
92
|
|
|
134
|
-
|
|
93
|
+
### API Reference
|
|
135
94
|
|
|
136
|
-
|
|
137
|
-
- **ID**: Unique 4-character identifier
|
|
138
|
-
- **Tags**: Article category ("keyterm", "name", or empty)
|
|
139
|
-
- **OrigWords**: The matched text from the source
|
|
140
|
-
- **Occurrence**: Occurrence number for this term in this verse
|
|
141
|
-
- **TWLink**: Link to the translation words article
|
|
142
|
-
- **Disambiguation**: Multiple article options (if applicable)
|
|
143
|
-
- **Context**: Verse text with [matched term] in brackets
|
|
95
|
+
#### `generateTWLWithUsfm(book, usfmContent?)`
|
|
144
96
|
|
|
145
|
-
|
|
97
|
+
- `book`: (string) Book code (e.g., 'mat', 'rut'). Required if `usfmContent` is not provided.
|
|
98
|
+
- `usfmContent`: (string, optional) USFM file content. If provided, this is used instead of fetching from Door43.
|
|
99
|
+
- **Returns:** `Promise<string>` — TSV string of TWL matches.
|
|
146
100
|
|
|
147
|
-
|
|
148
|
-
- **Browser**: Modern browser with ES6 modules support
|
|
149
|
-
- **React.js**: >=16.8.0 (for React usage)
|
|
101
|
+
---
|
|
150
102
|
|
|
151
103
|
## License
|
|
152
104
|
|
|
153
|
-
MIT
|
|
105
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "twl-generator",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.12",
|
|
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": {
|