@comunica/actor-abstract-path 3.3.0 → 4.0.1
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/components/ActorAbstractPath.jsonld +44 -19
- package/components/components.jsonld +1 -1
- package/components/context.jsonld +7 -1
- package/lib/ActorAbstractPath.d.ts +17 -12
- package/lib/ActorAbstractPath.js +44 -38
- package/lib/ActorAbstractPath.js.map +1 -1
- package/lib/PathVariableObjectIterator.d.ts +3 -2
- package/lib/PathVariableObjectIterator.js +6 -9
- package/lib/PathVariableObjectIterator.js.map +1 -1
- package/package.json +13 -9
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-abstract-path/^
|
|
4
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^
|
|
5
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-abstract-path/^4.0.0/components/context.jsonld",
|
|
4
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^4.0.0/components/context.jsonld",
|
|
5
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-query-operation/^4.0.0/components/context.jsonld"
|
|
6
6
|
],
|
|
7
7
|
"@id": "npmd:@comunica/actor-abstract-path",
|
|
8
8
|
"components": [
|
|
@@ -49,29 +49,37 @@
|
|
|
49
49
|
"genericTypeInstances": [
|
|
50
50
|
{
|
|
51
51
|
"@type": "ParameterRangeGenericTypeReference",
|
|
52
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
52
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
53
53
|
},
|
|
54
54
|
{
|
|
55
55
|
"@type": "ParameterRangeGenericTypeReference",
|
|
56
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
56
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
57
57
|
},
|
|
58
58
|
{
|
|
59
59
|
"@type": "ParameterRangeGenericTypeReference",
|
|
60
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
60
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
64
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
61
65
|
}
|
|
62
66
|
]
|
|
63
67
|
},
|
|
64
68
|
{
|
|
65
69
|
"@type": "ParameterRangeGenericTypeReference",
|
|
66
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
70
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
67
71
|
},
|
|
68
72
|
{
|
|
69
73
|
"@type": "ParameterRangeGenericTypeReference",
|
|
70
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
74
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
71
75
|
},
|
|
72
76
|
{
|
|
73
77
|
"@type": "ParameterRangeGenericTypeReference",
|
|
74
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
78
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
82
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
75
83
|
}
|
|
76
84
|
]
|
|
77
85
|
},
|
|
@@ -81,6 +89,20 @@
|
|
|
81
89
|
},
|
|
82
90
|
"comment": "The bus this actor subscribes to."
|
|
83
91
|
},
|
|
92
|
+
{
|
|
93
|
+
"@id": "caap:components/ActorAbstractPath.jsonld#ActorAbstractPath_args_busFailMessage",
|
|
94
|
+
"range": {
|
|
95
|
+
"@type": "ParameterRangeUnion",
|
|
96
|
+
"parameterRangeElements": [
|
|
97
|
+
"xsd:string",
|
|
98
|
+
{
|
|
99
|
+
"@type": "ParameterRangeUndefined"
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
"default": "Query operation processing failed: none of the configured actors were able to handle the operation type ${action.operation.type}",
|
|
104
|
+
"comment": "The message that will be configured in the bus for reporting failures. This message may be a template string that contains references to the executed `action`. For example, the following templated string is allowed: \"RDF dereferencing failed: no actors could handle ${action.handle.mediaType}\""
|
|
105
|
+
},
|
|
84
106
|
{
|
|
85
107
|
"@id": "caap:components/ActorAbstractPath.jsonld#ActorAbstractPath_args_beforeActors",
|
|
86
108
|
"range": {
|
|
@@ -94,15 +116,19 @@
|
|
|
94
116
|
"genericTypeInstances": [
|
|
95
117
|
{
|
|
96
118
|
"@type": "ParameterRangeGenericTypeReference",
|
|
97
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
119
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
98
120
|
},
|
|
99
121
|
{
|
|
100
122
|
"@type": "ParameterRangeGenericTypeReference",
|
|
101
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
123
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
102
124
|
},
|
|
103
125
|
{
|
|
104
126
|
"@type": "ParameterRangeGenericTypeReference",
|
|
105
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
127
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"@type": "ParameterRangeGenericTypeReference",
|
|
131
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^4.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
106
132
|
}
|
|
107
133
|
]
|
|
108
134
|
}
|
|
@@ -116,13 +142,6 @@
|
|
|
116
142
|
}
|
|
117
143
|
],
|
|
118
144
|
"memberFields": [
|
|
119
|
-
{
|
|
120
|
-
"@id": "caap:components/ActorAbstractPath.jsonld#ActorAbstractPath__member_FACTORY",
|
|
121
|
-
"memberFieldName": "FACTORY",
|
|
122
|
-
"range": {
|
|
123
|
-
"@type": "ParameterRangeWildcard"
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
145
|
{
|
|
127
146
|
"@id": "caap:components/ActorAbstractPath.jsonld#ActorAbstractPath__member_predicateType",
|
|
128
147
|
"memberFieldName": "predicateType",
|
|
@@ -191,6 +210,12 @@
|
|
|
191
210
|
"@id": "caap:components/ActorAbstractPath.jsonld#ActorAbstractPath_args_bus"
|
|
192
211
|
}
|
|
193
212
|
},
|
|
213
|
+
{
|
|
214
|
+
"keyRaw": "busFailMessage",
|
|
215
|
+
"value": {
|
|
216
|
+
"@id": "caap:components/ActorAbstractPath.jsonld#ActorAbstractPath_args_busFailMessage"
|
|
217
|
+
}
|
|
218
|
+
},
|
|
194
219
|
{
|
|
195
220
|
"keyRaw": "beforeActors",
|
|
196
221
|
"value": {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-abstract-path/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-abstract-path/^4.0.0/components/context.jsonld"
|
|
4
4
|
],
|
|
5
5
|
"@id": "npmd:@comunica/actor-abstract-path",
|
|
6
6
|
"@type": "Module",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"https://linkedsoftwaredependencies.org/bundles/npm/componentsjs/^6.0.0/components/context.jsonld",
|
|
4
4
|
{
|
|
5
5
|
"npmd": "https://linkedsoftwaredependencies.org/bundles/npm/",
|
|
6
|
-
"caap": "npmd:@comunica/actor-abstract-path/^
|
|
6
|
+
"caap": "npmd:@comunica/actor-abstract-path/^4.0.0/",
|
|
7
7
|
"ActorAbstractPath": {
|
|
8
8
|
"@id": "caap:components/ActorAbstractPath.jsonld#ActorAbstractPath",
|
|
9
9
|
"@prefix": true,
|
|
@@ -20,6 +20,9 @@
|
|
|
20
20
|
"args_bus": {
|
|
21
21
|
"@id": "caap:components/ActorAbstractPath.jsonld#ActorAbstractPath_args_bus"
|
|
22
22
|
},
|
|
23
|
+
"args_busFailMessage": {
|
|
24
|
+
"@id": "caap:components/ActorAbstractPath.jsonld#ActorAbstractPath_args_busFailMessage"
|
|
25
|
+
},
|
|
23
26
|
"args_beforeActors": {
|
|
24
27
|
"@id": "caap:components/ActorAbstractPath.jsonld#ActorAbstractPath_args_beforeActors",
|
|
25
28
|
"@container": "@list"
|
|
@@ -36,6 +39,9 @@
|
|
|
36
39
|
"bus": {
|
|
37
40
|
"@id": "caap:components/ActorAbstractPath.jsonld#ActorAbstractPath_args_bus"
|
|
38
41
|
},
|
|
42
|
+
"busFailMessage": {
|
|
43
|
+
"@id": "caap:components/ActorAbstractPath.jsonld#ActorAbstractPath_args_busFailMessage"
|
|
44
|
+
},
|
|
39
45
|
"beforeActors": {
|
|
40
46
|
"@id": "caap:components/ActorAbstractPath.jsonld#ActorAbstractPath_args_beforeActors",
|
|
41
47
|
"@container": "@list"
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import type { BindingsFactory } from '@comunica/bindings-factory';
|
|
2
1
|
import type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';
|
|
3
2
|
import { ActorQueryOperationTypedMediated } from '@comunica/bus-query-operation';
|
|
4
|
-
import type { IActorTest } from '@comunica/core';
|
|
5
|
-
import type { IQueryOperationResultBindings, Bindings, IActionContext, MetadataBindings, IQuerySourceWrapper } from '@comunica/types';
|
|
3
|
+
import type { IActorTest, TestResult } from '@comunica/core';
|
|
4
|
+
import type { IQueryOperationResultBindings, Bindings, IActionContext, MetadataBindings, IQuerySourceWrapper, ComunicaDataFactory } from '@comunica/types';
|
|
5
|
+
import type { BindingsFactory } from '@comunica/utils-bindings-factory';
|
|
6
6
|
import type * as RDF from '@rdfjs/types';
|
|
7
7
|
import type { AsyncIterator } from 'asynciterator';
|
|
8
8
|
import { BufferedIterator } from 'asynciterator';
|
|
9
|
-
import {
|
|
9
|
+
import type { Factory } from 'sparqlalgebrajs';
|
|
10
|
+
import { Algebra } from 'sparqlalgebrajs';
|
|
10
11
|
/**
|
|
11
12
|
* An abstract actor that handles Path operations.
|
|
12
13
|
*
|
|
13
14
|
* Provides multiple helper functions used by the Path operation actors.
|
|
14
15
|
*/
|
|
15
16
|
export declare abstract class ActorAbstractPath extends ActorQueryOperationTypedMediated<Algebra.Path> {
|
|
16
|
-
protected static readonly FACTORY: Factory;
|
|
17
17
|
protected readonly predicateType: string;
|
|
18
18
|
protected constructor(args: IActorQueryOperationTypedMediatedArgs, predicateType: string);
|
|
19
|
-
testOperation(operation: Algebra.Path, _context: IActionContext): Promise<IActorTest
|
|
20
|
-
generateVariable(path?: Algebra.Path, name?: string): RDF.Variable;
|
|
21
|
-
isPathArbitraryLengthDistinct(context: IActionContext, path: Algebra.Path): Promise<{
|
|
19
|
+
testOperation(operation: Algebra.Path, _context: IActionContext): Promise<TestResult<IActorTest>>;
|
|
20
|
+
generateVariable(dataFactory: ComunicaDataFactory, path?: Algebra.Path, name?: string): RDF.Variable;
|
|
21
|
+
isPathArbitraryLengthDistinct(algebraFactory: Factory, context: IActionContext, path: Algebra.Path): Promise<{
|
|
22
22
|
context: IActionContext;
|
|
23
23
|
operation: IQueryOperationResultBindings | undefined;
|
|
24
24
|
}>;
|
|
@@ -32,11 +32,14 @@ export declare abstract class ActorAbstractPath extends ActorQueryOperationTyped
|
|
|
32
32
|
* @param {Term} graph The graph in which we search for the pattern. (Possibly a variable)
|
|
33
33
|
* @param {ActionContext} context The context to pass to sub-opertations
|
|
34
34
|
* @param emitFirstSubject If the path operation is predicate*, otherwise it is predicate+.
|
|
35
|
+
* @param algebraFactory The algebra factory.
|
|
36
|
+
* @param bindingsFactory The data factory.
|
|
35
37
|
* @return {Promise<AsyncIterator<Bindings>} Iterator to where all bindings of query should have been pushed.
|
|
36
38
|
*/
|
|
37
|
-
getObjectsPredicateStarEval(subject: RDF.Term, predicate: Algebra.PropertyPathSymbol, object: RDF.Variable, graph: RDF.Term, context: IActionContext, emitFirstSubject: boolean, bindingsFactory: BindingsFactory): Promise<IPathResultStream>;
|
|
39
|
+
getObjectsPredicateStarEval(subject: RDF.Term, predicate: Algebra.PropertyPathSymbol, object: RDF.Variable, graph: RDF.Term, context: IActionContext, emitFirstSubject: boolean, algebraFactory: Factory, bindingsFactory: BindingsFactory): Promise<IPathResultStream>;
|
|
38
40
|
/**
|
|
39
41
|
* Pushes all terms to iterator `it` that are a solution of object predicate* ?o.
|
|
42
|
+
* @param algebraFactory The algebra factory.
|
|
40
43
|
* @param {Term} object Term of where we start the predicate* search.
|
|
41
44
|
* @param {Algebra.PropertyPathSymbol} predicate Predicate of the *-path.
|
|
42
45
|
* @param {Term} graph The graph in which we search for the pattern.
|
|
@@ -46,7 +49,7 @@ export declare abstract class ActorAbstractPath extends ActorQueryOperationTyped
|
|
|
46
49
|
* @param {any} counter Counts how many searches are in progress to close it when needed (when counter == 0).
|
|
47
50
|
* @return {Promise<IPathResultStream['metadata']>} The results metadata.
|
|
48
51
|
*/
|
|
49
|
-
getObjectsPredicateStar(object: RDF.Term, predicate: Algebra.PropertyPathSymbol, graph: RDF.Term, context: IActionContext, termHashes: Record<string, RDF.Term>, it: BufferedIterator<RDF.Term>, counter: any): Promise<IPathResultStream['metadata'] | undefined>;
|
|
52
|
+
getObjectsPredicateStar(algebraFactory: Factory, object: RDF.Term, predicate: Algebra.PropertyPathSymbol, graph: RDF.Term, context: IActionContext, termHashes: Record<string, RDF.Term>, it: BufferedIterator<RDF.Term>, counter: any): Promise<IPathResultStream['metadata'] | undefined>;
|
|
50
53
|
/**
|
|
51
54
|
* Pushes all terms to iterator `it` that are a solution of ?s predicate* ?o.
|
|
52
55
|
* @param {string} subjectVar String representation of subjectVariable
|
|
@@ -62,15 +65,17 @@ export declare abstract class ActorAbstractPath extends ActorQueryOperationTyped
|
|
|
62
65
|
* Remembers the pairs we've already searched for, can stop searching if so.
|
|
63
66
|
* @param {BufferedIterator<Bindings>} it Iterator to push terms to.
|
|
64
67
|
* @param {any} counter Counts how many searches are in progress to close it when needed (when counter == 0).
|
|
68
|
+
* @param algebraFactory The algebra factory.
|
|
69
|
+
* @param bindingsFactory The bindings factory.
|
|
65
70
|
* @return {Promise<void>} All solutions of query should have been pushed to it by then.
|
|
66
71
|
*/
|
|
67
|
-
getSubjectAndObjectBindingsPredicateStar(subjectVar: RDF.Variable, objectVar: RDF.Variable, subjectVal: RDF.Term, objectVal: RDF.Term, predicate: Algebra.PropertyPathSymbol, graph: RDF.Term, context: IActionContext, termHashesGlobal: Record<string, Promise<RDF.Term[]>>, termHashesCurrentSubject: Record<string, boolean>, it: BufferedIterator<Bindings>, counter: any, bindingsFactory: BindingsFactory): Promise<void>;
|
|
72
|
+
getSubjectAndObjectBindingsPredicateStar(subjectVar: RDF.Variable, objectVar: RDF.Variable, subjectVal: RDF.Term, objectVal: RDF.Term, predicate: Algebra.PropertyPathSymbol, graph: RDF.Term, context: IActionContext, termHashesGlobal: Record<string, Promise<RDF.Term[]>>, termHashesCurrentSubject: Record<string, boolean>, it: BufferedIterator<Bindings>, counter: any, algebraFactory: Factory, bindingsFactory: BindingsFactory): Promise<void>;
|
|
68
73
|
/**
|
|
69
74
|
* Find all sources recursively contained in the given path operation.
|
|
70
75
|
* @param operation
|
|
71
76
|
*/
|
|
72
77
|
getPathSources(operation: Algebra.PropertyPathSymbol): IQuerySourceWrapper[];
|
|
73
|
-
assignPatternSources(pattern: Algebra.Pattern, sources: IQuerySourceWrapper[]): Algebra.Operation;
|
|
78
|
+
assignPatternSources(algebraFactory: Factory, pattern: Algebra.Pattern, sources: IQuerySourceWrapper[]): Algebra.Operation;
|
|
74
79
|
}
|
|
75
80
|
export interface IPathResultStream {
|
|
76
81
|
bindingsStream: AsyncIterator<Bindings>;
|
package/lib/ActorAbstractPath.js
CHANGED
|
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ActorAbstractPath = void 0;
|
|
4
4
|
const bus_query_operation_1 = require("@comunica/bus-query-operation");
|
|
5
5
|
const context_entries_1 = require("@comunica/context-entries");
|
|
6
|
+
const core_1 = require("@comunica/core");
|
|
7
|
+
const utils_query_operation_1 = require("@comunica/utils-query-operation");
|
|
6
8
|
const asynciterator_1 = require("asynciterator");
|
|
7
|
-
const rdf_data_factory_1 = require("rdf-data-factory");
|
|
8
9
|
const rdf_string_1 = require("rdf-string");
|
|
9
10
|
const sparqlalgebrajs_1 = require("sparqlalgebrajs");
|
|
10
11
|
const PathVariableObjectIterator_1 = require("./PathVariableObjectIterator");
|
|
11
|
-
const DF = new rdf_data_factory_1.DataFactory();
|
|
12
12
|
/**
|
|
13
13
|
* An abstract actor that handles Path operations.
|
|
14
14
|
*
|
|
@@ -21,46 +21,46 @@ class ActorAbstractPath extends bus_query_operation_1.ActorQueryOperationTypedMe
|
|
|
21
21
|
}
|
|
22
22
|
async testOperation(operation, _context) {
|
|
23
23
|
if (operation.predicate.type !== this.predicateType) {
|
|
24
|
-
|
|
24
|
+
return (0, core_1.failTest)(`This Actor only supports ${this.predicateType} Path operations.`);
|
|
25
25
|
}
|
|
26
|
-
return
|
|
26
|
+
return (0, core_1.passTestVoid)();
|
|
27
27
|
}
|
|
28
28
|
// Generates a variable that does not yet occur in the path
|
|
29
|
-
generateVariable(path, name) {
|
|
29
|
+
generateVariable(dataFactory, path, name) {
|
|
30
30
|
if (!name) {
|
|
31
|
-
return this.generateVariable(path, 'b');
|
|
31
|
+
return this.generateVariable(dataFactory, path, 'b');
|
|
32
32
|
}
|
|
33
33
|
// Path predicates can't contain variables
|
|
34
34
|
if (path && (path.subject.value === name || path.object.value === name)) {
|
|
35
|
-
return this.generateVariable(path, `${name}b`);
|
|
35
|
+
return this.generateVariable(dataFactory, path, `${name}b`);
|
|
36
36
|
}
|
|
37
|
-
return
|
|
37
|
+
return dataFactory.variable(name);
|
|
38
38
|
}
|
|
39
39
|
// Such connectivity matching does not introduce duplicates (it does not incorporate any count of the number
|
|
40
40
|
// of ways the connection can be made) even if the repeated path itself would otherwise result in duplicates.
|
|
41
41
|
// https://www.w3.org/TR/sparql11-query/#propertypaths
|
|
42
|
-
async isPathArbitraryLengthDistinct(context, path) {
|
|
42
|
+
async isPathArbitraryLengthDistinct(algebraFactory, context, path) {
|
|
43
43
|
if (!context.get(context_entries_1.KeysQueryOperation.isPathArbitraryLengthDistinctKey)) {
|
|
44
44
|
context = context.set(context_entries_1.KeysQueryOperation.isPathArbitraryLengthDistinctKey, true);
|
|
45
|
-
return { context, operation:
|
|
46
|
-
operation:
|
|
45
|
+
return { context, operation: (0, utils_query_operation_1.getSafeBindings)(await this.mediatorQueryOperation.mediate({
|
|
46
|
+
operation: algebraFactory.createDistinct(path),
|
|
47
47
|
context,
|
|
48
48
|
})) };
|
|
49
49
|
}
|
|
50
50
|
context = context.set(context_entries_1.KeysQueryOperation.isPathArbitraryLengthDistinctKey, false);
|
|
51
51
|
return { context, operation: undefined };
|
|
52
52
|
}
|
|
53
|
-
async predicateStarGraphVariable(subject, object, predicate, graph, context, bindingsFactory) {
|
|
53
|
+
async predicateStarGraphVariable(subject, object, predicate, graph, context, algebraFactory, bindingsFactory) {
|
|
54
54
|
const sources = this.getPathSources(predicate);
|
|
55
55
|
// TODO: refactor this with an iterator just like PathVariableObjectIterator so we handle backpressure correctly
|
|
56
56
|
// Construct path to obtain all graphs where subject exists
|
|
57
|
-
const predVar = this.generateVariable(
|
|
57
|
+
const predVar = this.generateVariable(algebraFactory.dataFactory, algebraFactory
|
|
58
58
|
.createPath(subject, predicate, object, graph));
|
|
59
|
-
const findGraphs =
|
|
60
|
-
this.assignPatternSources(
|
|
61
|
-
this.assignPatternSources(
|
|
59
|
+
const findGraphs = algebraFactory.createUnion([
|
|
60
|
+
this.assignPatternSources(algebraFactory, algebraFactory.createPattern(subject, predVar, object, graph), sources),
|
|
61
|
+
this.assignPatternSources(algebraFactory, algebraFactory.createPattern(object, predVar, subject, graph), sources),
|
|
62
62
|
]);
|
|
63
|
-
const results =
|
|
63
|
+
const results = (0, utils_query_operation_1.getSafeBindings)(await this.mediatorQueryOperation.mediate({ context, operation: findGraphs }));
|
|
64
64
|
const passedGraphs = new Set();
|
|
65
65
|
const bindingsStream = new asynciterator_1.MultiTransformIterator(results.bindingsStream, {
|
|
66
66
|
multiTransform: (bindings) => {
|
|
@@ -72,7 +72,8 @@ class ActorAbstractPath extends bus_query_operation_1.ActorQueryOperationTypedMe
|
|
|
72
72
|
passedGraphs.add(graphValue.value);
|
|
73
73
|
return new asynciterator_1.TransformIterator(async () => {
|
|
74
74
|
const it = new asynciterator_1.BufferedIterator();
|
|
75
|
-
await this
|
|
75
|
+
await this
|
|
76
|
+
.getObjectsPredicateStar(algebraFactory, subject, predicate, graphValue, context, {}, it, { count: 0 });
|
|
76
77
|
return it.transform({
|
|
77
78
|
transform(item, next, push) {
|
|
78
79
|
push(bindingsFactory.bindings([
|
|
@@ -100,13 +101,16 @@ class ActorAbstractPath extends bus_query_operation_1.ActorQueryOperationTypedMe
|
|
|
100
101
|
* @param {Term} graph The graph in which we search for the pattern. (Possibly a variable)
|
|
101
102
|
* @param {ActionContext} context The context to pass to sub-opertations
|
|
102
103
|
* @param emitFirstSubject If the path operation is predicate*, otherwise it is predicate+.
|
|
104
|
+
* @param algebraFactory The algebra factory.
|
|
105
|
+
* @param bindingsFactory The data factory.
|
|
103
106
|
* @return {Promise<AsyncIterator<Bindings>} Iterator to where all bindings of query should have been pushed.
|
|
104
107
|
*/
|
|
105
|
-
async getObjectsPredicateStarEval(subject, predicate, object, graph, context, emitFirstSubject, bindingsFactory) {
|
|
108
|
+
async getObjectsPredicateStarEval(subject, predicate, object, graph, context, emitFirstSubject, algebraFactory, bindingsFactory) {
|
|
106
109
|
if (graph.termType === 'Variable') {
|
|
107
|
-
return this
|
|
110
|
+
return this
|
|
111
|
+
.predicateStarGraphVariable(subject, object, predicate, graph, context, algebraFactory, bindingsFactory);
|
|
108
112
|
}
|
|
109
|
-
const it = new PathVariableObjectIterator_1.PathVariableObjectIterator(subject, predicate, graph, context, this.mediatorQueryOperation, emitFirstSubject);
|
|
113
|
+
const it = new PathVariableObjectIterator_1.PathVariableObjectIterator(algebraFactory, subject, predicate, graph, context, this.mediatorQueryOperation, emitFirstSubject);
|
|
110
114
|
const bindingsStream = it.transform({
|
|
111
115
|
autoStart: false,
|
|
112
116
|
transform(item, next, push) {
|
|
@@ -129,6 +133,7 @@ class ActorAbstractPath extends bus_query_operation_1.ActorQueryOperationTypedMe
|
|
|
129
133
|
}
|
|
130
134
|
/**
|
|
131
135
|
* Pushes all terms to iterator `it` that are a solution of object predicate* ?o.
|
|
136
|
+
* @param algebraFactory The algebra factory.
|
|
132
137
|
* @param {Term} object Term of where we start the predicate* search.
|
|
133
138
|
* @param {Algebra.PropertyPathSymbol} predicate Predicate of the *-path.
|
|
134
139
|
* @param {Term} graph The graph in which we search for the pattern.
|
|
@@ -138,7 +143,7 @@ class ActorAbstractPath extends bus_query_operation_1.ActorQueryOperationTypedMe
|
|
|
138
143
|
* @param {any} counter Counts how many searches are in progress to close it when needed (when counter == 0).
|
|
139
144
|
* @return {Promise<IPathResultStream['metadata']>} The results metadata.
|
|
140
145
|
*/
|
|
141
|
-
async getObjectsPredicateStar(object, predicate, graph, context, termHashes, it, counter) {
|
|
146
|
+
async getObjectsPredicateStar(algebraFactory, object, predicate, graph, context, termHashes, it, counter) {
|
|
142
147
|
const termString = (0, rdf_string_1.termToString)(object);
|
|
143
148
|
if (termHashes[termString]) {
|
|
144
149
|
return;
|
|
@@ -146,14 +151,14 @@ class ActorAbstractPath extends bus_query_operation_1.ActorQueryOperationTypedMe
|
|
|
146
151
|
it._push(object);
|
|
147
152
|
termHashes[termString] = object;
|
|
148
153
|
counter.count++;
|
|
149
|
-
const thisVariable = this.generateVariable();
|
|
150
|
-
const path =
|
|
151
|
-
const results =
|
|
154
|
+
const thisVariable = this.generateVariable(algebraFactory.dataFactory);
|
|
155
|
+
const path = algebraFactory.createPath(object, predicate, thisVariable, graph);
|
|
156
|
+
const results = (0, utils_query_operation_1.getSafeBindings)(await this.mediatorQueryOperation.mediate({ operation: path, context }));
|
|
152
157
|
// TODO: fixme
|
|
153
158
|
// eslint-disable-next-line ts/no-misused-promises
|
|
154
159
|
results.bindingsStream.on('data', async (bindings) => {
|
|
155
160
|
const result = bindings.get(thisVariable);
|
|
156
|
-
await this.getObjectsPredicateStar(result, predicate, graph, context, termHashes, it, counter);
|
|
161
|
+
await this.getObjectsPredicateStar(algebraFactory, result, predicate, graph, context, termHashes, it, counter);
|
|
157
162
|
});
|
|
158
163
|
results.bindingsStream.on('end', () => {
|
|
159
164
|
if (--counter.count === 0) {
|
|
@@ -177,11 +182,13 @@ class ActorAbstractPath extends bus_query_operation_1.ActorQueryOperationTypedMe
|
|
|
177
182
|
* Remembers the pairs we've already searched for, can stop searching if so.
|
|
178
183
|
* @param {BufferedIterator<Bindings>} it Iterator to push terms to.
|
|
179
184
|
* @param {any} counter Counts how many searches are in progress to close it when needed (when counter == 0).
|
|
185
|
+
* @param algebraFactory The algebra factory.
|
|
186
|
+
* @param bindingsFactory The bindings factory.
|
|
180
187
|
* @return {Promise<void>} All solutions of query should have been pushed to it by then.
|
|
181
188
|
*/
|
|
182
189
|
// Let the iterator `it` emit all bindings of size 2, with subjectStringVariable as value subjectVal
|
|
183
190
|
// and objectStringVariable as value all nodes reachable through predicate* beginning at objectVal
|
|
184
|
-
async getSubjectAndObjectBindingsPredicateStar(subjectVar, objectVar, subjectVal, objectVal, predicate, graph, context, termHashesGlobal, termHashesCurrentSubject, it, counter, bindingsFactory) {
|
|
191
|
+
async getSubjectAndObjectBindingsPredicateStar(subjectVar, objectVar, subjectVal, objectVal, predicate, graph, context, termHashesGlobal, termHashesCurrentSubject, it, counter, algebraFactory, bindingsFactory) {
|
|
185
192
|
const termString = (0, rdf_string_1.termToString)(objectVal) + (0, rdf_string_1.termToString)(graph);
|
|
186
193
|
// If this combination of subject and object already done, return nothing
|
|
187
194
|
if (termHashesCurrentSubject[termString]) {
|
|
@@ -197,7 +204,7 @@ class ActorAbstractPath extends bus_query_operation_1.ActorQueryOperationTypedMe
|
|
|
197
204
|
if (termString in termHashesGlobal) {
|
|
198
205
|
const objects = await termHashesGlobal[termString];
|
|
199
206
|
for (const object of objects) {
|
|
200
|
-
await this.getSubjectAndObjectBindingsPredicateStar(subjectVar, objectVar, subjectVal, object, predicate, graph, context, termHashesGlobal, termHashesCurrentSubject, it, counter, bindingsFactory);
|
|
207
|
+
await this.getSubjectAndObjectBindingsPredicateStar(subjectVar, objectVar, subjectVal, object, predicate, graph, context, termHashesGlobal, termHashesCurrentSubject, it, counter, algebraFactory, bindingsFactory);
|
|
201
208
|
}
|
|
202
209
|
if (--counter.count === 0) {
|
|
203
210
|
it.close();
|
|
@@ -210,16 +217,16 @@ class ActorAbstractPath extends bus_query_operation_1.ActorQueryOperationTypedMe
|
|
|
210
217
|
const promise = new Promise(async (resolve, reject) => {
|
|
211
218
|
const objectsArray = [];
|
|
212
219
|
// Construct path that leads us one step through predicate
|
|
213
|
-
const thisVariable = this.generateVariable();
|
|
214
|
-
const path =
|
|
215
|
-
const results =
|
|
220
|
+
const thisVariable = this.generateVariable(algebraFactory.dataFactory);
|
|
221
|
+
const path = algebraFactory.createPath(objectVal, predicate, thisVariable, graph);
|
|
222
|
+
const results = (0, utils_query_operation_1.getSafeBindings)(await this.mediatorQueryOperation.mediate({ operation: path, context }));
|
|
216
223
|
// Recursive call on all neighbours
|
|
217
224
|
// TODO: fixme
|
|
218
225
|
// eslint-disable-next-line ts/no-misused-promises
|
|
219
226
|
results.bindingsStream.on('data', async (bindings) => {
|
|
220
227
|
const result = bindings.get(thisVariable);
|
|
221
228
|
objectsArray.push(result);
|
|
222
|
-
await this.getSubjectAndObjectBindingsPredicateStar(subjectVar, objectVar, subjectVal, result, predicate, graph, context, termHashesGlobal, termHashesCurrentSubject, it, counter, bindingsFactory);
|
|
229
|
+
await this.getSubjectAndObjectBindingsPredicateStar(subjectVar, objectVar, subjectVal, result, predicate, graph, context, termHashesGlobal, termHashesCurrentSubject, it, counter, algebraFactory, bindingsFactory);
|
|
223
230
|
});
|
|
224
231
|
results.bindingsStream.on('error', reject);
|
|
225
232
|
results.bindingsStream.on('end', () => {
|
|
@@ -249,7 +256,7 @@ class ActorAbstractPath extends bus_query_operation_1.ActorQueryOperationTypedMe
|
|
|
249
256
|
return this.getPathSources(operation.path);
|
|
250
257
|
case sparqlalgebrajs_1.Algebra.types.LINK:
|
|
251
258
|
case sparqlalgebrajs_1.Algebra.types.NPS: {
|
|
252
|
-
const source =
|
|
259
|
+
const source = (0, utils_query_operation_1.getOperationSource)(operation);
|
|
253
260
|
if (!source) {
|
|
254
261
|
throw new Error(`Could not find a required source on a link path operation`);
|
|
255
262
|
}
|
|
@@ -257,17 +264,16 @@ class ActorAbstractPath extends bus_query_operation_1.ActorQueryOperationTypedMe
|
|
|
257
264
|
}
|
|
258
265
|
}
|
|
259
266
|
}
|
|
260
|
-
assignPatternSources(pattern, sources) {
|
|
267
|
+
assignPatternSources(algebraFactory, pattern, sources) {
|
|
261
268
|
if (sources.length === 0) {
|
|
262
269
|
throw new Error(`Attempted to assign zero sources to a pattern during property path handling`);
|
|
263
270
|
}
|
|
264
271
|
if (sources.length === 1) {
|
|
265
|
-
return
|
|
272
|
+
return (0, utils_query_operation_1.assignOperationSource)(pattern, sources[0]);
|
|
266
273
|
}
|
|
267
|
-
return
|
|
268
|
-
.map(source =>
|
|
274
|
+
return algebraFactory.createUnion(sources
|
|
275
|
+
.map(source => (0, utils_query_operation_1.assignOperationSource)(pattern, source)), true);
|
|
269
276
|
}
|
|
270
277
|
}
|
|
271
278
|
exports.ActorAbstractPath = ActorAbstractPath;
|
|
272
|
-
ActorAbstractPath.FACTORY = new sparqlalgebrajs_1.Factory();
|
|
273
279
|
//# sourceMappingURL=ActorAbstractPath.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorAbstractPath.js","sourceRoot":"","sources":["ActorAbstractPath.ts"],"names":[],"mappings":";;;AAEA,uEAGuC;AACvC,+DAA+D;AAW/D,iDAKuB;AACvB,uDAA+C;AAC/C,2CAA0C;AAC1C,qDAAmD;AACnD,6EAA0E;AAE1E,MAAM,EAAE,GAAG,IAAI,8BAAW,EAAE,CAAC;AAE7B;;;;GAIG;AACH,MAAsB,iBAAkB,SAAQ,sDAA8C;IAK5F,YAAsB,IAA2C,EAAE,aAAqB;QACtF,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC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AAmB,CAAC,qBAAqB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACtF,CAAC;;AAhXH,8CAiXC;AAhX2B,yBAAO,GAAY,IAAI,yBAAO,EAAE,CAAC","sourcesContent":["import type { BindingsFactory } from '@comunica/bindings-factory';\nimport type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';\nimport {\n ActorQueryOperation,\n ActorQueryOperationTypedMediated,\n} from '@comunica/bus-query-operation';\nimport { KeysQueryOperation } from '@comunica/context-entries';\nimport type { IActorTest } from '@comunica/core';\nimport type {\n IQueryOperationResultBindings,\n Bindings,\n IActionContext,\n MetadataBindings,\n IQuerySourceWrapper,\n} from '@comunica/types';\nimport type * as RDF from '@rdfjs/types';\nimport type { AsyncIterator } from 'asynciterator';\nimport {\n BufferedIterator,\n MultiTransformIterator,\n TransformIterator,\n EmptyIterator,\n} from 'asynciterator';\nimport { DataFactory } from 'rdf-data-factory';\nimport { termToString } from 'rdf-string';\nimport { Algebra, Factory } from 'sparqlalgebrajs';\nimport { PathVariableObjectIterator } from './PathVariableObjectIterator';\n\nconst DF = new DataFactory();\n\n/**\n * An abstract actor that handles Path operations.\n *\n * Provides multiple helper functions used by the Path operation actors.\n */\nexport abstract class ActorAbstractPath extends ActorQueryOperationTypedMediated<Algebra.Path> {\n protected static readonly FACTORY: Factory = new Factory();\n\n protected readonly predicateType: string;\n\n protected constructor(args: IActorQueryOperationTypedMediatedArgs, predicateType: string) {\n super(args, 'path');\n this.predicateType = predicateType;\n }\n\n public async testOperation(operation: Algebra.Path, _context: IActionContext): Promise<IActorTest> {\n if (operation.predicate.type !== this.predicateType) {\n throw new Error(`This Actor only supports ${this.predicateType} Path operations.`);\n }\n\n return true;\n }\n\n // Generates a variable that does not yet occur in the path\n public generateVariable(path?: Algebra.Path, name?: string): RDF.Variable {\n if (!name) {\n return this.generateVariable(path, 'b');\n }\n\n // Path predicates can't contain variables\n if (path && (path.subject.value === name || path.object.value === name)) {\n return this.generateVariable(path, `${name}b`);\n }\n\n return DF.variable(name);\n }\n\n // Such connectivity matching does not introduce duplicates (it does not incorporate any count of the number\n // of ways the connection can be made) even if the repeated path itself would otherwise result in duplicates.\n // https://www.w3.org/TR/sparql11-query/#propertypaths\n public async isPathArbitraryLengthDistinct(context: IActionContext, path: Algebra.Path):\n Promise<{ context: IActionContext; operation: IQueryOperationResultBindings | undefined }> {\n if (!context.get(KeysQueryOperation.isPathArbitraryLengthDistinctKey)) {\n context = context.set(KeysQueryOperation.isPathArbitraryLengthDistinctKey, true);\n return { context, operation: ActorQueryOperation.getSafeBindings(await this.mediatorQueryOperation.mediate({\n operation: ActorAbstractPath.FACTORY.createDistinct(path),\n context,\n })) };\n }\n\n context = context.set(KeysQueryOperation.isPathArbitraryLengthDistinctKey, false);\n return { context, operation: undefined };\n }\n\n private async predicateStarGraphVariable(\n subject: RDF.Term,\n object: RDF.Variable,\n predicate: Algebra.PropertyPathSymbol,\n graph: RDF.Variable,\n context: IActionContext,\n bindingsFactory: BindingsFactory,\n ): Promise<IPathResultStream> {\n const sources = this.getPathSources(predicate);\n // TODO: refactor this with an iterator just like PathVariableObjectIterator so we handle backpressure correctly\n // Construct path to obtain all graphs where subject exists\n const predVar = this.generateVariable(ActorAbstractPath.FACTORY\n .createPath(subject, predicate, object, graph));\n const findGraphs = ActorAbstractPath.FACTORY.createUnion([\n this.assignPatternSources(ActorAbstractPath.FACTORY.createPattern(subject, predVar, object, graph), sources),\n this.assignPatternSources(ActorAbstractPath.FACTORY.createPattern(object, predVar, subject, graph), sources),\n ]);\n const results = ActorQueryOperation.getSafeBindings(\n await this.mediatorQueryOperation.mediate({ context, operation: findGraphs }),\n );\n\n const passedGraphs: Set<string> = new Set();\n\n const bindingsStream = new MultiTransformIterator<Bindings, Bindings>(\n results.bindingsStream,\n {\n multiTransform: (bindings: Bindings) => {\n // Extract the graph and start a predicate* search starting from subject in each graph\n const graphValue: RDF.Term = bindings.get(graph)!;\n if (passedGraphs.has(graphValue.value)) {\n return new EmptyIterator();\n }\n passedGraphs.add(graphValue.value);\n return new TransformIterator<Bindings>(\n async() => {\n const it = new BufferedIterator<RDF.Term>();\n await this.getObjectsPredicateStar(subject, predicate, graphValue, context, {}, it, { count: 0 });\n return it.transform<Bindings>({\n transform(item, next, push) {\n push(bindingsFactory.bindings([\n [ object, item ],\n [ graph, graphValue ],\n ]));\n next();\n },\n });\n },\n { maxBufferSize: 128 },\n );\n },\n autoStart: false,\n },\n );\n\n return {\n bindingsStream,\n metadata: results.metadata,\n };\n }\n\n /**\n * Returns an iterator with Bindings of the query subject predicate* ?o or subject predicate+ ?o\n * If graph is a variable, it will also be in those bindings\n * @param {Term} subject Term of where we start the predicate* search.\n * @param {Algebra.PropertyPathSymbol} predicate Predicate of the *-path.\n * @param {Variable} object Variable of the zeroOrMore-query.\n * @param {Term} graph The graph in which we search for the pattern. (Possibly a variable)\n * @param {ActionContext} context The context to pass to sub-opertations\n * @param emitFirstSubject If the path operation is predicate*, otherwise it is predicate+.\n * @return {Promise<AsyncIterator<Bindings>} Iterator to where all bindings of query should have been pushed.\n */\n public async getObjectsPredicateStarEval(\n subject: RDF.Term,\n predicate: Algebra.PropertyPathSymbol,\n object: RDF.Variable,\n graph: RDF.Term,\n context: IActionContext,\n emitFirstSubject: boolean,\n bindingsFactory: BindingsFactory,\n ): Promise<IPathResultStream> {\n if (graph.termType === 'Variable') {\n return this.predicateStarGraphVariable(subject, object, predicate, graph, context, bindingsFactory);\n }\n\n const it = new PathVariableObjectIterator(\n subject,\n predicate,\n graph,\n context,\n this.mediatorQueryOperation,\n emitFirstSubject,\n );\n\n const bindingsStream = it.transform<Bindings>({\n autoStart: false,\n transform(item, next, push) {\n push(bindingsFactory.bindings([[ object, item ]]));\n next();\n },\n });\n\n return {\n bindingsStream,\n async metadata() {\n const metadata: MetadataBindings = await new Promise((resolve) => {\n it.getProperty('metadata', (metadataInner: any) => resolve(metadataInner()));\n });\n // Increment cardinality by one, because we always have at least one result once we reach this stage.\n // See the transformation above where we push a single binding.\n metadata.cardinality.value++;\n return metadata;\n },\n };\n }\n\n /**\n * Pushes all terms to iterator `it` that are a solution of object predicate* ?o.\n * @param {Term} object Term of where we start the predicate* search.\n * @param {Algebra.PropertyPathSymbol} predicate Predicate of the *-path.\n * @param {Term} graph The graph in which we search for the pattern.\n * @param {ActionContext} context\n * @param {Record<string, Term>} termHashes Remembers the objects we've already searched for.\n * @param {BufferedIterator<Term>} it Iterator to push terms to.\n * @param {any} counter Counts how many searches are in progress to close it when needed (when counter == 0).\n * @return {Promise<IPathResultStream['metadata']>} The results metadata.\n */\n public async getObjectsPredicateStar(\n object: RDF.Term,\n predicate: Algebra.PropertyPathSymbol,\n graph: RDF.Term,\n context: IActionContext,\n termHashes: Record<string, RDF.Term>,\n it: BufferedIterator<RDF.Term>,\n counter: any,\n ): Promise<IPathResultStream['metadata'] | undefined> {\n const termString = termToString(object);\n if (termHashes[termString]) {\n return;\n }\n\n (<any> it)._push(object);\n termHashes[termString] = object;\n counter.count++;\n\n const thisVariable = this.generateVariable();\n const path = ActorAbstractPath.FACTORY.createPath(object, predicate, thisVariable, graph);\n const results = ActorQueryOperation.getSafeBindings(\n await this.mediatorQueryOperation.mediate({ operation: path, context }),\n );\n // TODO: fixme\n // eslint-disable-next-line ts/no-misused-promises\n results.bindingsStream.on('data', async(bindings: Bindings) => {\n const result = bindings.get(thisVariable);\n await this.getObjectsPredicateStar(result!, predicate, graph, context, termHashes, it, counter);\n });\n results.bindingsStream.on('end', () => {\n if (--counter.count === 0) {\n it.close();\n }\n });\n\n return results.metadata;\n }\n\n /**\n * Pushes all terms to iterator `it` that are a solution of ?s predicate* ?o.\n * @param {string} subjectVar String representation of subjectVariable\n * @param {string} objectVar String representation of objectVariable\n * @param {Term} subjectVal Term of where we start the predicate* search.\n * @param {Term} objectVal Found solution for an object, start for the new step.\n * @param {Algebra.PropertyPathSymbol} predicate Predicate of the *-path.\n * @param {Term} graph The graph in which we search for the pattern.\n * @param {ActionContext} context\n * @param {{[id: string]: Promise<Term[]>}} termHashesGlobal\n * Remembers solutions for when objectVal is already been calculated, can be reused when same objectVal occurs\n * @param {{[id: string]: Term}} termHashesCurrentSubject\n * Remembers the pairs we've already searched for, can stop searching if so.\n * @param {BufferedIterator<Bindings>} it Iterator to push terms to.\n * @param {any} counter Counts how many searches are in progress to close it when needed (when counter == 0).\n * @return {Promise<void>} All solutions of query should have been pushed to it by then.\n */\n // Let the iterator `it` emit all bindings of size 2, with subjectStringVariable as value subjectVal\n // and objectStringVariable as value all nodes reachable through predicate* beginning at objectVal\n public async getSubjectAndObjectBindingsPredicateStar(\n subjectVar: RDF.Variable,\n objectVar: RDF.Variable,\n subjectVal: RDF.Term,\n objectVal: RDF.Term,\n predicate: Algebra.PropertyPathSymbol,\n graph: RDF.Term,\n context: IActionContext,\n termHashesGlobal: Record<string, Promise<RDF.Term[]>>,\n termHashesCurrentSubject: Record<string, boolean>,\n it: BufferedIterator<Bindings>,\n counter: any,\n bindingsFactory: BindingsFactory,\n ): Promise<void> {\n const termString = termToString(objectVal) + termToString(graph);\n\n // If this combination of subject and object already done, return nothing\n if (termHashesCurrentSubject[termString]) {\n return;\n }\n\n counter.count++;\n termHashesCurrentSubject[termString] = true;\n (<any> it)._push(bindingsFactory.bindings([\n [ subjectVar, subjectVal ],\n [ objectVar, objectVal ],\n ]));\n\n // If every reachable node from object has already been calculated, use these for current subject too\n if (termString in termHashesGlobal) {\n const objects = await termHashesGlobal[termString];\n for (const object of objects) {\n await this.getSubjectAndObjectBindingsPredicateStar(\n subjectVar,\n objectVar,\n subjectVal,\n object,\n predicate,\n graph,\n context,\n termHashesGlobal,\n termHashesCurrentSubject,\n it,\n counter,\n bindingsFactory,\n );\n }\n if (--counter.count === 0) {\n it.close();\n }\n\n return;\n }\n\n // Construct promise to calculate all reachable nodes from this object\n // TODO: fixme\n // eslint-disable-next-line no-async-promise-executor,ts/no-misused-promises\n const promise = new Promise<RDF.Term[]>(async(resolve, reject) => {\n const objectsArray: RDF.Term[] = [];\n\n // Construct path that leads us one step through predicate\n const thisVariable = this.generateVariable();\n const path = ActorAbstractPath.FACTORY.createPath(objectVal, predicate, thisVariable, graph);\n const results = ActorQueryOperation.getSafeBindings(\n await this.mediatorQueryOperation.mediate({ operation: path, context }),\n );\n\n // Recursive call on all neighbours\n // TODO: fixme\n // eslint-disable-next-line ts/no-misused-promises\n results.bindingsStream.on('data', async(bindings: RDF.Bindings) => {\n const result: RDF.Term = bindings.get(thisVariable)!;\n objectsArray.push(result);\n await this.getSubjectAndObjectBindingsPredicateStar(\n subjectVar,\n objectVar,\n subjectVal,\n result,\n predicate,\n graph,\n context,\n termHashesGlobal,\n termHashesCurrentSubject,\n it,\n counter,\n bindingsFactory,\n );\n });\n results.bindingsStream.on('error', reject);\n results.bindingsStream.on('end', () => {\n if (--counter.count === 0) {\n it.close();\n }\n resolve(objectsArray);\n });\n });\n\n // Set it in the termHashesGlobal when this object occurs again they can wait for this promise\n termHashesGlobal[termString] = promise;\n }\n\n /**\n * Find all sources recursively contained in the given path operation.\n * @param operation\n */\n public getPathSources(operation: Algebra.PropertyPathSymbol): IQuerySourceWrapper[] {\n switch (operation.type) {\n case Algebra.types.ALT:\n case Algebra.types.SEQ:\n return operation.input\n .flatMap((subOp: Algebra.PropertyPathSymbol) => this.getPathSources(subOp));\n case Algebra.types.INV:\n case Algebra.types.ONE_OR_MORE_PATH:\n case Algebra.types.ZERO_OR_MORE_PATH:\n case Algebra.types.ZERO_OR_ONE_PATH:\n return this.getPathSources(operation.path);\n case Algebra.types.LINK:\n case Algebra.types.NPS: {\n const source = ActorQueryOperation.getOperationSource(operation);\n if (!source) {\n throw new Error(`Could not find a required source on a link path operation`);\n }\n return [ source ];\n }\n }\n }\n\n public assignPatternSources(pattern: Algebra.Pattern, sources: IQuerySourceWrapper[]): Algebra.Operation {\n if (sources.length === 0) {\n throw new Error(`Attempted to assign zero sources to a pattern during property path handling`);\n }\n if (sources.length === 1) {\n return ActorQueryOperation.assignOperationSource(pattern, sources[0]);\n }\n return ActorAbstractPath.FACTORY.createUnion(sources\n .map(source => ActorQueryOperation.assignOperationSource(pattern, source)), true);\n }\n}\n\nexport interface IPathResultStream {\n bindingsStream: AsyncIterator<Bindings>;\n metadata: () => Promise<MetadataBindings>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ActorAbstractPath.js","sourceRoot":"","sources":["ActorAbstractPath.ts"],"names":[],"mappings":";;;AACA,uEAEuC;AACvC,+DAA+D;AAE/D,yCAAwD;AAUxD,2EAA6G;AAG7G,iDAKuB;AACvB,2CAA0C;AAE1C,qDAA0C;AAC1C,6EAA0E;AAE1E;;;;GAIG;AACH,MAAsB,iBAAkB,SAAQ,sDAA8C;IAG5F,YAAsB,IAA2C,EAAE,aAAqB;QACtF,KAAK,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACpB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,SAAuB,EAAE,QAAwB;QAC1E,IAAI,SAAS,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC,aAAa,EAAE,CAAC;YACpD,OAAO,IAAA,eAAQ,EAAC,4BAA4B,IAAI,CAAC,aAAa,mBAAmB,CAAC,CAAC;QACrF,CAAC;QAED,OAAO,IAAA,mBAAY,GAAE,CAAC;IACxB,CAAC;IAED,2DAA2D;IACpD,gBAAgB,CAAC,WAAgC,EAAE,IAAmB,EAAE,IAAa;QAC1F,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,IAAI,CAAC,gBAAgB,CAAC,WAAW,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;QACvD,CAAC;QAED,0CAA0C;QAC1C,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC,EAAE,CAAC;YACxE,OAAO,IAAI,CAA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O,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;gBACvB,MAAM,MAAM,GAAG,IAAA,0CAAkB,EAAC,SAAS,CAAC,CAAC;gBAC7C,IAAI,CAAC,MAAM,EAAE,CAAC;oBACZ,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;gBAC/E,CAAC;gBACD,OAAO,CAAE,MAAM,CAAE,CAAC;YACpB,CAAC;QACH,CAAC;IACH,CAAC;IAEM,oBAAoB,CACzB,cAAuB,EACvB,OAAwB,EACxB,OAA8B;QAE9B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,6EAA6E,CAAC,CAAC;QACjG,CAAC;QACD,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO,IAAA,6CAAqB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,cAAc,CAAC,WAAW,CAAC,OAAO;aACtC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAA,6CAAqB,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAClE,CAAC;CACF;AAlYD,8CAkYC","sourcesContent":["import type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';\nimport {\n ActorQueryOperationTypedMediated,\n} from '@comunica/bus-query-operation';\nimport { KeysQueryOperation } from '@comunica/context-entries';\nimport type { IActorTest, TestResult } from '@comunica/core';\nimport { failTest, passTestVoid } from '@comunica/core';\nimport type {\n IQueryOperationResultBindings,\n Bindings,\n IActionContext,\n MetadataBindings,\n IQuerySourceWrapper,\n ComunicaDataFactory,\n} from '@comunica/types';\nimport type { BindingsFactory } from '@comunica/utils-bindings-factory';\nimport { assignOperationSource, getOperationSource, getSafeBindings } from '@comunica/utils-query-operation';\nimport type * as RDF from '@rdfjs/types';\nimport type { AsyncIterator } from 'asynciterator';\nimport {\n BufferedIterator,\n MultiTransformIterator,\n TransformIterator,\n EmptyIterator,\n} from 'asynciterator';\nimport { termToString } from 'rdf-string';\nimport type { Factory } from 'sparqlalgebrajs';\nimport { Algebra } from 'sparqlalgebrajs';\nimport { PathVariableObjectIterator } from './PathVariableObjectIterator';\n\n/**\n * An abstract actor that handles Path operations.\n *\n * Provides multiple helper functions used by the Path operation actors.\n */\nexport abstract class ActorAbstractPath extends ActorQueryOperationTypedMediated<Algebra.Path> {\n protected readonly predicateType: string;\n\n protected constructor(args: IActorQueryOperationTypedMediatedArgs, predicateType: string) {\n super(args, 'path');\n this.predicateType = predicateType;\n }\n\n public async testOperation(operation: Algebra.Path, _context: IActionContext): Promise<TestResult<IActorTest>> {\n if (operation.predicate.type !== this.predicateType) {\n return failTest(`This Actor only supports ${this.predicateType} Path operations.`);\n }\n\n return passTestVoid();\n }\n\n // Generates a variable that does not yet occur in the path\n public generateVariable(dataFactory: ComunicaDataFactory, path?: Algebra.Path, name?: string): RDF.Variable {\n if (!name) {\n return this.generateVariable(dataFactory, path, 'b');\n }\n\n // Path predicates can't contain variables\n if (path && (path.subject.value === name || path.object.value === name)) {\n return this.generateVariable(dataFactory, path, `${name}b`);\n }\n\n return dataFactory.variable(name);\n }\n\n // Such connectivity matching does not introduce duplicates (it does not incorporate any count of the number\n // of ways the connection can be made) even if the repeated path itself would otherwise result in duplicates.\n // https://www.w3.org/TR/sparql11-query/#propertypaths\n public async isPathArbitraryLengthDistinct(algebraFactory: Factory, context: IActionContext, path: Algebra.Path):\n Promise<{ context: IActionContext; operation: IQueryOperationResultBindings | undefined }> {\n if (!context.get(KeysQueryOperation.isPathArbitraryLengthDistinctKey)) {\n context = context.set(KeysQueryOperation.isPathArbitraryLengthDistinctKey, true);\n return { context, operation: getSafeBindings(await this.mediatorQueryOperation.mediate({\n operation: algebraFactory.createDistinct(path),\n context,\n })) };\n }\n\n context = context.set(KeysQueryOperation.isPathArbitraryLengthDistinctKey, false);\n return { context, operation: undefined };\n }\n\n private async predicateStarGraphVariable(\n subject: RDF.Term,\n object: RDF.Variable,\n predicate: Algebra.PropertyPathSymbol,\n graph: RDF.Variable,\n context: IActionContext,\n algebraFactory: Factory,\n bindingsFactory: BindingsFactory,\n ): Promise<IPathResultStream> {\n const sources = this.getPathSources(predicate);\n // TODO: refactor this with an iterator just like PathVariableObjectIterator so we handle backpressure correctly\n // Construct path to obtain all graphs where subject exists\n const predVar = this.generateVariable(<ComunicaDataFactory> algebraFactory.dataFactory, algebraFactory\n .createPath(subject, predicate, object, graph));\n const findGraphs = algebraFactory.createUnion([\n this.assignPatternSources(algebraFactory, algebraFactory.createPattern(subject, predVar, object, graph), sources),\n this.assignPatternSources(algebraFactory, algebraFactory.createPattern(object, predVar, subject, graph), sources),\n ]);\n const results = getSafeBindings(\n await this.mediatorQueryOperation.mediate({ context, operation: findGraphs }),\n );\n\n const passedGraphs: Set<string> = new Set();\n\n const bindingsStream = new MultiTransformIterator<Bindings, Bindings>(\n results.bindingsStream,\n {\n multiTransform: (bindings: Bindings) => {\n // Extract the graph and start a predicate* search starting from subject in each graph\n const graphValue: RDF.Term = bindings.get(graph)!;\n if (passedGraphs.has(graphValue.value)) {\n return new EmptyIterator();\n }\n passedGraphs.add(graphValue.value);\n return new TransformIterator<Bindings>(\n async() => {\n const it = new BufferedIterator<RDF.Term>();\n await this\n .getObjectsPredicateStar(algebraFactory, subject, predicate, graphValue, context, {}, it, { count: 0 });\n return it.transform<Bindings>({\n transform(item, next, push) {\n push(bindingsFactory.bindings([\n [ object, item ],\n [ graph, graphValue ],\n ]));\n next();\n },\n });\n },\n { maxBufferSize: 128 },\n );\n },\n autoStart: false,\n },\n );\n\n return {\n bindingsStream,\n metadata: results.metadata,\n };\n }\n\n /**\n * Returns an iterator with Bindings of the query subject predicate* ?o or subject predicate+ ?o\n * If graph is a variable, it will also be in those bindings\n * @param {Term} subject Term of where we start the predicate* search.\n * @param {Algebra.PropertyPathSymbol} predicate Predicate of the *-path.\n * @param {Variable} object Variable of the zeroOrMore-query.\n * @param {Term} graph The graph in which we search for the pattern. (Possibly a variable)\n * @param {ActionContext} context The context to pass to sub-opertations\n * @param emitFirstSubject If the path operation is predicate*, otherwise it is predicate+.\n * @param algebraFactory The algebra factory.\n * @param bindingsFactory The data factory.\n * @return {Promise<AsyncIterator<Bindings>} Iterator to where all bindings of query should have been pushed.\n */\n public async getObjectsPredicateStarEval(\n subject: RDF.Term,\n predicate: Algebra.PropertyPathSymbol,\n object: RDF.Variable,\n graph: RDF.Term,\n context: IActionContext,\n emitFirstSubject: boolean,\n algebraFactory: Factory,\n bindingsFactory: BindingsFactory,\n ): Promise<IPathResultStream> {\n if (graph.termType === 'Variable') {\n return this\n .predicateStarGraphVariable(subject, object, predicate, graph, context, algebraFactory, bindingsFactory);\n }\n\n const it = new PathVariableObjectIterator(\n algebraFactory,\n subject,\n predicate,\n graph,\n context,\n this.mediatorQueryOperation,\n emitFirstSubject,\n );\n\n const bindingsStream = it.transform<Bindings>({\n autoStart: false,\n transform(item, next, push) {\n push(bindingsFactory.bindings([[ object, item ]]));\n next();\n },\n });\n\n return {\n bindingsStream,\n async metadata() {\n const metadata: MetadataBindings = await new Promise((resolve) => {\n it.getProperty('metadata', (metadataInner: any) => resolve(metadataInner()));\n });\n // Increment cardinality by one, because we always have at least one result once we reach this stage.\n // See the transformation above where we push a single binding.\n metadata.cardinality.value++;\n return metadata;\n },\n };\n }\n\n /**\n * Pushes all terms to iterator `it` that are a solution of object predicate* ?o.\n * @param algebraFactory The algebra factory.\n * @param {Term} object Term of where we start the predicate* search.\n * @param {Algebra.PropertyPathSymbol} predicate Predicate of the *-path.\n * @param {Term} graph The graph in which we search for the pattern.\n * @param {ActionContext} context\n * @param {Record<string, Term>} termHashes Remembers the objects we've already searched for.\n * @param {BufferedIterator<Term>} it Iterator to push terms to.\n * @param {any} counter Counts how many searches are in progress to close it when needed (when counter == 0).\n * @return {Promise<IPathResultStream['metadata']>} The results metadata.\n */\n public async getObjectsPredicateStar(\n algebraFactory: Factory,\n object: RDF.Term,\n predicate: Algebra.PropertyPathSymbol,\n graph: RDF.Term,\n context: IActionContext,\n termHashes: Record<string, RDF.Term>,\n it: BufferedIterator<RDF.Term>,\n counter: any,\n ): Promise<IPathResultStream['metadata'] | undefined> {\n const termString = termToString(object);\n if (termHashes[termString]) {\n return;\n }\n\n (<any> it)._push(object);\n termHashes[termString] = object;\n counter.count++;\n\n const thisVariable = this.generateVariable(<ComunicaDataFactory> algebraFactory.dataFactory);\n const path = algebraFactory.createPath(object, predicate, thisVariable, graph);\n const results = getSafeBindings(\n await this.mediatorQueryOperation.mediate({ operation: path, context }),\n );\n\n // TODO: fixme\n // eslint-disable-next-line ts/no-misused-promises\n results.bindingsStream.on('data', async(bindings: Bindings) => {\n const result = bindings.get(thisVariable);\n await this.getObjectsPredicateStar(algebraFactory, result!, predicate, graph, context, termHashes, it, counter);\n });\n results.bindingsStream.on('end', () => {\n if (--counter.count === 0) {\n it.close();\n }\n });\n\n return results.metadata;\n }\n\n /**\n * Pushes all terms to iterator `it` that are a solution of ?s predicate* ?o.\n * @param {string} subjectVar String representation of subjectVariable\n * @param {string} objectVar String representation of objectVariable\n * @param {Term} subjectVal Term of where we start the predicate* search.\n * @param {Term} objectVal Found solution for an object, start for the new step.\n * @param {Algebra.PropertyPathSymbol} predicate Predicate of the *-path.\n * @param {Term} graph The graph in which we search for the pattern.\n * @param {ActionContext} context\n * @param {{[id: string]: Promise<Term[]>}} termHashesGlobal\n * Remembers solutions for when objectVal is already been calculated, can be reused when same objectVal occurs\n * @param {{[id: string]: Term}} termHashesCurrentSubject\n * Remembers the pairs we've already searched for, can stop searching if so.\n * @param {BufferedIterator<Bindings>} it Iterator to push terms to.\n * @param {any} counter Counts how many searches are in progress to close it when needed (when counter == 0).\n * @param algebraFactory The algebra factory.\n * @param bindingsFactory The bindings factory.\n * @return {Promise<void>} All solutions of query should have been pushed to it by then.\n */\n // Let the iterator `it` emit all bindings of size 2, with subjectStringVariable as value subjectVal\n // and objectStringVariable as value all nodes reachable through predicate* beginning at objectVal\n public async getSubjectAndObjectBindingsPredicateStar(\n subjectVar: RDF.Variable,\n objectVar: RDF.Variable,\n subjectVal: RDF.Term,\n objectVal: RDF.Term,\n predicate: Algebra.PropertyPathSymbol,\n graph: RDF.Term,\n context: IActionContext,\n termHashesGlobal: Record<string, Promise<RDF.Term[]>>,\n termHashesCurrentSubject: Record<string, boolean>,\n it: BufferedIterator<Bindings>,\n counter: any,\n algebraFactory: Factory,\n bindingsFactory: BindingsFactory,\n ): Promise<void> {\n const termString = termToString(objectVal) + termToString(graph);\n\n // If this combination of subject and object already done, return nothing\n if (termHashesCurrentSubject[termString]) {\n return;\n }\n\n counter.count++;\n termHashesCurrentSubject[termString] = true;\n (<any> it)._push(bindingsFactory.bindings([\n [ subjectVar, subjectVal ],\n [ objectVar, objectVal ],\n ]));\n\n // If every reachable node from object has already been calculated, use these for current subject too\n if (termString in termHashesGlobal) {\n const objects = await termHashesGlobal[termString];\n for (const object of objects) {\n await this.getSubjectAndObjectBindingsPredicateStar(\n subjectVar,\n objectVar,\n subjectVal,\n object,\n predicate,\n graph,\n context,\n termHashesGlobal,\n termHashesCurrentSubject,\n it,\n counter,\n algebraFactory,\n bindingsFactory,\n );\n }\n if (--counter.count === 0) {\n it.close();\n }\n\n return;\n }\n\n // Construct promise to calculate all reachable nodes from this object\n // TODO: fixme\n // eslint-disable-next-line no-async-promise-executor,ts/no-misused-promises\n const promise = new Promise<RDF.Term[]>(async(resolve, reject) => {\n const objectsArray: RDF.Term[] = [];\n\n // Construct path that leads us one step through predicate\n const thisVariable = this.generateVariable(<ComunicaDataFactory> algebraFactory.dataFactory);\n const path = algebraFactory.createPath(objectVal, predicate, thisVariable, graph);\n const results = getSafeBindings(\n await this.mediatorQueryOperation.mediate({ operation: path, context }),\n );\n\n // Recursive call on all neighbours\n // TODO: fixme\n // eslint-disable-next-line ts/no-misused-promises\n results.bindingsStream.on('data', async(bindings: RDF.Bindings) => {\n const result: RDF.Term = bindings.get(thisVariable)!;\n objectsArray.push(result);\n await this.getSubjectAndObjectBindingsPredicateStar(\n subjectVar,\n objectVar,\n subjectVal,\n result,\n predicate,\n graph,\n context,\n termHashesGlobal,\n termHashesCurrentSubject,\n it,\n counter,\n algebraFactory,\n bindingsFactory,\n );\n });\n results.bindingsStream.on('error', reject);\n results.bindingsStream.on('end', () => {\n if (--counter.count === 0) {\n it.close();\n }\n resolve(objectsArray);\n });\n });\n\n // Set it in the termHashesGlobal when this object occurs again they can wait for this promise\n termHashesGlobal[termString] = promise;\n }\n\n /**\n * Find all sources recursively contained in the given path operation.\n * @param operation\n */\n public getPathSources(operation: Algebra.PropertyPathSymbol): IQuerySourceWrapper[] {\n switch (operation.type) {\n case Algebra.types.ALT:\n case Algebra.types.SEQ:\n return operation.input\n .flatMap((subOp: Algebra.PropertyPathSymbol) => this.getPathSources(subOp));\n case Algebra.types.INV:\n case Algebra.types.ONE_OR_MORE_PATH:\n case Algebra.types.ZERO_OR_MORE_PATH:\n case Algebra.types.ZERO_OR_ONE_PATH:\n return this.getPathSources(operation.path);\n case Algebra.types.LINK:\n case Algebra.types.NPS: {\n const source = getOperationSource(operation);\n if (!source) {\n throw new Error(`Could not find a required source on a link path operation`);\n }\n return [ source ];\n }\n }\n }\n\n public assignPatternSources(\n algebraFactory: Factory,\n pattern: Algebra.Pattern,\n sources: IQuerySourceWrapper[],\n ): Algebra.Operation {\n if (sources.length === 0) {\n throw new Error(`Attempted to assign zero sources to a pattern during property path handling`);\n }\n if (sources.length === 1) {\n return assignOperationSource(pattern, sources[0]);\n }\n return algebraFactory.createUnion(sources\n .map(source => assignOperationSource(pattern, source)), true);\n }\n}\n\nexport interface IPathResultStream {\n bindingsStream: AsyncIterator<Bindings>;\n metadata: () => Promise<MetadataBindings>;\n}\n"]}
|
|
@@ -2,12 +2,13 @@ import type { MediatorQueryOperation } from '@comunica/bus-query-operation';
|
|
|
2
2
|
import type { IActionContext } from '@comunica/types';
|
|
3
3
|
import type * as RDF from '@rdfjs/types';
|
|
4
4
|
import { BufferedIterator } from 'asynciterator';
|
|
5
|
-
import type { Algebra } from 'sparqlalgebrajs';
|
|
5
|
+
import type { Algebra, Factory } from 'sparqlalgebrajs';
|
|
6
6
|
/**
|
|
7
7
|
* An iterator that implements the multi-length property path operation (* and +)
|
|
8
8
|
* for a fixed subject and predicate, and a variable object.
|
|
9
9
|
*/
|
|
10
10
|
export declare class PathVariableObjectIterator extends BufferedIterator<RDF.Term> {
|
|
11
|
+
private readonly algebraFactory;
|
|
11
12
|
private readonly subject;
|
|
12
13
|
private readonly predicate;
|
|
13
14
|
private readonly graph;
|
|
@@ -17,7 +18,7 @@ export declare class PathVariableObjectIterator extends BufferedIterator<RDF.Ter
|
|
|
17
18
|
private readonly termHashes;
|
|
18
19
|
private readonly runningOperations;
|
|
19
20
|
private readonly pendingOperations;
|
|
20
|
-
constructor(subject: RDF.Term, predicate: Algebra.PropertyPathSymbol, graph: RDF.Term, context: IActionContext, mediatorQueryOperation: MediatorQueryOperation, emitFirstSubject: boolean, maxRunningOperations?: number);
|
|
21
|
+
constructor(algebraFactory: Factory, subject: RDF.Term, predicate: Algebra.PropertyPathSymbol, graph: RDF.Term, context: IActionContext, mediatorQueryOperation: MediatorQueryOperation, emitFirstSubject: boolean, maxRunningOperations?: number);
|
|
21
22
|
protected _end(destroy?: boolean): void;
|
|
22
23
|
protected _push(item: RDF.Term, pushAsResult?: boolean): void;
|
|
23
24
|
protected _read(count: number, done: () => void): void;
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PathVariableObjectIterator = void 0;
|
|
4
|
-
const
|
|
4
|
+
const utils_query_operation_1 = require("@comunica/utils-query-operation");
|
|
5
5
|
const asynciterator_1 = require("asynciterator");
|
|
6
|
-
const rdf_data_factory_1 = require("rdf-data-factory");
|
|
7
6
|
const rdf_string_1 = require("rdf-string");
|
|
8
|
-
const sparqlalgebrajs_1 = require("sparqlalgebrajs");
|
|
9
|
-
const DF = new rdf_data_factory_1.DataFactory();
|
|
10
|
-
const FACTORY = new sparqlalgebrajs_1.Factory();
|
|
11
7
|
/**
|
|
12
8
|
* An iterator that implements the multi-length property path operation (* and +)
|
|
13
9
|
* for a fixed subject and predicate, and a variable object.
|
|
14
10
|
*/
|
|
15
11
|
class PathVariableObjectIterator extends asynciterator_1.BufferedIterator {
|
|
16
|
-
constructor(subject, predicate, graph, context, mediatorQueryOperation, emitFirstSubject, maxRunningOperations = 16) {
|
|
12
|
+
constructor(algebraFactory, subject, predicate, graph, context, mediatorQueryOperation, emitFirstSubject, maxRunningOperations = 16) {
|
|
17
13
|
// The autoStart flag must be true to kickstart metadata collection
|
|
18
14
|
super({ autoStart: true });
|
|
15
|
+
this.algebraFactory = algebraFactory;
|
|
19
16
|
this.subject = subject;
|
|
20
17
|
this.predicate = predicate;
|
|
21
18
|
this.graph = graph;
|
|
@@ -45,10 +42,10 @@ class PathVariableObjectIterator extends asynciterator_1.BufferedIterator {
|
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
44
|
// Add a pending path operation for this item
|
|
48
|
-
const variable =
|
|
45
|
+
const variable = this.algebraFactory.dataFactory.variable('b');
|
|
49
46
|
this.pendingOperations.push({
|
|
50
47
|
variable,
|
|
51
|
-
operation:
|
|
48
|
+
operation: this.algebraFactory.createPath(item, this.predicate, variable, this.graph),
|
|
52
49
|
});
|
|
53
50
|
// Otherwise, push the subject
|
|
54
51
|
if (termString) {
|
|
@@ -66,7 +63,7 @@ class PathVariableObjectIterator extends asynciterator_1.BufferedIterator {
|
|
|
66
63
|
break;
|
|
67
64
|
}
|
|
68
65
|
const pendingOperation = self.pendingOperations.pop();
|
|
69
|
-
const results =
|
|
66
|
+
const results = (0, utils_query_operation_1.getSafeBindings)(await self.mediatorQueryOperation.mediate({ operation: pendingOperation.operation, context: self.context }));
|
|
70
67
|
const runningOperation = results.bindingsStream.transform({
|
|
71
68
|
autoStart: false,
|
|
72
69
|
transform(bindings, next, push) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PathVariableObjectIterator.js","sourceRoot":"","sources":["PathVariableObjectIterator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"PathVariableObjectIterator.js","sourceRoot":"","sources":["PathVariableObjectIterator.ts"],"names":[],"mappings":";;;AAEA,2EAAkE;AAGlE,iDAAiD;AACjD,2CAA0C;AAG1C;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,gCAA0B;IAKxE,YACmB,cAAuB,EACvB,OAAiB,EACjB,SAAqC,EACrC,KAAe,EACf,OAAuB,EACvB,sBAA8C,EAC/D,gBAAyB,EACR,uBAAuB,EAAE;QAE1C,mEAAmE;QACnE,KAAK,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAVV,mBAAc,GAAd,cAAc,CAAS;QACvB,YAAO,GAAP,OAAO,CAAU;QACjB,cAAS,GAAT,SAAS,CAA4B;QACrC,UAAK,GAAL,KAAK,CAAU;QACf,YAAO,GAAP,OAAO,CAAgB;QACvB,2BAAsB,GAAtB,sBAAsB,CAAwB;QAE9C,yBAAoB,GAApB,oBAAoB,CAAK;QAZ3B,eAAU,GAA0B,IAAI,GAAG,EAAE,CAAC;QAC9C,sBAAiB,GAA8B,EAAE,CAAC;QAClD,sBAAiB,GAA0D,EAAE,CAAC;QAe7F,qCAAqC;QACrC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAC7C,CAAC;IAEkB,IAAI,CAAC,OAAiB;QACvC,8BAA8B;QAC9B,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACxC,EAAE,CAAC,OAAO,EAAE,CAAC;QACf,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACtB,CAAC;IAEkB,KAAK,CAAC,IAAc,EAA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AC,CAAC;YAClB,IAAI,IAAqB,CAAC;YAC1B,0CAA0C;YAC1C,OAAO,SAAS,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,EAAE,CAAC;gBACzC,uDAAuD;gBACvD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,iBAAiB,CAAC,MAAM,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;oBACpE,0CAA0C;oBAC1C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC;wBACvD,KAAK,EAAE,CAAC;wBACR,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBACnB,CAAC;gBACH,CAAC;YACH,CAAC;YAED,oCAAoC;YACpC,IAAI,IAAI,CAAC,iBAAiB,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC/E,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,CAAC;QACH,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;YACb,IAAI,EAAE,CAAC;QACT,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;IACnC,CAAC;CACF;AArHD,gEAqHC","sourcesContent":["import type { MediatorQueryOperation } from '@comunica/bus-query-operation';\nimport type { IActionContext } from '@comunica/types';\nimport { getSafeBindings } from '@comunica/utils-query-operation';\nimport type * as RDF from '@rdfjs/types';\nimport type { AsyncIterator } from 'asynciterator';\nimport { BufferedIterator } from 'asynciterator';\nimport { termToString } from 'rdf-string';\nimport type { Algebra, Factory } from 'sparqlalgebrajs';\n\n/**\n * An iterator that implements the multi-length property path operation (* and +)\n * for a fixed subject and predicate, and a variable object.\n */\nexport class PathVariableObjectIterator extends BufferedIterator<RDF.Term> {\n private readonly termHashes: Map<string, RDF.Term> = new Map();\n private readonly runningOperations: AsyncIterator<RDF.Term>[] = [];\n private readonly pendingOperations: { variable: RDF.Variable; operation: Algebra.Path }[] = [];\n\n public constructor(\n private readonly algebraFactory: Factory,\n private readonly subject: RDF.Term,\n private readonly predicate: Algebra.PropertyPathSymbol,\n private readonly graph: RDF.Term,\n private readonly context: IActionContext,\n private readonly mediatorQueryOperation: MediatorQueryOperation,\n emitFirstSubject: boolean,\n private readonly maxRunningOperations = 16,\n ) {\n // The autoStart flag must be true to kickstart metadata collection\n super({ autoStart: true });\n\n // Push the subject as starting point\n this._push(this.subject, emitFirstSubject);\n }\n\n protected override _end(destroy?: boolean): void {\n // Close all running iterators\n for (const it of this.runningOperations) {\n it.destroy();\n }\n\n super._end(destroy);\n }\n\n protected override _push(item: RDF.Term, pushAsResult = true): void {\n let termString;\n if (pushAsResult) {\n // Don't push if this subject was already found\n termString = termToString(item);\n if (this.termHashes.has(termString)) {\n return;\n }\n }\n\n // Add a pending path operation for this item\n const variable = this.algebraFactory.dataFactory.variable!('b');\n this.pendingOperations.push({\n variable,\n operation: this.algebraFactory.createPath(item, this.predicate, variable, this.graph),\n });\n\n // Otherwise, push the subject\n if (termString) {\n this.termHashes.set(termString, item);\n super._push(item);\n }\n }\n\n protected override _read(count: number, done: () => void): void {\n // eslint-disable-next-line ts/no-this-alias\n const self = this;\n (async function() {\n // Open as many operations as possible\n while (self.runningOperations.length < self.maxRunningOperations) {\n if (self.pendingOperations.length === 0) {\n break;\n }\n\n const pendingOperation = self.pendingOperations.pop()!;\n const results = getSafeBindings(\n await self.mediatorQueryOperation.mediate({ operation: pendingOperation.operation, context: self.context }),\n );\n const runningOperation = results.bindingsStream.transform<RDF.Term>({\n autoStart: false,\n transform(bindings, next, push) {\n const newTerm: RDF.Term = <RDF.Term> bindings.get(pendingOperation.variable);\n push(newTerm);\n next();\n },\n });\n if (!runningOperation.done) {\n self.runningOperations.push(runningOperation);\n runningOperation.on('error', error => self.destroy(error));\n runningOperation.on('readable', () => {\n self.readable = true;\n self._fillBufferAsync();\n });\n runningOperation.on('end', () => {\n self.runningOperations.splice(self.runningOperations.indexOf(runningOperation), 1);\n self.readable = true;\n self._fillBufferAsync();\n });\n }\n\n self.setProperty('metadata', results.metadata);\n }\n\n // Try to read `count` items (based on UnionIterator)\n let lastCount = 0;\n let item: RDF.Term | null;\n // eslint-disable-next-line no-cond-assign\n while (lastCount !== (lastCount = count)) {\n // Prioritize the operations that have been added first\n for (let i = 0; i < self.runningOperations.length && count > 0; i++) {\n // eslint-disable-next-line no-cond-assign\n if ((item = self.runningOperations[i].read()) !== null) {\n count--;\n self._push(item);\n }\n }\n }\n\n // Close if everything has been read\n if (self.runningOperations.length === 0 && self.pendingOperations.length === 0) {\n self.close();\n }\n })().then(() => {\n done();\n }, error => this.destroy(error));\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-abstract-path",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "An abstract actor for handling mediatypes",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"funding": {
|
|
8
|
+
"type": "opencollective",
|
|
9
|
+
"url": "https://opencollective.com/comunica-association"
|
|
10
|
+
},
|
|
7
11
|
"homepage": "https://comunica.dev/",
|
|
8
12
|
"repository": {
|
|
9
13
|
"type": "git",
|
|
@@ -37,16 +41,16 @@
|
|
|
37
41
|
"build:components": "componentsjs-generator"
|
|
38
42
|
},
|
|
39
43
|
"dependencies": {
|
|
40
|
-
"@comunica/
|
|
41
|
-
"@comunica/
|
|
42
|
-
"@comunica/
|
|
43
|
-
"@comunica/
|
|
44
|
-
"@comunica/
|
|
44
|
+
"@comunica/bus-query-operation": "^4.0.1",
|
|
45
|
+
"@comunica/context-entries": "^4.0.1",
|
|
46
|
+
"@comunica/core": "^4.0.1",
|
|
47
|
+
"@comunica/types": "^4.0.1",
|
|
48
|
+
"@comunica/utils-bindings-factory": "^4.0.1",
|
|
49
|
+
"@comunica/utils-query-operation": "^4.0.1",
|
|
45
50
|
"@rdfjs/types": "*",
|
|
46
51
|
"asynciterator": "^3.9.0",
|
|
47
|
-
"rdf-data-factory": "^1.1.1",
|
|
48
52
|
"rdf-string": "^1.6.1",
|
|
49
|
-
"sparqlalgebrajs": "^4.3.
|
|
53
|
+
"sparqlalgebrajs": "^4.3.8"
|
|
50
54
|
},
|
|
51
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "67831ba79e45ea1ced41fe3f83c5d6e8802dbeaa"
|
|
52
56
|
}
|