triangle-utils 1.4.14 → 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/dist/src/UtilsMisc.d.ts +4 -0
- package/dist/src/UtilsMisc.js +14 -0
- package/package.json +1 -1
- package/src/UtilsMisc.ts +21 -0
package/dist/src/UtilsMisc.d.ts
CHANGED
|
@@ -28,6 +28,10 @@ export declare class UtilsMisc {
|
|
|
28
28
|
chunk_index: [number, number];
|
|
29
29
|
chunk_text: string;
|
|
30
30
|
}[];
|
|
31
|
+
static chunkify_pages(pages: string[], max_length?: number, overlap?: number): {
|
|
32
|
+
chunk_index: [number, number];
|
|
33
|
+
chunk_text: string;
|
|
34
|
+
}[];
|
|
31
35
|
static instantiate<T>(constructor: new (x: any) => T, x: any): T | undefined;
|
|
32
36
|
static instantiator<T>(constructor: new (x: any) => T): (x: any) => T | undefined;
|
|
33
37
|
}
|
package/dist/src/UtilsMisc.js
CHANGED
|
@@ -153,6 +153,20 @@ export class UtilsMisc {
|
|
|
153
153
|
chunk_text: text.substring(...chunk_index)
|
|
154
154
|
}));
|
|
155
155
|
}
|
|
156
|
+
static chunkify_pages(pages, max_length = 2500, overlap = 50) {
|
|
157
|
+
const chunks = [];
|
|
158
|
+
for (const page of pages) {
|
|
159
|
+
const page_chunks = UtilsMisc.chunkify(page, max_length, overlap);
|
|
160
|
+
const start_index = (chunks.length > 0 ? (chunks[chunks.length - 1].chunk_index[1]) : 0);
|
|
161
|
+
for (const page_chunk of page_chunks) {
|
|
162
|
+
chunks.push({
|
|
163
|
+
chunk_index: [page_chunk.chunk_index[0] + start_index, page_chunk.chunk_index[1] + start_index],
|
|
164
|
+
chunk_text: page_chunk.chunk_text + "\n\n"
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return chunks;
|
|
169
|
+
}
|
|
156
170
|
static instantiate(constructor, x) {
|
|
157
171
|
try {
|
|
158
172
|
const instance = new constructor(x);
|
package/package.json
CHANGED
package/src/UtilsMisc.ts
CHANGED
|
@@ -185,6 +185,27 @@ export class UtilsMisc {
|
|
|
185
185
|
}))
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
static chunkify_pages(pages : string[], max_length = 2500, overlap = 50) : {
|
|
189
|
+
chunk_index : [number, number],
|
|
190
|
+
chunk_text : string
|
|
191
|
+
}[] {
|
|
192
|
+
const chunks : {
|
|
193
|
+
chunk_index : [number, number],
|
|
194
|
+
chunk_text : string
|
|
195
|
+
}[] = []
|
|
196
|
+
for (const page of pages) {
|
|
197
|
+
const page_chunks = UtilsMisc.chunkify(page, max_length, overlap)
|
|
198
|
+
const start_index : number = (chunks.length > 0 ? (chunks[chunks.length - 1].chunk_index[1]) : 0)
|
|
199
|
+
for (const page_chunk of page_chunks) {
|
|
200
|
+
chunks.push({
|
|
201
|
+
chunk_index : [page_chunk.chunk_index[0] + start_index, page_chunk.chunk_index[1] + start_index],
|
|
202
|
+
chunk_text : page_chunk.chunk_text + "\n\n"
|
|
203
|
+
})
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return chunks
|
|
207
|
+
}
|
|
208
|
+
|
|
188
209
|
static instantiate<T>(constructor : new (x : any) => T, x : any) : T | undefined {
|
|
189
210
|
try {
|
|
190
211
|
const instance = new constructor(x)
|