@lde/pipeline 0.6.20 → 0.6.21
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.
|
@@ -21,7 +21,8 @@ export interface SparqlWriterOptions {
|
|
|
21
21
|
/**
|
|
22
22
|
* Writes RDF data to a SPARQL endpoint using SPARQL UPDATE INSERT DATA queries.
|
|
23
23
|
*
|
|
24
|
-
*
|
|
24
|
+
* Clears the named graph before writing, then streams quads in batches
|
|
25
|
+
* to avoid accumulating the entire dataset in memory.
|
|
25
26
|
*/
|
|
26
27
|
export declare class SparqlUpdateWriter implements Writer {
|
|
27
28
|
private readonly endpoint;
|
|
@@ -29,6 +30,8 @@ export declare class SparqlUpdateWriter implements Writer {
|
|
|
29
30
|
private readonly batchSize;
|
|
30
31
|
constructor(options: SparqlWriterOptions);
|
|
31
32
|
write(dataset: Dataset, quads: AsyncIterable<Quad>): Promise<void>;
|
|
33
|
+
private clearGraph;
|
|
32
34
|
private insertBatch;
|
|
35
|
+
private executeUpdate;
|
|
33
36
|
}
|
|
34
37
|
//# sourceMappingURL=sparqlUpdateWriter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sparqlUpdateWriter.d.ts","sourceRoot":"","sources":["../../src/writer/sparqlUpdateWriter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"sparqlUpdateWriter.d.ts","sourceRoot":"","sources":["../../src/writer/sparqlUpdateWriter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAGrC,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,QAAQ,EAAE,GAAG,CAAC;IACd;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,UAAU,CAAC,KAAK,CAAC;IAChC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;GAKG;AACH,qBAAa,kBAAmB,YAAW,MAAM;IAC/C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAM;IAC/B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA0B;IAChD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEvB,OAAO,EAAE,mBAAmB;IAMlC,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;YAS1D,UAAU;YAIV,WAAW;YAOX,aAAa;CAgB5B"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { batch } from '../batch.js';
|
|
1
2
|
import { serializeQuads } from './serialize.js';
|
|
2
3
|
/**
|
|
3
4
|
* Writes RDF data to a SPARQL endpoint using SPARQL UPDATE INSERT DATA queries.
|
|
4
5
|
*
|
|
5
|
-
*
|
|
6
|
+
* Clears the named graph before writing, then streams quads in batches
|
|
7
|
+
* to avoid accumulating the entire dataset in memory.
|
|
6
8
|
*/
|
|
7
9
|
export class SparqlUpdateWriter {
|
|
8
10
|
endpoint;
|
|
@@ -15,22 +17,19 @@ export class SparqlUpdateWriter {
|
|
|
15
17
|
}
|
|
16
18
|
async write(dataset, quads) {
|
|
17
19
|
const graphUri = dataset.iri.toString();
|
|
18
|
-
|
|
19
|
-
for await (const
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
if (collected.length === 0) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
// Process in batches to avoid hitting endpoint size limits.
|
|
26
|
-
for (let i = 0; i < collected.length; i += this.batchSize) {
|
|
27
|
-
const batch = collected.slice(i, i + this.batchSize);
|
|
28
|
-
await this.insertBatch(graphUri, batch);
|
|
20
|
+
await this.clearGraph(graphUri);
|
|
21
|
+
for await (const chunk of batch(quads, this.batchSize)) {
|
|
22
|
+
await this.insertBatch(graphUri, chunk);
|
|
29
23
|
}
|
|
30
24
|
}
|
|
25
|
+
async clearGraph(graphUri) {
|
|
26
|
+
await this.executeUpdate(`CLEAR GRAPH <${graphUri}>`);
|
|
27
|
+
}
|
|
31
28
|
async insertBatch(graphUri, quads) {
|
|
32
29
|
const turtleData = await serializeQuads(quads, 'N-Triples');
|
|
33
|
-
|
|
30
|
+
await this.executeUpdate(`INSERT DATA { GRAPH <${graphUri}> { ${turtleData} } }`);
|
|
31
|
+
}
|
|
32
|
+
async executeUpdate(query) {
|
|
34
33
|
const response = await this.fetch(this.endpoint.toString(), {
|
|
35
34
|
method: 'POST',
|
|
36
35
|
headers: {
|