@lde/sparql-qlever 0.10.1 → 0.11.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.
@@ -1,5 +1,5 @@
1
1
  import { Importer as ImporterInterface, ImportFailed, ImportSuccessful, NotSupported } from '@lde/sparql-importer';
2
- import { Dataset } from '@lde/dataset';
2
+ import { Distribution } from '@lde/dataset';
3
3
  import { Downloader } from '@lde/distribution-downloader';
4
4
  import { TaskRunner } from '@lde/task-runner';
5
5
  export interface Options {
@@ -26,7 +26,7 @@ export declare class Importer implements ImporterInterface {
26
26
  private qleverOptions;
27
27
  private cacheIndex;
28
28
  constructor({ taskRunner, downloader, indexName, qleverOptions, cacheIndex, }: Options);
29
- import(dataset: Dataset): Promise<NotSupported | ImportSuccessful | ImportFailed>;
29
+ import(distributions: Distribution[]): Promise<NotSupported | ImportSuccessful | ImportFailed>;
30
30
  private doImport;
31
31
  private fileFormatFromMimeType;
32
32
  private parseTripleCount;
@@ -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;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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IACnG,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAMD;;;;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;IACtB,OAAO,CAAC,UAAU,CAAC;gBAEP,EACV,UAAU,EACV,UAAU,EACV,SAAS,EACT,aAAa,EACb,UAAU,GACX,EAAE,OAAO;IAWG,MAAM,CACjB,aAAa,EAAE,YAAY,EAAE,GAC5B,OAAO,CAAC,YAAY,GAAG,gBAAgB,GAAG,YAAY,CAAC;YA+B5C,QAAQ;IA4CtB,OAAO,CAAC,sBAAsB;IAQ9B,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,aAAa;IAIrB;;OAEG;YACW,eAAe;IA0B7B,yDAAyD;YAC3C,eAAe;YAaf,cAAc;YAKd,KAAK;CAyBpB"}
package/dist/importer.js CHANGED
@@ -28,10 +28,8 @@ export class Importer {
28
28
  };
29
29
  this.cacheIndex = cacheIndex ?? true;
30
30
  }
31
- async import(dataset) {
32
- const downloadDistributions = dataset
33
- .getDownloadDistributions()
34
- .filter((distribution) => distribution.mimeType !== undefined &&
31
+ async import(distributions) {
32
+ const downloadDistributions = distributions.filter((distribution) => distribution.mimeType !== undefined &&
35
33
  supportedFormats.has(distribution.mimeType));
36
34
  if (downloadDistributions.length === 0) {
37
35
  return new NotSupported();
@@ -61,10 +59,29 @@ export class Importer {
61
59
  const localFile = await this.downloader.download(distribution);
62
60
  if (await this.isIndexUpToDate(localFile)) {
63
61
  const tripleCount = await this.readTripleCount(localFile);
62
+ if (tripleCount === 0) {
63
+ return new ImportFailed(distribution, 'Index is cached but contains 0 triples');
64
+ }
64
65
  return new ImportSuccessful(distribution, undefined, tripleCount);
65
66
  }
66
- const logs = await this.index(localFile, this.fileFormatFromMimeType(distribution.mimeType));
67
+ const format = this.fileFormatFromMimeType(distribution.mimeType);
68
+ let logs;
69
+ try {
70
+ logs = await this.index(localFile, format);
71
+ }
72
+ catch (error) {
73
+ if (format === 'ttl' &&
74
+ error.message?.includes('multiline string literal')) {
75
+ logs = await this.index(localFile, format, false);
76
+ }
77
+ else {
78
+ throw error;
79
+ }
80
+ }
67
81
  const tripleCount = this.parseTripleCount(logs);
82
+ if (tripleCount === 0) {
83
+ return new ImportFailed(distribution, 'Indexed 0 triples from distribution');
84
+ }
68
85
  await this.writeCacheInfo(localFile);
69
86
  return new ImportSuccessful(distribution, undefined, tripleCount);
70
87
  }
@@ -126,12 +143,12 @@ export class Importer {
126
143
  const info = { sourceFile: basename(dataFile) };
127
144
  await writeFile(this.cacheInfoPath(dataFile), JSON.stringify(info));
128
145
  }
129
- async index(file, format) {
146
+ async index(file, format, parseParallel = true) {
130
147
  const settingsFile = 'index.settings.json';
131
148
  await writeFile(`${dirname(file)}/${settingsFile}`, JSON.stringify(this.qleverOptions));
132
149
  // TODO: write index to named volume instead of bind mount for better performance.
133
150
  const metadataFile = `${this.indexName}.meta-data.json`;
134
- const indexTask = await this.taskRunner.run(`(gunzip -c '${basename(file)}' 2>/dev/null || cat '${basename(file)}') | qlever-index -i ${this.indexName} -s ${settingsFile} -F ${format} -p true -f - && cat ${metadataFile}`);
151
+ const indexTask = await this.taskRunner.run(`(gunzip -c '${basename(file)}' 2>/dev/null || cat '${basename(file)}') | qlever-index -i ${this.indexName} -s ${settingsFile} -F ${format} -p true${parseParallel ? '' : ' --parse-parallel false'} -f - && cat ${metadataFile}`);
135
152
  return await this.taskRunner.wait(indexTask);
136
153
  }
137
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lde/sparql-qlever",
3
- "version": "0.10.1",
3
+ "version": "0.11.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.2",
27
27
  "@lde/distribution-downloader": "0.5.3",
28
- "@lde/sparql-importer": "0.4.1",
28
+ "@lde/sparql-importer": "0.4.2",
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",