rdfjs-resource 2.0.5 → 2.0.7
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/dist/AbstractTermValue.d.ts +4 -2
- package/dist/AbstractTermValue.js +5 -2
- package/dist/DatasetObjectValues.js +3 -1
- package/dist/DatasetSubjectValues.js +3 -1
- package/dist/DatasetValues.d.ts +6 -2
- package/dist/DatasetValues.js +3 -1
- package/dist/IdentifierValue.js +3 -1
- package/dist/Resource.d.ts +15 -4
- package/dist/Resource.js +36 -21
- package/dist/ResourceSet.d.ts +3 -1
- package/dist/ResourceSet.js +6 -3
- package/dist/TermValue.d.ts +4 -2
- package/dist/TermValue.js +5 -3
- package/package.json +3 -3
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
|
|
1
|
+
import type { BlankNode, DataFactory, Literal, NamedNode } from "@rdfjs/types";
|
|
2
2
|
import { Either } from "purify-ts";
|
|
3
3
|
import { MistypedTermValueError } from "./MistypedTermValueError.js";
|
|
4
4
|
import { Resource } from "./Resource.js";
|
|
5
5
|
export declare abstract class AbstractTermValue<TermT extends BlankNode | Literal | NamedNode> {
|
|
6
|
+
protected readonly dataFactory: DataFactory;
|
|
6
7
|
protected readonly focusResource: Resource;
|
|
7
8
|
protected readonly predicate: NamedNode;
|
|
8
9
|
protected readonly term: TermT;
|
|
9
|
-
constructor({ focusResource, predicate, term, }: {
|
|
10
|
+
constructor({ dataFactory, focusResource, predicate, term, }: {
|
|
11
|
+
dataFactory: DataFactory;
|
|
10
12
|
focusResource: Resource;
|
|
11
13
|
predicate: NamedNode;
|
|
12
14
|
term: TermT;
|
|
@@ -2,7 +2,8 @@ import { Either, Left } from "purify-ts";
|
|
|
2
2
|
import { MistypedTermValueError } from "./MistypedTermValueError.js";
|
|
3
3
|
import { Resource } from "./Resource.js";
|
|
4
4
|
export class AbstractTermValue {
|
|
5
|
-
constructor({ focusResource, predicate, term, }) {
|
|
5
|
+
constructor({ dataFactory, focusResource, predicate, term, }) {
|
|
6
|
+
this.dataFactory = dataFactory;
|
|
6
7
|
this.focusResource = focusResource;
|
|
7
8
|
this.predicate = predicate;
|
|
8
9
|
this.term = term;
|
|
@@ -30,7 +31,9 @@ export class AbstractTermValue {
|
|
|
30
31
|
* Try to convert the term to a named resource.
|
|
31
32
|
*/
|
|
32
33
|
toNamedResource() {
|
|
33
|
-
return this.toIri().map((identifier) => new Resource(this.focusResource.dataset, identifier
|
|
34
|
+
return this.toIri().map((identifier) => new Resource(this.focusResource.dataset, identifier, {
|
|
35
|
+
dataFactory: this.dataFactory,
|
|
36
|
+
}));
|
|
34
37
|
}
|
|
35
38
|
toTerm() {
|
|
36
39
|
return this.term;
|
|
@@ -22,6 +22,7 @@ export class DatasetObjectValues extends DatasetValues {
|
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
24
|
yield new TermValue({
|
|
25
|
+
dataFactory: this.dataFactory,
|
|
25
26
|
focusResource: this.focusResource,
|
|
26
27
|
predicate: this.predicate,
|
|
27
28
|
term: nonUniqueTerm,
|
|
@@ -32,6 +33,7 @@ export class DatasetObjectValues extends DatasetValues {
|
|
|
32
33
|
else {
|
|
33
34
|
for (const nonUniqueTerm of this.nonUniqueTermIterator()) {
|
|
34
35
|
yield new TermValue({
|
|
36
|
+
dataFactory: this.dataFactory,
|
|
35
37
|
focusResource: this.focusResource,
|
|
36
38
|
predicate: this.predicate,
|
|
37
39
|
term: nonUniqueTerm,
|
|
@@ -53,7 +55,7 @@ export class DatasetObjectValues extends DatasetValues {
|
|
|
53
55
|
// }
|
|
54
56
|
// }
|
|
55
57
|
// } else {
|
|
56
|
-
for (const quad of this.focusResource.dataset.match(this.focusResource.identifier, this.predicate, null,
|
|
58
|
+
for (const quad of this.focusResource.dataset.match(this.focusResource.identifier, this.predicate, null, this.graph)) {
|
|
57
59
|
switch (quad.object.termType) {
|
|
58
60
|
case "BlankNode":
|
|
59
61
|
case "Literal":
|
|
@@ -15,6 +15,7 @@ export class DatasetSubjectValues extends DatasetValues {
|
|
|
15
15
|
continue;
|
|
16
16
|
}
|
|
17
17
|
yield new IdentifierValue({
|
|
18
|
+
dataFactory: this.dataFactory,
|
|
18
19
|
focusResource: this.focusResource,
|
|
19
20
|
predicate: this.predicate,
|
|
20
21
|
term: nonUniqueIdentifier,
|
|
@@ -25,6 +26,7 @@ export class DatasetSubjectValues extends DatasetValues {
|
|
|
25
26
|
else {
|
|
26
27
|
for (const nonUniqueIdentifier of this.nonUniqueIdentifierIterator()) {
|
|
27
28
|
yield new IdentifierValue({
|
|
29
|
+
dataFactory: this.dataFactory,
|
|
28
30
|
focusResource: this.focusResource,
|
|
29
31
|
predicate: this.predicate,
|
|
30
32
|
term: nonUniqueIdentifier,
|
|
@@ -33,7 +35,7 @@ export class DatasetSubjectValues extends DatasetValues {
|
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
*nonUniqueIdentifierIterator() {
|
|
36
|
-
for (const quad of this.focusResource.dataset.match(null, this.predicate, this.focusResource.identifier)) {
|
|
38
|
+
for (const quad of this.focusResource.dataset.match(null, this.predicate, this.focusResource.identifier, this.graph)) {
|
|
37
39
|
switch (quad.subject.termType) {
|
|
38
40
|
case "BlankNode":
|
|
39
41
|
case "NamedNode":
|
package/dist/DatasetValues.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import type { NamedNode } from "@rdfjs/types";
|
|
1
|
+
import type { DataFactory, NamedNode, Quad_Graph, Variable } from "@rdfjs/types";
|
|
2
2
|
import type { Resource } from "./Resource.js";
|
|
3
3
|
import { Values } from "./Values.js";
|
|
4
4
|
export declare abstract class DatasetValues<ValueT> extends Values<ValueT> {
|
|
5
|
+
protected readonly dataFactory: DataFactory;
|
|
6
|
+
protected readonly graph: Exclude<Quad_Graph, Variable> | null;
|
|
5
7
|
protected readonly unique: boolean;
|
|
6
|
-
constructor({ focusResource, predicate, unique, }: {
|
|
8
|
+
constructor({ dataFactory, focusResource, graph, predicate, unique, }: {
|
|
9
|
+
dataFactory: DataFactory;
|
|
7
10
|
focusResource: Resource;
|
|
11
|
+
graph: Exclude<Quad_Graph, Variable> | null;
|
|
8
12
|
predicate: NamedNode;
|
|
9
13
|
unique: boolean;
|
|
10
14
|
});
|
package/dist/DatasetValues.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Values } from "./Values.js";
|
|
2
2
|
export class DatasetValues extends Values {
|
|
3
|
-
constructor({ focusResource, predicate, unique, }) {
|
|
3
|
+
constructor({ dataFactory, focusResource, graph, predicate, unique, }) {
|
|
4
4
|
super({ focusResource, predicate });
|
|
5
|
+
this.dataFactory = dataFactory;
|
|
6
|
+
this.graph = graph;
|
|
5
7
|
this.unique = unique;
|
|
6
8
|
}
|
|
7
9
|
get length() {
|
package/dist/IdentifierValue.js
CHANGED
|
@@ -8,7 +8,9 @@ export class IdentifierValue extends AbstractTermValue {
|
|
|
8
8
|
return this.term;
|
|
9
9
|
}
|
|
10
10
|
toResource() {
|
|
11
|
-
return new Resource(this.focusResource.dataset, this.term
|
|
11
|
+
return new Resource(this.focusResource.dataset, this.term, {
|
|
12
|
+
dataFactory: this.dataFactory,
|
|
13
|
+
});
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
//# sourceMappingURL=IdentifierValue.js.map
|
package/dist/Resource.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export declare class Resource<IdentifierT extends Resource.Identifier = Resource
|
|
|
15
15
|
readonly dataset: DatasetCore;
|
|
16
16
|
readonly identifier: IdentifierT;
|
|
17
17
|
private readonly dataFactory;
|
|
18
|
+
private readonly graph?;
|
|
18
19
|
private readonly literalFactory;
|
|
19
20
|
constructor(dataset: DatasetCore, identifier: IdentifierT, options?: {
|
|
20
21
|
dataFactory?: DataFactory;
|
|
@@ -47,10 +48,12 @@ export declare class Resource<IdentifierT extends Resource.Identifier = Resource
|
|
|
47
48
|
delete(predicate: NamedNode, object?: AddableValue | readonly AddableValue[], graph?: Exclude<Quad_Graph, Variable>): this;
|
|
48
49
|
isInstanceOf(class_: NamedNode, options?: {
|
|
49
50
|
excludeSubclasses?: boolean;
|
|
51
|
+
graph?: Exclude<Quad_Graph, Variable>;
|
|
50
52
|
instanceOfPredicate?: NamedNode;
|
|
51
53
|
subClassOfPredicate?: NamedNode;
|
|
52
54
|
}): boolean;
|
|
53
55
|
isSubClassOf(class_: NamedNode, options?: {
|
|
56
|
+
graph?: Exclude<Quad_Graph, Variable>;
|
|
54
57
|
subClassOfPredicate?: NamedNode;
|
|
55
58
|
}): boolean;
|
|
56
59
|
/**
|
|
@@ -60,26 +63,34 @@ export declare class Resource<IdentifierT extends Resource.Identifier = Resource
|
|
|
60
63
|
/**
|
|
61
64
|
* Consider the resource itself as an RDF list.
|
|
62
65
|
*/
|
|
63
|
-
toList(
|
|
66
|
+
toList(options?: {
|
|
67
|
+
graph?: Exclude<Quad_Graph, Variable>;
|
|
68
|
+
}): Either<Resource.ValueError, readonly Resource.TermValue[]>;
|
|
64
69
|
/**
|
|
65
70
|
* Get the first matching value of dataset statements (this.identifier, predicate, value).
|
|
66
71
|
*/
|
|
67
|
-
value(predicate: NamedNode
|
|
72
|
+
value(predicate: NamedNode, options?: {
|
|
73
|
+
graph?: Exclude<Quad_Graph, Variable>;
|
|
74
|
+
}): Either<Resource.ValueError, Resource.TermValue>;
|
|
68
75
|
/**
|
|
69
76
|
* Get the first matching subject of dataset statements (subject, predicate, this.identifier).
|
|
70
77
|
*/
|
|
71
|
-
valueOf(predicate: NamedNode
|
|
78
|
+
valueOf(predicate: NamedNode, options?: {
|
|
79
|
+
graph?: Exclude<Quad_Graph, Variable>;
|
|
80
|
+
}): Either<Resource.ValueError, Resource.IdentifierValue>;
|
|
72
81
|
/**
|
|
73
82
|
* Get all values of dataset statements (this.identifier, predicate, value).
|
|
74
83
|
*/
|
|
75
84
|
values(predicate: NamedNode, options?: {
|
|
85
|
+
graph?: Exclude<Quad_Graph, Variable>;
|
|
76
86
|
unique?: boolean;
|
|
77
87
|
}): Resource.Values<Resource.TermValue>;
|
|
78
88
|
/**
|
|
79
89
|
* Get the subject of dataset statements (subject, predicate, this.identifier).
|
|
80
90
|
*/
|
|
81
91
|
valuesOf(predicate: NamedNode, options?: {
|
|
82
|
-
|
|
92
|
+
graph?: Exclude<Quad_Graph, Variable>;
|
|
93
|
+
unique?: boolean;
|
|
83
94
|
}): Resource.Values<Resource.IdentifierValue>;
|
|
84
95
|
private addableValueToTerm;
|
|
85
96
|
private addableValuesToTerms;
|
package/dist/Resource.js
CHANGED
|
@@ -27,7 +27,7 @@ export class Resource {
|
|
|
27
27
|
*/
|
|
28
28
|
add(predicate, object, graph) {
|
|
29
29
|
for (const term of this.addableValuesToTerms(object)) {
|
|
30
|
-
this.dataset.add(this.dataFactory.quad(this.identifier, predicate, term, graph));
|
|
30
|
+
this.dataset.add(this.dataFactory.quad(this.identifier, predicate, term, graph ?? this.graph));
|
|
31
31
|
}
|
|
32
32
|
return this;
|
|
33
33
|
}
|
|
@@ -46,8 +46,11 @@ export class Resource {
|
|
|
46
46
|
}
|
|
47
47
|
const mintSubListIdentifier = options?.mintSubListIdentifier ?? (() => this.dataFactory.blankNode());
|
|
48
48
|
const listResource = new Resource(this.dataset, mintSubListIdentifier(itemsArray[0], 0), { dataFactory: this.dataFactory });
|
|
49
|
-
listResource.addListItems(itemsArray, {
|
|
50
|
-
|
|
49
|
+
listResource.addListItems(itemsArray, {
|
|
50
|
+
graph: options?.graph,
|
|
51
|
+
mintSubListIdentifier,
|
|
52
|
+
});
|
|
53
|
+
this.add(predicate, listResource.identifier, options?.graph);
|
|
51
54
|
return listResource;
|
|
52
55
|
}
|
|
53
56
|
/**
|
|
@@ -55,7 +58,7 @@ export class Resource {
|
|
|
55
58
|
*/
|
|
56
59
|
addListItems(items, options) {
|
|
57
60
|
const addSubListResourceValues = options?.addSubListResourceValues ?? (() => { });
|
|
58
|
-
const graph = options?.graph;
|
|
61
|
+
const graph = options?.graph ?? this.graph;
|
|
59
62
|
const mintSubListIdentifier = options?.mintSubListIdentifier ?? (() => this.dataFactory.blankNode());
|
|
60
63
|
let currentHead = this;
|
|
61
64
|
let itemIndex = 0;
|
|
@@ -86,7 +89,7 @@ export class Resource {
|
|
|
86
89
|
delete(predicate, object, graph) {
|
|
87
90
|
if (!object) {
|
|
88
91
|
for (const quad of [
|
|
89
|
-
...this.dataset.match(this.identifier, predicate, null, graph),
|
|
92
|
+
...this.dataset.match(this.identifier, predicate, null, graph ?? this.graph),
|
|
90
93
|
]) {
|
|
91
94
|
this.dataset.delete(quad);
|
|
92
95
|
}
|
|
@@ -94,7 +97,7 @@ export class Resource {
|
|
|
94
97
|
else {
|
|
95
98
|
for (const term of this.addableValuesToTerms(object)) {
|
|
96
99
|
for (const quad of [
|
|
97
|
-
...this.dataset.match(this.identifier, predicate, term, graph),
|
|
100
|
+
...this.dataset.match(this.identifier, predicate, term, graph ?? this.graph),
|
|
98
101
|
]) {
|
|
99
102
|
this.dataset.delete(quad);
|
|
100
103
|
}
|
|
@@ -106,11 +109,12 @@ export class Resource {
|
|
|
106
109
|
return isInstanceOfRecursive({
|
|
107
110
|
class_,
|
|
108
111
|
dataset: this.dataset,
|
|
112
|
+
graph: options?.graph ?? this.graph,
|
|
109
113
|
instance: this.identifier,
|
|
110
114
|
visitedClasses: new TermSet(),
|
|
111
115
|
});
|
|
112
|
-
function isInstanceOfRecursive({ class_, dataset, instance, visitedClasses, }) {
|
|
113
|
-
for (const _ of dataset.match(instance, options?.instanceOfPredicate ?? rdf.type, class_)) {
|
|
116
|
+
function isInstanceOfRecursive({ class_, dataset, graph, instance, visitedClasses, }) {
|
|
117
|
+
for (const _ of dataset.match(instance, options?.instanceOfPredicate ?? rdf.type, class_, graph)) {
|
|
114
118
|
return true;
|
|
115
119
|
}
|
|
116
120
|
visitedClasses.add(class_);
|
|
@@ -118,7 +122,7 @@ export class Resource {
|
|
|
118
122
|
return false;
|
|
119
123
|
}
|
|
120
124
|
// Recurse into class's sub-classes that haven't been visited yet.
|
|
121
|
-
for (const quad of dataset.match(null, options?.subClassOfPredicate ?? rdfs.subClassOf, class_,
|
|
125
|
+
for (const quad of dataset.match(null, options?.subClassOfPredicate ?? rdfs.subClassOf, class_, graph)) {
|
|
122
126
|
if (quad.subject.termType !== "NamedNode") {
|
|
123
127
|
continue;
|
|
124
128
|
}
|
|
@@ -128,6 +132,7 @@ export class Resource {
|
|
|
128
132
|
if (isInstanceOfRecursive({
|
|
129
133
|
class_: quad.subject,
|
|
130
134
|
dataset,
|
|
135
|
+
graph,
|
|
131
136
|
instance,
|
|
132
137
|
visitedClasses,
|
|
133
138
|
})) {
|
|
@@ -141,16 +146,17 @@ export class Resource {
|
|
|
141
146
|
return isSubClassOfRecursive({
|
|
142
147
|
class_,
|
|
143
148
|
dataset: this.dataset,
|
|
149
|
+
graph: options?.graph ?? this.graph,
|
|
144
150
|
thisIdentifier: this.identifier,
|
|
145
151
|
visitedClasses: new TermSet(),
|
|
146
152
|
});
|
|
147
|
-
function isSubClassOfRecursive({ class_, dataset, thisIdentifier, visitedClasses, }) {
|
|
148
|
-
for (const _ of dataset.match(thisIdentifier, options?.subClassOfPredicate ?? rdfs.subClassOf, class_)) {
|
|
153
|
+
function isSubClassOfRecursive({ class_, dataset, graph, thisIdentifier, visitedClasses, }) {
|
|
154
|
+
for (const _ of dataset.match(thisIdentifier, options?.subClassOfPredicate ?? rdfs.subClassOf, class_, graph)) {
|
|
149
155
|
return true;
|
|
150
156
|
}
|
|
151
157
|
visitedClasses.add(class_);
|
|
152
158
|
// Recurse into class's sub-classes that haven't been visited yet.
|
|
153
|
-
for (const quad of dataset.match(null, options?.subClassOfPredicate ?? rdfs.subClassOf, class_,
|
|
159
|
+
for (const quad of dataset.match(null, options?.subClassOfPredicate ?? rdfs.subClassOf, class_, graph)) {
|
|
154
160
|
if (quad.subject.termType !== "NamedNode") {
|
|
155
161
|
continue;
|
|
156
162
|
}
|
|
@@ -160,6 +166,7 @@ export class Resource {
|
|
|
160
166
|
if (isSubClassOfRecursive({
|
|
161
167
|
class_: quad.subject,
|
|
162
168
|
dataset,
|
|
169
|
+
graph,
|
|
163
170
|
thisIdentifier,
|
|
164
171
|
visitedClasses,
|
|
165
172
|
})) {
|
|
@@ -179,12 +186,13 @@ export class Resource {
|
|
|
179
186
|
/**
|
|
180
187
|
* Consider the resource itself as an RDF list.
|
|
181
188
|
*/
|
|
182
|
-
toList() {
|
|
189
|
+
toList(options) {
|
|
183
190
|
if (this.identifier.equals(rdf.nil)) {
|
|
184
191
|
return Either.of([]);
|
|
185
192
|
}
|
|
193
|
+
const graph = options?.graph ?? this.graph;
|
|
186
194
|
const firstObjects = [
|
|
187
|
-
...new TermSet([...this.dataset.match(this.identifier, rdf.first, null)].map((quad) => quad.object)),
|
|
195
|
+
...new TermSet([...this.dataset.match(this.identifier, rdf.first, null, graph)].map((quad) => quad.object)),
|
|
188
196
|
];
|
|
189
197
|
if (firstObjects.length === 0) {
|
|
190
198
|
return Left(new Resource.ListStructureError({
|
|
@@ -215,7 +223,7 @@ export class Resource {
|
|
|
215
223
|
}));
|
|
216
224
|
}
|
|
217
225
|
const restObjects = [
|
|
218
|
-
...new TermSet([...this.dataset.match(this.identifier, rdf.rest, null)].map((quad) => quad.object)),
|
|
226
|
+
...new TermSet([...this.dataset.match(this.identifier, rdf.rest, null, graph)].map((quad) => quad.object)),
|
|
219
227
|
];
|
|
220
228
|
if (restObjects.length === 0) {
|
|
221
229
|
return Left(new Resource.ListStructureError({
|
|
@@ -246,32 +254,37 @@ export class Resource {
|
|
|
246
254
|
}
|
|
247
255
|
return Either.of([
|
|
248
256
|
new Resource.TermValue({
|
|
257
|
+
dataFactory: this.dataFactory,
|
|
249
258
|
focusResource: this,
|
|
250
259
|
predicate: rdf.first,
|
|
251
260
|
term: firstObject,
|
|
252
261
|
}),
|
|
253
|
-
]).chain((items) => new Resource(this.dataset, restObject
|
|
254
|
-
.
|
|
262
|
+
]).chain((items) => new Resource(this.dataset, restObject, {
|
|
263
|
+
dataFactory: this.dataFactory,
|
|
264
|
+
})
|
|
265
|
+
.toList({ graph })
|
|
255
266
|
.map((restItems) => items.concat(restItems)));
|
|
256
267
|
}
|
|
257
268
|
/**
|
|
258
269
|
* Get the first matching value of dataset statements (this.identifier, predicate, value).
|
|
259
270
|
*/
|
|
260
|
-
value(predicate) {
|
|
261
|
-
return this.values(predicate).head();
|
|
271
|
+
value(predicate, options) {
|
|
272
|
+
return this.values(predicate, options).head();
|
|
262
273
|
}
|
|
263
274
|
/**
|
|
264
275
|
* Get the first matching subject of dataset statements (subject, predicate, this.identifier).
|
|
265
276
|
*/
|
|
266
|
-
valueOf(predicate) {
|
|
267
|
-
return this.valuesOf(predicate).head();
|
|
277
|
+
valueOf(predicate, options) {
|
|
278
|
+
return this.valuesOf(predicate, options).head();
|
|
268
279
|
}
|
|
269
280
|
/**
|
|
270
281
|
* Get all values of dataset statements (this.identifier, predicate, value).
|
|
271
282
|
*/
|
|
272
283
|
values(predicate, options) {
|
|
273
284
|
return new DatasetObjectValues({
|
|
285
|
+
dataFactory: this.dataFactory,
|
|
274
286
|
focusResource: this,
|
|
287
|
+
graph: options?.graph ?? this.graph ?? null,
|
|
275
288
|
predicate,
|
|
276
289
|
unique: !!options?.unique,
|
|
277
290
|
});
|
|
@@ -281,7 +294,9 @@ export class Resource {
|
|
|
281
294
|
*/
|
|
282
295
|
valuesOf(predicate, options) {
|
|
283
296
|
return new DatasetSubjectValues({
|
|
297
|
+
dataFactory: this.dataFactory,
|
|
284
298
|
focusResource: this,
|
|
299
|
+
graph: options?.graph ?? this.graph ?? null,
|
|
285
300
|
predicate,
|
|
286
301
|
unique: !!options?.unique,
|
|
287
302
|
});
|
package/dist/ResourceSet.d.ts
CHANGED
|
@@ -6,12 +6,14 @@ import { Resource } from "./Resource.js";
|
|
|
6
6
|
export declare class ResourceSet {
|
|
7
7
|
readonly dataset: DatasetCore;
|
|
8
8
|
private readonly dataFactory;
|
|
9
|
+
private readonly graph?;
|
|
9
10
|
constructor(dataset: DatasetCore, options?: {
|
|
10
11
|
dataFactory?: DataFactory;
|
|
12
|
+
graph?: Exclude<Quad_Graph, Variable>;
|
|
11
13
|
});
|
|
12
14
|
instancesOf(class_: NamedNode, options?: {
|
|
13
15
|
excludeSubclasses?: boolean;
|
|
14
|
-
graph?: Exclude<Quad_Graph, Variable
|
|
16
|
+
graph?: Exclude<Quad_Graph, Variable>;
|
|
15
17
|
instanceOfPredicate?: NamedNode;
|
|
16
18
|
subClassOfPredicate?: NamedNode;
|
|
17
19
|
}): Generator<Resource>;
|
package/dist/ResourceSet.js
CHANGED
|
@@ -9,6 +9,7 @@ export class ResourceSet {
|
|
|
9
9
|
constructor(dataset, options) {
|
|
10
10
|
this.dataset = dataset;
|
|
11
11
|
this.dataFactory = options?.dataFactory ?? DefaultDataFactory;
|
|
12
|
+
this.graph = options?.graph;
|
|
12
13
|
}
|
|
13
14
|
*instancesOf(class_, options) {
|
|
14
15
|
for (const identifier of this.instanceIdentifiers(class_, options)) {
|
|
@@ -30,12 +31,13 @@ export class ResourceSet {
|
|
|
30
31
|
yield* instanceIdentifiersRecursive({
|
|
31
32
|
class_,
|
|
32
33
|
dataset: this.dataset,
|
|
34
|
+
graph: options?.graph ?? this.graph,
|
|
33
35
|
visitedClasses: new TermSet(),
|
|
34
36
|
yieldedInstanceIdentifiers: new TermSet(),
|
|
35
37
|
});
|
|
36
|
-
function* instanceIdentifiersRecursive({ class_, dataset, visitedClasses, yieldedInstanceIdentifiers, }) {
|
|
38
|
+
function* instanceIdentifiersRecursive({ class_, dataset, graph, visitedClasses, yieldedInstanceIdentifiers, }) {
|
|
37
39
|
// Get instanceQuads of the class
|
|
38
|
-
for (const quad of dataset.match(null, options?.instanceOfPredicate ?? rdf.type, class_,
|
|
40
|
+
for (const quad of dataset.match(null, options?.instanceOfPredicate ?? rdf.type, class_, graph)) {
|
|
39
41
|
switch (quad.subject.termType) {
|
|
40
42
|
case "BlankNode":
|
|
41
43
|
case "NamedNode":
|
|
@@ -53,7 +55,7 @@ export class ResourceSet {
|
|
|
53
55
|
return;
|
|
54
56
|
}
|
|
55
57
|
// Recurse into class's sub-classes that haven't been visited yet.
|
|
56
|
-
for (const quad of dataset.match(null, options?.subClassOfPredicate ?? rdfs.subClassOf, class_,
|
|
58
|
+
for (const quad of dataset.match(null, options?.subClassOfPredicate ?? rdfs.subClassOf, class_, graph)) {
|
|
57
59
|
if (quad.subject.termType !== "NamedNode") {
|
|
58
60
|
continue;
|
|
59
61
|
}
|
|
@@ -63,6 +65,7 @@ export class ResourceSet {
|
|
|
63
65
|
yield* instanceIdentifiersRecursive({
|
|
64
66
|
class_: quad.subject,
|
|
65
67
|
dataset,
|
|
68
|
+
graph,
|
|
66
69
|
visitedClasses,
|
|
67
70
|
yieldedInstanceIdentifiers,
|
|
68
71
|
});
|
package/dist/TermValue.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BlankNode, Literal, NamedNode } from "@rdfjs/types";
|
|
1
|
+
import type { BlankNode, Literal, NamedNode, Quad_Graph, Variable } from "@rdfjs/types";
|
|
2
2
|
import { Either } from "purify-ts";
|
|
3
3
|
import { AbstractTermValue } from "./AbstractTermValue.js";
|
|
4
4
|
import type { Identifier } from "./Identifier.js";
|
|
@@ -42,7 +42,9 @@ export declare class TermValue extends AbstractTermValue<BlankNode | Literal | N
|
|
|
42
42
|
/**
|
|
43
43
|
* Try to convert the term to an RDF list.
|
|
44
44
|
*/
|
|
45
|
-
toList(
|
|
45
|
+
toList(options?: {
|
|
46
|
+
graph?: Exclude<Quad_Graph, Variable>;
|
|
47
|
+
}): Either<ValueError, readonly TermValue[]>;
|
|
46
48
|
/**
|
|
47
49
|
* Try to convert the term to a Literal.
|
|
48
50
|
*/
|
package/dist/TermValue.js
CHANGED
|
@@ -70,8 +70,8 @@ export class TermValue extends AbstractTermValue {
|
|
|
70
70
|
/**
|
|
71
71
|
* Try to convert the term to an RDF list.
|
|
72
72
|
*/
|
|
73
|
-
toList() {
|
|
74
|
-
return this.toResource().chain((resource) => resource.toList());
|
|
73
|
+
toList(options) {
|
|
74
|
+
return this.toResource().chain((resource) => resource.toList({ graph: options?.graph }));
|
|
75
75
|
}
|
|
76
76
|
/**
|
|
77
77
|
* Try to convert the term to a Literal.
|
|
@@ -101,7 +101,9 @@ export class TermValue extends AbstractTermValue {
|
|
|
101
101
|
* Try to convert the term to a resource (identified by a blank node or IRI).
|
|
102
102
|
*/
|
|
103
103
|
toResource() {
|
|
104
|
-
return this.toIdentifier().map((identifier) => new Resource(this.focusResource.dataset, identifier
|
|
104
|
+
return this.toIdentifier().map((identifier) => new Resource(this.focusResource.dataset, identifier, {
|
|
105
|
+
dataFactory: this.dataFactory,
|
|
106
|
+
}));
|
|
105
107
|
}
|
|
106
108
|
/**
|
|
107
109
|
* Try to convert the term to a string literal.
|
package/package.json
CHANGED
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"description": "Resource abstraction over RDF/JS Datasets",
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"@biomejs/biome": "2.3.10",
|
|
13
|
+
"@rdfjs/dataset": "~2.0.2",
|
|
13
14
|
"@tpluscode/rdf-ns-builders": "~4.3.0",
|
|
14
15
|
"@tsconfig/strictest": "~2.0.8",
|
|
15
|
-
"@types/
|
|
16
|
+
"@types/rdfjs__dataset": "~2.0.7",
|
|
16
17
|
"@vitest/coverage-v8": "~4.0.18",
|
|
17
18
|
"housemd": "0.1.3",
|
|
18
|
-
"n3": "~1.26.0",
|
|
19
19
|
"rimraf": "~6.0.1",
|
|
20
20
|
"typescript": "5.9.3",
|
|
21
21
|
"vitest": "~4.0.18"
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
},
|
|
47
47
|
"type": "module",
|
|
48
48
|
"types": "dist/index.d.ts",
|
|
49
|
-
"version": "2.0.
|
|
49
|
+
"version": "2.0.7"
|
|
50
50
|
}
|