Skip to content

Commit

Permalink
Merge pull request #48 from jaw111/fix-hdt-utility
Browse files Browse the repository at this point in the history
Migrate the hdt utility to new interfaces
  • Loading branch information
RubenVerborgh authored Jun 16, 2020
2 parents 30b2bbb + f39222f commit ed586cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ install:
script:
- npm run lint
- npm test
- bin/hdt test/test.hdt --format turtle --query 'http://example.org/s1 ?p ?o' | grep 'http://example.org/p1'
cache:
directories:
- node_modules
28 changes: 15 additions & 13 deletions bin/hdt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var args = require('minimist')(process.argv.slice(2), { alias:
query = typeof args.query === 'string' ? args.query : '',
format = typeof args.format === 'string' ? args.format : 'text/turtle',
offset = /^\d+$/.test(args.offset) ? args.offset : 0,
limit = /^\d+$/.test(args.limit) ? args.limit : 0;
limit = /^\d+$/.test(args.limit) ? args.limit : Infinity;

// Verify the arguments
if (args._.length !== 1 || args.h || args.help) {
Expand All @@ -16,7 +16,8 @@ if (args._.length !== 1 || args.h || args.help) {
}

var hdt = require('../lib/hdt'),
N3 = require('n3');
N3 = require('n3'),
{ stringToTerm } = require('rdf-string');

// Prepare the query and the result writer
var parts = /^\s*<?([^\s>]*)>?\s*<?([^\s>]*)>?\s*<?([^]*?)>?\s*$/.exec(query),
Expand All @@ -27,15 +28,16 @@ var writer = new N3.Writer(process.stdout, { format: format, end: false });

// Load the HDT file
hdt.fromFile(hdtFile)
.then(hdtDocument => hdtDocument.search(subject, predicate, object, { offset: offset, limit: limit }))
.then(
results => {
process.stdout.write('# Total matches: ' + results.totalCount +
.then(hdtDocument => hdtDocument.searchTriples(
stringToTerm(subject), stringToTerm(predicate), stringToTerm(object),
{ offset: offset, limit: limit }))
.then(results => {
process.stdout.write('# Total matches: ' + results.totalCount +
(results.exactCount ? '' : ' (estimated)') + '\n');
writer.addQuads(results.triples);
writer.end();
},
error => {
console.error(error.message), process.exit(1);
}
);
writer.addQuads(results.triples);
writer.end();
})
.catch(error => {
console.error(error.message);
process.exit(1);
});

0 comments on commit ed586cf

Please sign in to comment.