n3 1.23.1 → 1.24.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.
- package/README.md +7 -0
- package/browser/n3.min.js +1 -1
- package/lib/IRIs.js +2 -1
- package/lib/N3Lexer.js +7 -1
- package/lib/N3Parser.js +6 -2
- package/lib/N3Store.js +20 -18
- package/package.json +2 -2
- package/src/IRIs.js +1 -0
- package/src/N3Lexer.js +8 -2
- package/src/N3Parser.js +4 -1
- package/src/N3Store.js +19 -18
package/lib/IRIs.js
CHANGED
package/lib/N3Lexer.js
CHANGED
|
@@ -84,6 +84,9 @@ class N3Lexer {
|
|
|
84
84
|
this._endOfFile = /^(?:#[^\n\r]*)?$/;
|
|
85
85
|
options = options || {};
|
|
86
86
|
|
|
87
|
+
// Whether the log:isImpliedBy predicate is supported
|
|
88
|
+
this._isImpliedBy = options.isImpliedBy;
|
|
89
|
+
|
|
87
90
|
// In line mode (N-Triples or N-Quads), only simple features may be parsed
|
|
88
91
|
if (this._lineMode = !!options.lineMode) {
|
|
89
92
|
this._n3Mode = false;
|
|
@@ -179,7 +182,10 @@ class N3Lexer {
|
|
|
179
182
|
// Try to find a nested triple
|
|
180
183
|
else if (input.length > 1 && input[1] === '<') type = '<<', matchLength = 2;
|
|
181
184
|
// Try to find a backwards implication arrow
|
|
182
|
-
else if (this._n3Mode && input.length > 1 && input[1] === '=')
|
|
185
|
+
else if (this._n3Mode && input.length > 1 && input[1] === '=') {
|
|
186
|
+
matchLength = 2;
|
|
187
|
+
if (this._isImpliedBy) type = 'abbreviation', value = '<';else type = 'inverse', value = '>';
|
|
188
|
+
}
|
|
183
189
|
break;
|
|
184
190
|
case '>':
|
|
185
191
|
if (input.length > 1 && input[1] === '>') type = '>>', matchLength = 2;
|
package/lib/N3Parser.js
CHANGED
|
@@ -34,6 +34,8 @@ class N3Parser {
|
|
|
34
34
|
if (!(this._supportsNamedGraphs = !(isTurtle || isN3))) this._readPredicateOrNamedGraph = this._readPredicate;
|
|
35
35
|
// Support triples in other graphs
|
|
36
36
|
this._supportsQuads = !(isTurtle || isTriG || isNTriples || isN3);
|
|
37
|
+
// Whether the log:isImpliedBy predicate is supported
|
|
38
|
+
this._isImpliedBy = options.isImpliedBy;
|
|
37
39
|
// Support nesting of triples
|
|
38
40
|
this._supportsRDFStar = format === '' || /star|\*$/.test(format);
|
|
39
41
|
// Disable relative IRIs in N-Triples or N-Quads mode
|
|
@@ -43,7 +45,8 @@ class N3Parser {
|
|
|
43
45
|
this._blankNodePrefix = typeof options.blankNodePrefix !== 'string' ? '' : options.blankNodePrefix.replace(/^(?!_:)/, '_:');
|
|
44
46
|
this._lexer = options.lexer || new _N3Lexer.default({
|
|
45
47
|
lineMode: isLineMode,
|
|
46
|
-
n3: isN3
|
|
48
|
+
n3: isN3,
|
|
49
|
+
isImpliedBy: this._isImpliedBy
|
|
47
50
|
});
|
|
48
51
|
// Disable explicit quantifiers by default
|
|
49
52
|
this._explicitQuantifiers = !!options.explicitQuantifiers;
|
|
@@ -1019,7 +1022,8 @@ function initDataFactory(parser, factory) {
|
|
|
1019
1022
|
parser.ABBREVIATIONS = {
|
|
1020
1023
|
'a': factory.namedNode(_IRIs.default.rdf.type),
|
|
1021
1024
|
'=': factory.namedNode(_IRIs.default.owl.sameAs),
|
|
1022
|
-
'>': factory.namedNode(_IRIs.default.log.implies)
|
|
1025
|
+
'>': factory.namedNode(_IRIs.default.log.implies),
|
|
1026
|
+
'<': factory.namedNode(_IRIs.default.log.isImpliedBy)
|
|
1023
1027
|
};
|
|
1024
1028
|
parser.QUANTIFIERS_GRAPH = factory.namedNode('urn:n3:quantifiers');
|
|
1025
1029
|
}
|
package/lib/N3Store.js
CHANGED
|
@@ -1083,26 +1083,28 @@ class DatasetCoreAndReadableStream extends _readableStream.Readable {
|
|
|
1083
1083
|
if (subject && !(subjectId = newStore._termToNumericId(subject)) || predicate && !(predicateId = newStore._termToNumericId(predicate)) || object && !(objectId = newStore._termToNumericId(object))) return newStore;
|
|
1084
1084
|
const graphs = n3Store._getGraphs(graph);
|
|
1085
1085
|
for (const graphKey in graphs) {
|
|
1086
|
-
let subjects, predicates, objects;
|
|
1087
|
-
if (
|
|
1088
|
-
if (
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1086
|
+
let subjects, predicates, objects, content;
|
|
1087
|
+
if (content = graphs[graphKey]) {
|
|
1088
|
+
if (!subjectId && predicateId) {
|
|
1089
|
+
if (predicates = indexMatch(content.predicates, [predicateId, objectId, subjectId])) {
|
|
1090
|
+
subjects = indexMatch(content.subjects, [subjectId, predicateId, objectId]);
|
|
1091
|
+
objects = indexMatch(content.objects, [objectId, subjectId, predicateId]);
|
|
1092
|
+
}
|
|
1093
|
+
} else if (objectId) {
|
|
1094
|
+
if (objects = indexMatch(content.objects, [objectId, subjectId, predicateId])) {
|
|
1095
|
+
subjects = indexMatch(content.subjects, [subjectId, predicateId, objectId]);
|
|
1096
|
+
predicates = indexMatch(content.predicates, [predicateId, objectId, subjectId]);
|
|
1097
|
+
}
|
|
1098
|
+
} else if (subjects = indexMatch(content.subjects, [subjectId, predicateId, objectId])) {
|
|
1099
|
+
predicates = indexMatch(content.predicates, [predicateId, objectId, subjectId]);
|
|
1100
|
+
objects = indexMatch(content.objects, [objectId, subjectId, predicateId]);
|
|
1096
1101
|
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1102
|
+
if (subjects) newStore._graphs[graphKey] = {
|
|
1103
|
+
subjects,
|
|
1104
|
+
predicates,
|
|
1105
|
+
objects
|
|
1106
|
+
};
|
|
1100
1107
|
}
|
|
1101
|
-
if (subjects) newStore._graphs[graphKey] = {
|
|
1102
|
-
subjects,
|
|
1103
|
-
predicates,
|
|
1104
|
-
objects
|
|
1105
|
-
};
|
|
1106
1108
|
}
|
|
1107
1109
|
newStore._size = null;
|
|
1108
1110
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n3",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.0",
|
|
4
4
|
"description": "Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.",
|
|
5
5
|
"author": "Ruben Verborgh <ruben.verborgh@gmail.com>",
|
|
6
6
|
"keywords": [
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"eslint-plugin-jest": "^28.8.3",
|
|
44
44
|
"jest": "^29.7.0",
|
|
45
45
|
"pre-commit": "^1.2.2",
|
|
46
|
-
"rdf-isomorphic": "^
|
|
46
|
+
"rdf-isomorphic": "^2.0.0",
|
|
47
47
|
"rdf-test-suite": "^1.25.0",
|
|
48
48
|
"streamify-string": "^1.0.1",
|
|
49
49
|
"uglify-js": "^3.14.3"
|
package/src/IRIs.js
CHANGED
package/src/N3Lexer.js
CHANGED
|
@@ -54,6 +54,9 @@ export default class N3Lexer {
|
|
|
54
54
|
this._endOfFile = /^(?:#[^\n\r]*)?$/;
|
|
55
55
|
options = options || {};
|
|
56
56
|
|
|
57
|
+
// Whether the log:isImpliedBy predicate is supported
|
|
58
|
+
this._isImpliedBy = options.isImpliedBy;
|
|
59
|
+
|
|
57
60
|
// In line mode (N-Triples or N-Quads), only simple features may be parsed
|
|
58
61
|
if (this._lineMode = !!options.lineMode) {
|
|
59
62
|
this._n3Mode = false;
|
|
@@ -152,8 +155,11 @@ export default class N3Lexer {
|
|
|
152
155
|
else if (input.length > 1 && input[1] === '<')
|
|
153
156
|
type = '<<', matchLength = 2;
|
|
154
157
|
// Try to find a backwards implication arrow
|
|
155
|
-
else if (this._n3Mode && input.length > 1 && input[1] === '=')
|
|
156
|
-
|
|
158
|
+
else if (this._n3Mode && input.length > 1 && input[1] === '=') {
|
|
159
|
+
matchLength = 2;
|
|
160
|
+
if (this._isImpliedBy) type = 'abbreviation', value = '<';
|
|
161
|
+
else type = 'inverse', value = '>';
|
|
162
|
+
}
|
|
157
163
|
break;
|
|
158
164
|
|
|
159
165
|
case '>':
|
package/src/N3Parser.js
CHANGED
|
@@ -27,6 +27,8 @@ export default class N3Parser {
|
|
|
27
27
|
this._readPredicateOrNamedGraph = this._readPredicate;
|
|
28
28
|
// Support triples in other graphs
|
|
29
29
|
this._supportsQuads = !(isTurtle || isTriG || isNTriples || isN3);
|
|
30
|
+
// Whether the log:isImpliedBy predicate is supported
|
|
31
|
+
this._isImpliedBy = options.isImpliedBy;
|
|
30
32
|
// Support nesting of triples
|
|
31
33
|
this._supportsRDFStar = format === '' || /star|\*$/.test(format);
|
|
32
34
|
// Disable relative IRIs in N-Triples or N-Quads mode
|
|
@@ -34,7 +36,7 @@ export default class N3Parser {
|
|
|
34
36
|
this._resolveRelativeIRI = iri => { return null; };
|
|
35
37
|
this._blankNodePrefix = typeof options.blankNodePrefix !== 'string' ? '' :
|
|
36
38
|
options.blankNodePrefix.replace(/^(?!_:)/, '_:');
|
|
37
|
-
this._lexer = options.lexer || new N3Lexer({ lineMode: isLineMode, n3: isN3 });
|
|
39
|
+
this._lexer = options.lexer || new N3Lexer({ lineMode: isLineMode, n3: isN3, isImpliedBy: this._isImpliedBy });
|
|
38
40
|
// Disable explicit quantifiers by default
|
|
39
41
|
this._explicitQuantifiers = !!options.explicitQuantifiers;
|
|
40
42
|
}
|
|
@@ -1096,6 +1098,7 @@ function initDataFactory(parser, factory) {
|
|
|
1096
1098
|
'a': factory.namedNode(namespaces.rdf.type),
|
|
1097
1099
|
'=': factory.namedNode(namespaces.owl.sameAs),
|
|
1098
1100
|
'>': factory.namedNode(namespaces.log.implies),
|
|
1101
|
+
'<': factory.namedNode(namespaces.log.isImpliedBy),
|
|
1099
1102
|
};
|
|
1100
1103
|
parser.QUANTIFIERS_GRAPH = factory.namedNode('urn:n3:quantifiers');
|
|
1101
1104
|
}
|
package/src/N3Store.js
CHANGED
|
@@ -1134,27 +1134,28 @@ class DatasetCoreAndReadableStream extends Readable {
|
|
|
1134
1134
|
|
|
1135
1135
|
const graphs = n3Store._getGraphs(graph);
|
|
1136
1136
|
for (const graphKey in graphs) {
|
|
1137
|
-
let subjects, predicates, objects;
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1137
|
+
let subjects, predicates, objects, content;
|
|
1138
|
+
if (content = graphs[graphKey]) {
|
|
1139
|
+
if (!subjectId && predicateId) {
|
|
1140
|
+
if (predicates = indexMatch(content.predicates, [predicateId, objectId, subjectId])) {
|
|
1141
|
+
subjects = indexMatch(content.subjects, [subjectId, predicateId, objectId]);
|
|
1142
|
+
objects = indexMatch(content.objects, [objectId, subjectId, predicateId]);
|
|
1143
|
+
}
|
|
1143
1144
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1145
|
+
else if (objectId) {
|
|
1146
|
+
if (objects = indexMatch(content.objects, [objectId, subjectId, predicateId])) {
|
|
1147
|
+
subjects = indexMatch(content.subjects, [subjectId, predicateId, objectId]);
|
|
1148
|
+
predicates = indexMatch(content.predicates, [predicateId, objectId, subjectId]);
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
else if (subjects = indexMatch(content.subjects, [subjectId, predicateId, objectId])) {
|
|
1152
|
+
predicates = indexMatch(content.predicates, [predicateId, objectId, subjectId]);
|
|
1153
|
+
objects = indexMatch(content.objects, [objectId, subjectId, predicateId]);
|
|
1149
1154
|
}
|
|
1150
|
-
}
|
|
1151
|
-
else if (subjects = indexMatch(graphs[graphKey].subjects, [subjectId, predicateId, objectId])) {
|
|
1152
|
-
predicates = indexMatch(graphs[graphKey].predicates, [predicateId, objectId, subjectId]);
|
|
1153
|
-
objects = indexMatch(graphs[graphKey].objects, [objectId, subjectId, predicateId]);
|
|
1154
|
-
}
|
|
1155
1155
|
|
|
1156
|
-
|
|
1157
|
-
|
|
1156
|
+
if (subjects)
|
|
1157
|
+
newStore._graphs[graphKey] = { subjects, predicates, objects };
|
|
1158
|
+
}
|
|
1158
1159
|
}
|
|
1159
1160
|
newStore._size = null;
|
|
1160
1161
|
}
|