rdf-stores
Version:
A TypeScript/JavaScript implementation of the RDF/JS store interface with support for quoted triples.
53 lines • 2.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TermDictionaryNumberRecordFullTerms = void 0;
const rdf_data_factory_1 = require("rdf-data-factory");
const rdf_string_1 = require("rdf-string");
/**
* A term dictionary that encodes to numbers, and stores the dictionary in memory in a Record.
* The reverse dictionary will store full RDF term objects,
* resulting in slightly better query performance at the cost of slightly higher memory usage.
*/
class TermDictionaryNumberRecordFullTerms {
constructor(dataFactory = new rdf_data_factory_1.DataFactory()) {
this.lastId = 0;
this.dictionary = {};
this.reverseDictionary = {};
this.features = { quotedTriples: false };
this.dataFactory = dataFactory;
}
encode(term) {
const key = (0, rdf_string_1.termToString)(term);
let encoded = this.dictionary[key];
if (encoded === undefined) {
encoded = this.lastId++;
this.dictionary[key] = encoded;
this.reverseDictionary[encoded] = term;
}
return encoded;
}
encodeOptional(term) {
const key = (0, rdf_string_1.termToString)(term);
return this.dictionary[key];
}
decode(encoding) {
const string = this.reverseDictionary[encoding];
if (string === undefined) {
throw new Error(`The value ${encoding} is not present in this dictionary`);
}
return string;
}
*encodings() {
for (const key of Object.keys(this.reverseDictionary)) {
yield Number.parseInt(key, 10);
}
}
findQuotedTriples(quotedTriplePattern) {
throw new Error('findQuotedTriples is not supported');
}
findQuotedTriplesEncoded(quotedTriplePattern) {
throw new Error('findQuotedTriplesEncoded is not supported');
}
}
exports.TermDictionaryNumberRecordFullTerms = TermDictionaryNumberRecordFullTerms;
//# sourceMappingURL=TermDictionaryNumberRecordFullTerms.js.map