n3 1.17.0 → 1.17.2
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.
- package/README.md +10 -6
- package/browser/n3.min.js +1 -1
- package/lib/IRIs.js +4 -5
- package/lib/N3DataFactory.js +121 -137
- package/lib/N3Lexer.js +106 -139
- package/lib/N3Parser.js +275 -403
- package/lib/N3Store.js +294 -317
- package/lib/N3StreamParser.js +11 -14
- package/lib/N3StreamWriter.js +7 -11
- package/lib/N3Util.js +19 -25
- package/lib/N3Writer.js +124 -154
- package/lib/index.js +4 -18
- package/package.json +41 -18
- package/src/N3DataFactory.js +31 -24
- package/src/N3Store.js +68 -49
- package/src/N3Writer.js +2 -2
package/lib/N3StreamParser.js
CHANGED
|
@@ -4,22 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _N3Parser = _interopRequireDefault(require("./N3Parser"));
|
|
9
|
-
|
|
10
8
|
var _readableStream = require("readable-stream");
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
// **N3StreamParser** parses a text stream into a quad stream.
|
|
11
|
+
|
|
15
12
|
// ## Constructor
|
|
16
13
|
class N3StreamParser extends _readableStream.Transform {
|
|
17
14
|
constructor(options) {
|
|
18
15
|
super({
|
|
19
16
|
decodeStrings: true
|
|
20
17
|
});
|
|
21
|
-
this._readableState.objectMode = true;
|
|
18
|
+
this._readableState.objectMode = true;
|
|
22
19
|
|
|
20
|
+
// Set up parser with dummy stream to obtain `data` and `end` callbacks
|
|
23
21
|
const parser = new _N3Parser.default(options);
|
|
24
22
|
let onData, onEnd;
|
|
25
23
|
parser.parse({
|
|
@@ -28,32 +26,33 @@ class N3StreamParser extends _readableStream.Transform {
|
|
|
28
26
|
case 'data':
|
|
29
27
|
onData = callback;
|
|
30
28
|
break;
|
|
31
|
-
|
|
32
29
|
case 'end':
|
|
33
30
|
onEnd = callback;
|
|
34
31
|
break;
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
|
-
},
|
|
34
|
+
},
|
|
35
|
+
// Handle quads by pushing them down the pipeline
|
|
38
36
|
(error, quad) => {
|
|
39
37
|
error && this.emit('error', error) || quad && this.push(quad);
|
|
40
|
-
},
|
|
38
|
+
},
|
|
39
|
+
// Emit prefixes through the `prefix` event
|
|
41
40
|
(prefix, uri) => {
|
|
42
41
|
this.emit('prefix', prefix, uri);
|
|
43
|
-
});
|
|
42
|
+
});
|
|
44
43
|
|
|
44
|
+
// Implement Transform methods through parser callbacks
|
|
45
45
|
this._transform = (chunk, encoding, done) => {
|
|
46
46
|
onData(chunk);
|
|
47
47
|
done();
|
|
48
48
|
};
|
|
49
|
-
|
|
50
49
|
this._flush = done => {
|
|
51
50
|
onEnd();
|
|
52
51
|
done();
|
|
53
52
|
};
|
|
54
|
-
}
|
|
55
|
-
|
|
53
|
+
}
|
|
56
54
|
|
|
55
|
+
// ### Parses a stream of strings
|
|
57
56
|
import(stream) {
|
|
58
57
|
stream.on('data', chunk => {
|
|
59
58
|
this.write(chunk);
|
|
@@ -66,7 +65,5 @@ class N3StreamParser extends _readableStream.Transform {
|
|
|
66
65
|
});
|
|
67
66
|
return this;
|
|
68
67
|
}
|
|
69
|
-
|
|
70
68
|
}
|
|
71
|
-
|
|
72
69
|
exports.default = N3StreamParser;
|
package/lib/N3StreamWriter.js
CHANGED
|
@@ -4,22 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _readableStream = require("readable-stream");
|
|
9
|
-
|
|
10
8
|
var _N3Writer = _interopRequireDefault(require("./N3Writer"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
// **N3StreamWriter** serializes a quad stream into a text stream.
|
|
11
|
+
|
|
15
12
|
// ## Constructor
|
|
16
13
|
class N3StreamWriter extends _readableStream.Transform {
|
|
17
14
|
constructor(options) {
|
|
18
15
|
super({
|
|
19
16
|
encoding: 'utf8',
|
|
20
17
|
writableObjectMode: true
|
|
21
|
-
});
|
|
18
|
+
});
|
|
22
19
|
|
|
20
|
+
// Set up writer with a dummy stream object
|
|
23
21
|
const writer = this._writer = new _N3Writer.default({
|
|
24
22
|
write: (quad, encoding, callback) => {
|
|
25
23
|
this.push(quad);
|
|
@@ -29,18 +27,18 @@ class N3StreamWriter extends _readableStream.Transform {
|
|
|
29
27
|
this.push(null);
|
|
30
28
|
callback && callback();
|
|
31
29
|
}
|
|
32
|
-
}, options);
|
|
30
|
+
}, options);
|
|
33
31
|
|
|
32
|
+
// Implement Transform methods on top of writer
|
|
34
33
|
this._transform = (quad, encoding, done) => {
|
|
35
34
|
writer.addQuad(quad, done);
|
|
36
35
|
};
|
|
37
|
-
|
|
38
36
|
this._flush = done => {
|
|
39
37
|
writer.end(done);
|
|
40
38
|
};
|
|
41
|
-
}
|
|
42
|
-
|
|
39
|
+
}
|
|
43
40
|
|
|
41
|
+
// ### Serializes a stream of quads
|
|
44
42
|
import(stream) {
|
|
45
43
|
stream.on('data', quad => {
|
|
46
44
|
this.write(quad);
|
|
@@ -56,7 +54,5 @@ class N3StreamWriter extends _readableStream.Transform {
|
|
|
56
54
|
});
|
|
57
55
|
return this;
|
|
58
56
|
}
|
|
59
|
-
|
|
60
57
|
}
|
|
61
|
-
|
|
62
58
|
exports.default = N3StreamWriter;
|
package/lib/N3Util.js
CHANGED
|
@@ -11,75 +11,69 @@ exports.isNamedNode = isNamedNode;
|
|
|
11
11
|
exports.isVariable = isVariable;
|
|
12
12
|
exports.prefix = prefix;
|
|
13
13
|
exports.prefixes = prefixes;
|
|
14
|
-
|
|
15
14
|
var _N3DataFactory = _interopRequireDefault(require("./N3DataFactory"));
|
|
16
|
-
|
|
17
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
|
|
19
16
|
// **N3Util** provides N3 utility functions.
|
|
17
|
+
|
|
20
18
|
// Tests whether the given term represents an IRI
|
|
21
19
|
function isNamedNode(term) {
|
|
22
20
|
return !!term && term.termType === 'NamedNode';
|
|
23
|
-
}
|
|
24
|
-
|
|
21
|
+
}
|
|
25
22
|
|
|
23
|
+
// Tests whether the given term represents a blank node
|
|
26
24
|
function isBlankNode(term) {
|
|
27
25
|
return !!term && term.termType === 'BlankNode';
|
|
28
|
-
}
|
|
29
|
-
|
|
26
|
+
}
|
|
30
27
|
|
|
28
|
+
// Tests whether the given term represents a literal
|
|
31
29
|
function isLiteral(term) {
|
|
32
30
|
return !!term && term.termType === 'Literal';
|
|
33
|
-
}
|
|
34
|
-
|
|
31
|
+
}
|
|
35
32
|
|
|
33
|
+
// Tests whether the given term represents a variable
|
|
36
34
|
function isVariable(term) {
|
|
37
35
|
return !!term && term.termType === 'Variable';
|
|
38
|
-
}
|
|
39
|
-
|
|
36
|
+
}
|
|
40
37
|
|
|
38
|
+
// Tests whether the given term represents the default graph
|
|
41
39
|
function isDefaultGraph(term) {
|
|
42
40
|
return !!term && term.termType === 'DefaultGraph';
|
|
43
|
-
}
|
|
44
|
-
|
|
41
|
+
}
|
|
45
42
|
|
|
43
|
+
// Tests whether the given quad is in the default graph
|
|
46
44
|
function inDefaultGraph(quad) {
|
|
47
45
|
return isDefaultGraph(quad.graph);
|
|
48
|
-
}
|
|
49
|
-
|
|
46
|
+
}
|
|
50
47
|
|
|
48
|
+
// Creates a function that prepends the given IRI to a local name
|
|
51
49
|
function prefix(iri, factory) {
|
|
52
50
|
return prefixes({
|
|
53
51
|
'': iri.value || iri
|
|
54
52
|
}, factory)('');
|
|
55
|
-
}
|
|
56
|
-
|
|
53
|
+
}
|
|
57
54
|
|
|
55
|
+
// Creates a function that allows registering and expanding prefixes
|
|
58
56
|
function prefixes(defaultPrefixes, factory) {
|
|
59
57
|
// Add all of the default prefixes
|
|
60
58
|
const prefixes = Object.create(null);
|
|
59
|
+
for (const prefix in defaultPrefixes) processPrefix(prefix, defaultPrefixes[prefix]);
|
|
60
|
+
// Set the default factory if none was specified
|
|
61
|
+
factory = factory || _N3DataFactory.default;
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
factory = factory || _N3DataFactory.default; // Registers a new prefix (if an IRI was specified)
|
|
63
|
+
// Registers a new prefix (if an IRI was specified)
|
|
66
64
|
// or retrieves a function that expands an existing prefix (if no IRI was specified)
|
|
67
|
-
|
|
68
65
|
function processPrefix(prefix, iri) {
|
|
69
66
|
// Create a new prefix if an IRI is specified or the prefix doesn't exist
|
|
70
67
|
if (typeof iri === 'string') {
|
|
71
68
|
// Create a function that expands the prefix
|
|
72
69
|
const cache = Object.create(null);
|
|
73
|
-
|
|
74
70
|
prefixes[prefix] = local => {
|
|
75
71
|
return cache[local] || (cache[local] = factory.namedNode(iri + local));
|
|
76
72
|
};
|
|
77
73
|
} else if (!(prefix in prefixes)) {
|
|
78
74
|
throw new Error(`Unknown prefix: ${prefix}`);
|
|
79
75
|
}
|
|
80
|
-
|
|
81
76
|
return prefixes[prefix];
|
|
82
77
|
}
|
|
83
|
-
|
|
84
78
|
return processPrefix;
|
|
85
79
|
}
|