UNPKG

rdf-stores

Version:

A TypeScript/JavaScript implementation of the RDF/JS store interface with support for quoted triples.

49 lines 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TermDictionaryNumberMap = 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 Map. */ class TermDictionaryNumberMap { constructor(dataFactory = new rdf_data_factory_1.DataFactory()) { this.lastId = 0; this.dictionary = new Map(); this.reverseDictionary = new Map(); this.features = { quotedTriples: false }; this.dataFactory = dataFactory; } encode(term) { const key = (0, rdf_string_1.termToString)(term); let encoded = this.dictionary.get(key); if (encoded === undefined) { encoded = this.lastId++; this.dictionary.set(key, encoded); this.reverseDictionary.set(encoded, key); } return encoded; } encodeOptional(term) { const key = (0, rdf_string_1.termToString)(term); return this.dictionary.get(key); } decode(encoding) { const string = this.reverseDictionary.get(encoding); if (string === undefined) { throw new Error(`The value ${encoding} is not present in this dictionary`); } return (0, rdf_string_1.stringToTerm)(string, this.dataFactory); } encodings() { return this.reverseDictionary.keys(); } findQuotedTriples(quotedTriplePattern) { throw new Error('findQuotedTriples is not supported'); } findQuotedTriplesEncoded(quotedTriplePattern) { throw new Error('findQuotedTriplesEncoded is not supported'); } } exports.TermDictionaryNumberMap = TermDictionaryNumberMap; //# sourceMappingURL=TermDictionaryNumberMap.js.map