@lde/sparql-qlever 0.8.5 → 0.9.0

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.
@@ -26,6 +26,7 @@ export declare class Importer implements ImporterInterface {
26
26
  import(dataset: Dataset): Promise<NotSupported | ImportSuccessful | ImportFailed>;
27
27
  private doImport;
28
28
  private fileFormatFromMimeType;
29
+ private parseTripleCount;
29
30
  private index;
30
31
  }
31
32
  //# sourceMappingURL=importer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"importer.d.ts","sourceRoot":"","sources":["../src/importer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,IAAI,iBAAiB,EAC7B,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAgB,MAAM,cAAc,CAAC;AACrD,OAAO,EACL,UAAU,EAEX,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,WAAW,OAAO;IACtB,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,aAAa,CAAC,EAAE;QACd,qBAAqB,EAAE,OAAO,CAAC;QAC/B,uBAAuB,EAAE,MAAM,CAAC;KACjC,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,qBAAa,QAAS,YAAW,iBAAiB;IAChD,OAAO,CAAC,SAAS,CAAC;IAClB,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,UAAU,CAAC;IACnB,OAAO,CAAC,aAAa,CAAC;gBAEV,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,OAAO;IAU5D,MAAM,CACjB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,YAAY,GAAG,gBAAgB,GAAG,YAAY,CAAC;YAgC5C,QAAQ;IAYtB,OAAO,CAAC,sBAAsB;YAahB,KAAK;CAsBpB"}
1
+ {"version":3,"file":"importer.d.ts","sourceRoot":"","sources":["../src/importer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,IAAI,iBAAiB,EAC7B,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAgB,MAAM,cAAc,CAAC;AACrD,OAAO,EACL,UAAU,EAEX,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAU9C,MAAM,WAAW,OAAO;IACtB,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,aAAa,CAAC,EAAE;QACd,qBAAqB,EAAE,OAAO,CAAC;QAC/B,uBAAuB,EAAE,MAAM,CAAC;KACjC,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,qBAAa,QAAS,YAAW,iBAAiB;IAChD,OAAO,CAAC,SAAS,CAAC;IAClB,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,UAAU,CAAC;IACnB,OAAO,CAAC,aAAa,CAAC;gBAEV,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,OAAO;IAU5D,MAAM,CACjB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,YAAY,GAAG,gBAAgB,GAAG,YAAY,CAAC;YAiC5C,QAAQ;IAatB,OAAO,CAAC,sBAAsB;IAQ9B,OAAO,CAAC,gBAAgB;YAQV,KAAK;CAuBpB"}
package/dist/importer.js CHANGED
@@ -2,6 +2,11 @@ import { ImportFailed, ImportSuccessful, NotSupported, } from '@lde/sparql-impor
2
2
  import { LastModifiedDownloader, } from '@lde/distribution-downloader';
3
3
  import { basename, dirname } from 'path';
4
4
  import { writeFile } from 'node:fs/promises';
5
+ const supportedFormats = new Map([
6
+ ['application/n-triples', 'nt'],
7
+ ['application/n-quads', 'nq'],
8
+ ['text/turtle', 'ttl'],
9
+ ]);
5
10
  /**
6
11
  * Import RDF to a QLever SPARQL server.
7
12
  *
@@ -24,7 +29,8 @@ export class Importer {
24
29
  async import(dataset) {
25
30
  const downloadDistributions = dataset
26
31
  .getDownloadDistributions()
27
- .filter((distribution) => distribution.mimeType !== undefined);
32
+ .filter((distribution) => distribution.mimeType !== undefined &&
33
+ supportedFormats.has(distribution.mimeType));
28
34
  if (downloadDistributions.length === 0) {
29
35
  return new NotSupported();
30
36
  }
@@ -51,20 +57,23 @@ export class Importer {
51
57
  }
52
58
  async doImport(distribution) {
53
59
  const localFile = await this.downloader.download(distribution);
54
- await this.index(localFile, this.fileFormatFromMimeType(distribution.mimeType));
55
- return new ImportSuccessful(distribution);
60
+ const logs = await this.index(localFile, this.fileFormatFromMimeType(distribution.mimeType));
61
+ const tripleCount = this.parseTripleCount(logs);
62
+ return new ImportSuccessful(distribution, undefined, tripleCount);
56
63
  }
57
64
  fileFormatFromMimeType(mimeType) {
58
- switch (mimeType) {
59
- case 'application/n-triples':
60
- return 'nt';
61
- case 'application/n-quads':
62
- return 'nq';
63
- case 'text/turtle':
64
- return 'ttl';
65
- default:
66
- throw new Error(`Unsupported media type: ${mimeType}`);
65
+ const format = supportedFormats.get(mimeType);
66
+ if (format === undefined) {
67
+ throw new Error(`Unsupported media type: ${mimeType}`);
67
68
  }
69
+ return format;
70
+ }
71
+ parseTripleCount(logs) {
72
+ // Extract num-triples.normal from the metadata JSON that the index
73
+ // command cats to stdout. Use a regex rather than JSON.parse because
74
+ // Docker log multiplexing prepends binary frame headers to each chunk.
75
+ const match = logs.match(/"num-triples":\{[^}]*"normal":(\d+)/);
76
+ return match ? Number(match[1]) : undefined;
68
77
  }
69
78
  async index(file, format) {
70
79
  const workingDir = dirname(file);
@@ -76,7 +85,8 @@ export class Importer {
76
85
  : this.qleverOptions;
77
86
  await writeFile(`${workingDir}/${settingsFile}`, JSON.stringify(settings));
78
87
  // TODO: write index to named volume instead of bind mount for better performance.
79
- const indexTask = await this.taskRunner.run(`(zcat '${basename(file)}' 2>/dev/null || cat '${basename(file)}') | qlever-index -i ${this.indexName} -s ${settingsFile} -F ${format} -f -`);
80
- await this.taskRunner.wait(indexTask);
88
+ const metadataFile = `${this.indexName}.meta-data.json`;
89
+ const indexTask = await this.taskRunner.run(`(zcat '${basename(file)}' 2>/dev/null || cat '${basename(file)}') | qlever-index -i ${this.indexName} -s ${settingsFile} -F ${format} -f - && cat ${metadataFile}`);
90
+ return await this.taskRunner.wait(indexTask);
81
91
  }
82
92
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lde/sparql-qlever",
3
- "version": "0.8.5",
3
+ "version": "0.9.0",
4
4
  "repository": {
5
5
  "url": "git+https://github.com/ldelements/lde.git",
6
6
  "directory": "packages/sparql-qlever"
@@ -25,7 +25,7 @@
25
25
  "dependencies": {
26
26
  "@lde/dataset": "0.7.1",
27
27
  "@lde/distribution-downloader": "0.5.1",
28
- "@lde/sparql-importer": "0.3.1",
28
+ "@lde/sparql-importer": "0.4.0",
29
29
  "@lde/sparql-server": "0.4.10",
30
30
  "@lde/task-runner": "0.2.10",
31
31
  "@lde/task-runner-docker": "0.2.11",