@comunica/actor-optimize-query-operation-query-source-identify 4.4.2-alpha.49.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld +38 -17
- package/components/components.jsonld +1 -1
- package/components/context.jsonld +7 -1
- package/lib/ActorOptimizeQueryOperationQuerySourceIdentify.d.ts +7 -1
- package/lib/ActorOptimizeQueryOperationQuerySourceIdentify.js +38 -2
- package/lib/ActorOptimizeQueryOperationQuerySourceIdentify.js.map +1 -1
- package/package.json +12 -10
package/README.md
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
An [Optimize Query Operation](https://github.com/comunica/comunica/tree/master/packages/bus-optimize-query-operation) actor
|
|
6
6
|
that identifies all query sources in the context using
|
|
7
7
|
the [Query Source Identify bus](https://github.com/comunica/comunica/tree/master/packages/bus-query-source-identify).
|
|
8
|
+
It will store all query sources in the context using `KeysQueryOperation.querySources`,
|
|
9
|
+
and sources corresponding to the SERVICE clauses within the query will be stored
|
|
10
|
+
using `KeysQueryOperation.serviceSources`.
|
|
8
11
|
|
|
9
12
|
This actor also contains a cache so that identical sources will be reused across multiple query executions.
|
|
10
13
|
This cache can be invalidated via `engine.invalidateHttpCache()`.
|
|
@@ -43,6 +46,7 @@ After installing, this package can be added to your engine's configuration as fo
|
|
|
43
46
|
|
|
44
47
|
### Config Parameters
|
|
45
48
|
|
|
49
|
+
* `serviceForceSparqlEndpoint`: Optional flag indicating if the SERVICE target should be assumed to be a SPARQL endpoint, defaults to `false`.
|
|
46
50
|
* `cacheSize`: The maximum number of entries in the LRU cache, set to 0 to disable, defaults to 100.
|
|
47
51
|
* `httpInvalidator`: An optional actor that listens to HTTP invalidation events.
|
|
48
52
|
* `mediatorQuerySourceIdentify`: A mediator over the [Query Source Identify bus](https://github.com/comunica/comunica/tree/master/packages/bus-query-source-identify).
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-query-source-identify/^
|
|
4
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-http-invalidate/^
|
|
5
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^
|
|
6
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-optimize-query-operation/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-query-source-identify/^5.0.0/components/context.jsonld",
|
|
4
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-http-invalidate/^5.0.0/components/context.jsonld",
|
|
5
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/core/^5.0.0/components/context.jsonld",
|
|
6
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/bus-optimize-query-operation/^5.0.0/components/context.jsonld"
|
|
7
7
|
],
|
|
8
8
|
"@id": "npmd:@comunica/actor-optimize-query-operation-query-source-identify",
|
|
9
9
|
"components": [
|
|
@@ -16,6 +16,12 @@
|
|
|
16
16
|
],
|
|
17
17
|
"comment": "A comunica Query Source Identify Optimize Query Operation Actor.",
|
|
18
18
|
"parameters": [
|
|
19
|
+
{
|
|
20
|
+
"@id": "caoqoqsi:components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld#ActorOptimizeQueryOperationQuerySourceIdentify_args_serviceForceSparqlEndpoint",
|
|
21
|
+
"range": "xsd:boolean",
|
|
22
|
+
"default": "false",
|
|
23
|
+
"comment": "If the SERVICE target should be assumed to be a SPARQL endpoint."
|
|
24
|
+
},
|
|
19
25
|
{
|
|
20
26
|
"@id": "caoqoqsi:components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld#ActorOptimizeQueryOperationQuerySourceIdentify_args_cacheSize",
|
|
21
27
|
"range": "xsd:integer",
|
|
@@ -27,7 +33,7 @@
|
|
|
27
33
|
"range": "cbhi:components/ActorHttpInvalidateListenable.jsonld#ActorHttpInvalidateListenable",
|
|
28
34
|
"default": {
|
|
29
35
|
"@id": "caoqoqsi:components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld#IActorOptimizeQueryOperationQuerySourceIdentifyArgs_default_invalidator",
|
|
30
|
-
"@type": "npmd:@comunica/bus-http-invalidate/^
|
|
36
|
+
"@type": "npmd:@comunica/bus-http-invalidate/^5.0.0/components/ActorHttpInvalidateListenable.jsonld#ActorHttpInvalidateListenable"
|
|
31
37
|
},
|
|
32
38
|
"comment": "An actor that listens to HTTP invalidation events"
|
|
33
39
|
},
|
|
@@ -61,37 +67,37 @@
|
|
|
61
67
|
"genericTypeInstances": [
|
|
62
68
|
{
|
|
63
69
|
"@type": "ParameterRangeGenericTypeReference",
|
|
64
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
70
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
65
71
|
},
|
|
66
72
|
{
|
|
67
73
|
"@type": "ParameterRangeGenericTypeReference",
|
|
68
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
74
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
69
75
|
},
|
|
70
76
|
{
|
|
71
77
|
"@type": "ParameterRangeGenericTypeReference",
|
|
72
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
78
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
73
79
|
},
|
|
74
80
|
{
|
|
75
81
|
"@type": "ParameterRangeGenericTypeReference",
|
|
76
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
82
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
77
83
|
}
|
|
78
84
|
]
|
|
79
85
|
},
|
|
80
86
|
{
|
|
81
87
|
"@type": "ParameterRangeGenericTypeReference",
|
|
82
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
88
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
83
89
|
},
|
|
84
90
|
{
|
|
85
91
|
"@type": "ParameterRangeGenericTypeReference",
|
|
86
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
92
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
87
93
|
},
|
|
88
94
|
{
|
|
89
95
|
"@type": "ParameterRangeGenericTypeReference",
|
|
90
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
96
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
91
97
|
},
|
|
92
98
|
{
|
|
93
99
|
"@type": "ParameterRangeGenericTypeReference",
|
|
94
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
100
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
95
101
|
}
|
|
96
102
|
]
|
|
97
103
|
},
|
|
@@ -128,19 +134,19 @@
|
|
|
128
134
|
"genericTypeInstances": [
|
|
129
135
|
{
|
|
130
136
|
"@type": "ParameterRangeGenericTypeReference",
|
|
131
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
137
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_I"
|
|
132
138
|
},
|
|
133
139
|
{
|
|
134
140
|
"@type": "ParameterRangeGenericTypeReference",
|
|
135
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
141
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_T"
|
|
136
142
|
},
|
|
137
143
|
{
|
|
138
144
|
"@type": "ParameterRangeGenericTypeReference",
|
|
139
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
145
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_O"
|
|
140
146
|
},
|
|
141
147
|
{
|
|
142
148
|
"@type": "ParameterRangeGenericTypeReference",
|
|
143
|
-
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^
|
|
149
|
+
"parameterRangeGenericType": "npmd:@comunica/actor-abstract-mediatyped/^5.0.0/components/ActorAbstractMediaTyped.jsonld#ActorAbstractMediaTyped__generic_TS"
|
|
144
150
|
}
|
|
145
151
|
]
|
|
146
152
|
}
|
|
@@ -154,6 +160,11 @@
|
|
|
154
160
|
}
|
|
155
161
|
],
|
|
156
162
|
"memberFields": [
|
|
163
|
+
{
|
|
164
|
+
"@id": "caoqoqsi:components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld#ActorOptimizeQueryOperationQuerySourceIdentify__member_serviceForceSparqlEndpoint",
|
|
165
|
+
"memberFieldName": "serviceForceSparqlEndpoint",
|
|
166
|
+
"range": "xsd:boolean"
|
|
167
|
+
},
|
|
157
168
|
{
|
|
158
169
|
"@id": "caoqoqsi:components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld#ActorOptimizeQueryOperationQuerySourceIdentify__member_cacheSize",
|
|
159
170
|
"memberFieldName": "cacheSize",
|
|
@@ -206,6 +217,12 @@
|
|
|
206
217
|
{
|
|
207
218
|
"@id": "caoqoqsi:components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld#ActorOptimizeQueryOperationQuerySourceIdentify_args__constructorArgument",
|
|
208
219
|
"fields": [
|
|
220
|
+
{
|
|
221
|
+
"keyRaw": "serviceForceSparqlEndpoint",
|
|
222
|
+
"value": {
|
|
223
|
+
"@id": "caoqoqsi:components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld#ActorOptimizeQueryOperationQuerySourceIdentify_args_serviceForceSparqlEndpoint"
|
|
224
|
+
}
|
|
225
|
+
},
|
|
209
226
|
{
|
|
210
227
|
"keyRaw": "cacheSize",
|
|
211
228
|
"value": {
|
|
@@ -264,6 +281,10 @@
|
|
|
264
281
|
"requireElement": "IActorOptimizeQueryOperationQuerySourceIdentifyArgs",
|
|
265
282
|
"parameters": [],
|
|
266
283
|
"memberFields": [
|
|
284
|
+
{
|
|
285
|
+
"@id": "caoqoqsi:components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld#IActorOptimizeQueryOperationQuerySourceIdentifyArgs__member_serviceForceSparqlEndpoint",
|
|
286
|
+
"memberFieldName": "serviceForceSparqlEndpoint"
|
|
287
|
+
},
|
|
267
288
|
{
|
|
268
289
|
"@id": "caoqoqsi:components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld#IActorOptimizeQueryOperationQuerySourceIdentifyArgs__member_cacheSize",
|
|
269
290
|
"memberFieldName": "cacheSize"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"@context": [
|
|
3
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-query-source-identify/^
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-optimize-query-operation-query-source-identify/^5.0.0/components/context.jsonld"
|
|
4
4
|
],
|
|
5
5
|
"@id": "npmd:@comunica/actor-optimize-query-operation-query-source-identify",
|
|
6
6
|
"@type": "Module",
|
|
@@ -3,11 +3,14 @@
|
|
|
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
|
-
"caoqoqsi": "npmd:@comunica/actor-optimize-query-operation-query-source-identify/^
|
|
6
|
+
"caoqoqsi": "npmd:@comunica/actor-optimize-query-operation-query-source-identify/^5.0.0/",
|
|
7
7
|
"ActorOptimizeQueryOperationQuerySourceIdentify": {
|
|
8
8
|
"@id": "caoqoqsi:components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld#ActorOptimizeQueryOperationQuerySourceIdentify",
|
|
9
9
|
"@prefix": true,
|
|
10
10
|
"@context": {
|
|
11
|
+
"args_serviceForceSparqlEndpoint": {
|
|
12
|
+
"@id": "caoqoqsi:components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld#ActorOptimizeQueryOperationQuerySourceIdentify_args_serviceForceSparqlEndpoint"
|
|
13
|
+
},
|
|
11
14
|
"args_cacheSize": {
|
|
12
15
|
"@id": "caoqoqsi:components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld#ActorOptimizeQueryOperationQuerySourceIdentify_args_cacheSize"
|
|
13
16
|
},
|
|
@@ -33,6 +36,9 @@
|
|
|
33
36
|
"@id": "caoqoqsi:components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld#ActorOptimizeQueryOperationQuerySourceIdentify_args_beforeActors",
|
|
34
37
|
"@container": "@list"
|
|
35
38
|
},
|
|
39
|
+
"serviceForceSparqlEndpoint": {
|
|
40
|
+
"@id": "caoqoqsi:components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld#ActorOptimizeQueryOperationQuerySourceIdentify_args_serviceForceSparqlEndpoint"
|
|
41
|
+
},
|
|
36
42
|
"cacheSize": {
|
|
37
43
|
"@id": "caoqoqsi:components/ActorOptimizeQueryOperationQuerySourceIdentify.jsonld#ActorOptimizeQueryOperationQuerySourceIdentify_args_cacheSize"
|
|
38
44
|
},
|
|
@@ -10,6 +10,7 @@ import { LRUCache } from 'lru-cache';
|
|
|
10
10
|
* A comunica Query Source Identify Optimize Query Operation Actor.
|
|
11
11
|
*/
|
|
12
12
|
export declare class ActorOptimizeQueryOperationQuerySourceIdentify extends ActorOptimizeQueryOperation {
|
|
13
|
+
readonly serviceForceSparqlEndpoint: boolean;
|
|
13
14
|
readonly cacheSize: number;
|
|
14
15
|
readonly httpInvalidator: ActorHttpInvalidateListenable;
|
|
15
16
|
readonly mediatorQuerySourceIdentify: MediatorQuerySourceIdentify;
|
|
@@ -22,6 +23,11 @@ export declare class ActorOptimizeQueryOperationQuerySourceIdentify extends Acto
|
|
|
22
23
|
identifySource(querySourceUnidentified: QuerySourceUnidentifiedExpanded, context: IActionContext): Promise<IQuerySourceWrapper>;
|
|
23
24
|
}
|
|
24
25
|
export interface IActorOptimizeQueryOperationQuerySourceIdentifyArgs extends IActorOptimizeQueryOperationArgs {
|
|
26
|
+
/**
|
|
27
|
+
* If the SERVICE target should be assumed to be a SPARQL endpoint.
|
|
28
|
+
* @default {false}
|
|
29
|
+
*/
|
|
30
|
+
serviceForceSparqlEndpoint: boolean;
|
|
25
31
|
/**
|
|
26
32
|
* The maximum number of entries in the LRU cache, set to 0 to disable.
|
|
27
33
|
* @range {integer}
|
|
@@ -30,7 +36,7 @@ export interface IActorOptimizeQueryOperationQuerySourceIdentifyArgs extends IAc
|
|
|
30
36
|
cacheSize: number;
|
|
31
37
|
/**
|
|
32
38
|
* An actor that listens to HTTP invalidation events
|
|
33
|
-
* @default {<default_invalidator> a <npmd:@comunica/bus-http-invalidate/^
|
|
39
|
+
* @default {<default_invalidator> a <npmd:@comunica/bus-http-invalidate/^5.0.0/components/ActorHttpInvalidateListenable.jsonld#ActorHttpInvalidateListenable>}
|
|
34
40
|
*/
|
|
35
41
|
httpInvalidator: ActorHttpInvalidateListenable;
|
|
36
42
|
/**
|
|
@@ -4,13 +4,26 @@ exports.ActorOptimizeQueryOperationQuerySourceIdentify = void 0;
|
|
|
4
4
|
const bus_optimize_query_operation_1 = require("@comunica/bus-optimize-query-operation");
|
|
5
5
|
const context_entries_1 = require("@comunica/context-entries");
|
|
6
6
|
const core_1 = require("@comunica/core");
|
|
7
|
+
const utils_algebra_1 = require("@comunica/utils-algebra");
|
|
8
|
+
const utils_query_operation_1 = require("@comunica/utils-query-operation");
|
|
7
9
|
const lru_cache_1 = require("lru-cache");
|
|
8
10
|
/**
|
|
9
11
|
* A comunica Query Source Identify Optimize Query Operation Actor.
|
|
10
12
|
*/
|
|
11
13
|
class ActorOptimizeQueryOperationQuerySourceIdentify extends bus_optimize_query_operation_1.ActorOptimizeQueryOperation {
|
|
14
|
+
serviceForceSparqlEndpoint;
|
|
15
|
+
cacheSize;
|
|
16
|
+
httpInvalidator;
|
|
17
|
+
mediatorQuerySourceIdentify;
|
|
18
|
+
mediatorContextPreprocess;
|
|
19
|
+
cache;
|
|
12
20
|
constructor(args) {
|
|
13
21
|
super(args);
|
|
22
|
+
this.serviceForceSparqlEndpoint = args.serviceForceSparqlEndpoint;
|
|
23
|
+
this.cacheSize = args.cacheSize;
|
|
24
|
+
this.httpInvalidator = args.httpInvalidator;
|
|
25
|
+
this.mediatorQuerySourceIdentify = args.mediatorQuerySourceIdentify;
|
|
26
|
+
this.mediatorContextPreprocess = args.mediatorContextPreprocess;
|
|
14
27
|
this.cache = this.cacheSize ? new lru_cache_1.LRUCache({ max: this.cacheSize }) : undefined;
|
|
15
28
|
const cache = this.cache;
|
|
16
29
|
if (cache) {
|
|
@@ -23,12 +36,13 @@ class ActorOptimizeQueryOperationQuerySourceIdentify extends bus_optimize_query_
|
|
|
23
36
|
async run(action) {
|
|
24
37
|
let context = action.context;
|
|
25
38
|
// Rewrite sources
|
|
39
|
+
let querySources;
|
|
26
40
|
if (context.has(context_entries_1.KeysInitQuery.querySourcesUnidentified)) {
|
|
27
41
|
const querySourcesUnidentified = action.context
|
|
28
42
|
.get(context_entries_1.KeysInitQuery.querySourcesUnidentified);
|
|
29
43
|
const querySourcesUnidentifiedExpanded = await Promise.all(querySourcesUnidentified
|
|
30
44
|
.map(querySource => this.expandSource(querySource)));
|
|
31
|
-
|
|
45
|
+
querySources = await Promise.all(querySourcesUnidentifiedExpanded
|
|
32
46
|
.map(async (querySourceUnidentified) => this.identifySource(querySourceUnidentified, action.context)));
|
|
33
47
|
// When identifying sources in preprocess actor, we record this as a dereference seed document event
|
|
34
48
|
const statisticDereferenceLinks = action.context
|
|
@@ -43,10 +57,32 @@ class ActorOptimizeQueryOperationQuerySourceIdentify extends bus_optimize_query_
|
|
|
43
57
|
}, querySource.source);
|
|
44
58
|
}
|
|
45
59
|
}
|
|
46
|
-
context =
|
|
60
|
+
context = context
|
|
47
61
|
.delete(context_entries_1.KeysInitQuery.querySourcesUnidentified)
|
|
48
62
|
.set(context_entries_1.KeysQueryOperation.querySources, querySources);
|
|
49
63
|
}
|
|
64
|
+
// Identify sources of SERVICE targets, unless the whole query is passed to the source (e.g. for SPARQL endpoints)
|
|
65
|
+
if (!await (0, utils_query_operation_1.passFullOperationToSource)(action.operation, querySources ?? [], context)) {
|
|
66
|
+
const services = new Set();
|
|
67
|
+
utils_algebra_1.algebraUtils.visitOperation(action.operation, {
|
|
68
|
+
[utils_algebra_1.Algebra.Types.SERVICE]: {
|
|
69
|
+
preVisitor: () => ({ continue: false }),
|
|
70
|
+
visitor: (serviceOperation) => {
|
|
71
|
+
if (serviceOperation.name.termType === 'NamedNode') {
|
|
72
|
+
services.add(serviceOperation.name.value);
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
const serviceSources = Object.fromEntries(await Promise.all([...services]
|
|
78
|
+
.map(async (service) => [service, await this.identifySource({
|
|
79
|
+
type: this.serviceForceSparqlEndpoint ? 'sparql' : undefined,
|
|
80
|
+
value: service,
|
|
81
|
+
}, context)])));
|
|
82
|
+
if (services.size > 0) {
|
|
83
|
+
context = context.set(context_entries_1.KeysQueryOperation.serviceSources, serviceSources);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
50
86
|
return { context, operation: action.operation };
|
|
51
87
|
}
|
|
52
88
|
async expandSource(querySource) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorOptimizeQueryOperationQuerySourceIdentify.js","sourceRoot":"","sources":["ActorOptimizeQueryOperationQuerySourceIdentify.ts"],"names":[],"mappings":";;;AAOA,yFAAqF;AAErF,+DAA8F;AAE9F,yCAA6D;AAU7D,yCAAqC;AAErC;;GAEG;AACH,MAAa,8CAA+C,SAAQ,0DAA2B;IAO7F,YAAmB,IAAyD;QAC1E,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,oBAAQ,CAAc,EAAE,GAAG,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC7F,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,CAAC,EAAE,GAAG,EAAyB,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAC5E,CAAC;QACJ,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,OAAsC;QACtD,OAAO,IAAA,mBAAY,GAAE,CAAC;IACxB,CAAC;IAEM,KAAK,CAAC,G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extPreprocess } from '@comunica/bus-context-preprocess';\nimport type { ActorHttpInvalidateListenable, IActionHttpInvalidate } from '@comunica/bus-http-invalidate';\nimport type {\n IActionOptimizeQueryOperation,\n IActorOptimizeQueryOperationOutput,\n IActorOptimizeQueryOperationArgs,\n} from '@comunica/bus-optimize-query-operation';\nimport { ActorOptimizeQueryOperation } from '@comunica/bus-optimize-query-operation';\nimport type { MediatorQuerySourceIdentify } from '@comunica/bus-query-source-identify';\nimport { KeysInitQuery, KeysQueryOperation, KeysStatistics } from '@comunica/context-entries';\nimport type { TestResult, IActorTest } from '@comunica/core';\nimport { passTestVoid, ActionContext } from '@comunica/core';\nimport type {\n IActionContext,\n ILink,\n IQuerySourceUnidentifiedExpanded,\n IQuerySourceWrapper,\n IStatisticBase,\n QuerySourceUnidentified,\n QuerySourceUnidentifiedExpanded,\n} from '@comunica/types';\nimport { LRUCache } from 'lru-cache';\n\n/**\n * A comunica Query Source Identify Optimize Query Operation Actor.\n */\nexport class ActorOptimizeQueryOperationQuerySourceIdentify extends ActorOptimizeQueryOperation {\n public readonly cacheSize: number;\n public readonly httpInvalidator: ActorHttpInvalidateListenable;\n public readonly mediatorQuerySourceIdentify: MediatorQuerySourceIdentify;\n public readonly mediatorContextPreprocess: MediatorContextPreprocess;\n public readonly cache?: LRUCache<string, Promise<IQuerySourceWrapper>>;\n\n public constructor(args: IActorOptimizeQueryOperationQuerySourceIdentifyArgs) {\n super(args);\n this.cache = this.cacheSize ? new LRUCache<string, any>({ max: this.cacheSize }) : undefined;\n const cache = this.cache;\n if (cache) {\n this.httpInvalidator.addInvalidateListener(\n ({ url }: IActionHttpInvalidate) => url ? cache.delete(url) : cache.clear(),\n );\n }\n }\n\n public async test(_action: IActionOptimizeQueryOperation): Promise<TestResult<IActorTest>> {\n return passTestVoid();\n }\n\n public async run(action: IActionOptimizeQueryOperation): Promise<IActorOptimizeQueryOperationOutput> {\n let context = action.context;\n\n // Rewrite sources\n if (context.has(KeysInitQuery.querySourcesUnidentified)) {\n const querySourcesUnidentified: QuerySourceUnidentified[] = action.context\n .get(KeysInitQuery.querySourcesUnidentified)!;\n const querySourcesUnidentifiedExpanded = await Promise.all(querySourcesUnidentified\n .map(querySource => this.expandSource(querySource)));\n const querySources: IQuerySourceWrapper[] = await Promise.all(querySourcesUnidentifiedExpanded\n .map(async querySourceUnidentified => this.identifySource(querySourceUnidentified, action.context)));\n\n // When identifying sources in preprocess actor, we record this as a dereference seed document event\n const statisticDereferenceLinks: IStatisticBase<ILink> | undefined = action.context\n .get(KeysStatistics.dereferencedLinks);\n if (statisticDereferenceLinks) {\n for (const querySource of querySources) {\n statisticDereferenceLinks.updateStatistic({\n url: <string> querySource.source.referenceValue,\n metadata: {\n seed: true,\n },\n }, querySource.source);\n }\n }\n\n context = action.context\n .delete(KeysInitQuery.querySourcesUnidentified)\n .set(KeysQueryOperation.querySources, querySources);\n }\n\n return { context, operation: action.operation };\n }\n\n public async expandSource(querySource: QuerySourceUnidentified): Promise<QuerySourceUnidentifiedExpanded> {\n if (typeof querySource === 'string' || 'match' in querySource) {\n return { value: querySource };\n }\n return {\n ...<Omit<IQuerySourceUnidentifiedExpanded, 'context'>>querySource,\n context: (await this.mediatorContextPreprocess.mediate({\n context: ActionContext.ensureActionContext(querySource.context ?? {}),\n })).context,\n };\n }\n\n public identifySource(\n querySourceUnidentified: QuerySourceUnidentifiedExpanded,\n context: IActionContext,\n ): Promise<IQuerySourceWrapper> {\n let sourcePromise: Promise<IQuerySourceWrapper> | undefined;\n\n // Try to read from cache\n // Only sources based on string values (e.g. URLs) are supported!\n if (typeof querySourceUnidentified.value === 'string' && this.cache) {\n sourcePromise = this.cache.get(querySourceUnidentified.value)!;\n }\n\n // If not in cache, identify the source\n if (!sourcePromise) {\n sourcePromise = this.mediatorQuerySourceIdentify.mediate({ querySourceUnidentified, context })\n .then(({ querySource }) => querySource);\n\n // Set in cache\n if (typeof querySourceUnidentified.value === 'string' && this.cache) {\n this.cache.set(querySourceUnidentified.value, sourcePromise);\n }\n }\n\n return sourcePromise;\n }\n}\n\nexport interface IActorOptimizeQueryOperationQuerySourceIdentifyArgs extends IActorOptimizeQueryOperationArgs {\n /**\n * The maximum number of entries in the LRU cache, set to 0 to disable.\n * @range {integer}\n * @default {100}\n */\n cacheSize: number;\n /* eslint-disable max-len */\n /**\n * An actor that listens to HTTP invalidation events\n * @default {<default_invalidator> a <npmd:@comunica/bus-http-invalidate/^4.0.0/components/ActorHttpInvalidateListenable.jsonld#ActorHttpInvalidateListenable>}\n */\n httpInvalidator: ActorHttpInvalidateListenable;\n /* eslint-enable max-len */\n /**\n * Mediator for identifying query sources.\n */\n mediatorQuerySourceIdentify: MediatorQuerySourceIdentify;\n /**\n * The context processing combinator\n */\n mediatorContextPreprocess: MediatorContextPreprocess;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ActorOptimizeQueryOperationQuerySourceIdentify.js","sourceRoot":"","sources":["ActorOptimizeQueryOperationQuerySourceIdentify.ts"],"names":[],"mappings":";;;AAOA,yFAAqF;AAErF,+DAA8F;AAE9F,yCAA6D;AAU7D,2DAAgE;AAChE,2EAA4E;AAC5E,yCAAqC;AAErC;;GAEG;AACH,MAAa,8CAA+C,SAAQ,0DAA2B;IAC7E,0BAA0B,CAAU;IACpC,SAAS,CAAS;IAClB,eAAe,CAAgC;IAC/C,2BAA2B,CAA8B;IACzD,yBAAyB,CAA4B;IACrD,KAAK,CAAkD;IAEvE,YAAmB,IAAyD;QAC1E,KAAK,CAAC,IAAI,CAAC,CAAC;QACZ,IAAI,CAAC,0BAA0B,GAAG,IAAI,CAAC,0BAA0B,CAAC;QAClE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC5C,IAAI,CAAC,2BAA2B,GAAG,IAAI,CAAC,2BAA2B,CAAC;QACpE,IAAI,CAAC,yBAAyB,GAAG,IAAI,CAAC,yBAAyB,CAAC;QAChE,IAAI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C;QACvC,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,aAAa,GAAG,IAAI,CAAC,2BAA2B,CAAC,OAAO,CAAC,EAAE,uBAAuB,EAAE,OAAO,EAAE,CAAC;iBAC3F,IAAI,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC;YAE1C,eAAe;YACf,IAAI,OAAO,uBAAuB,CAAC,KAAK,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACpE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,uBAAuB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;YAC/D,CAAC;QACH,CAAC;QAED,OAAO,aAAa,CAAC;IACvB,CAAC;CACF;AA3HD,wGA2HC","sourcesContent":["import type { MediatorContextPreprocess } from '@comunica/bus-context-preprocess';\nimport type { ActorHttpInvalidateListenable, IActionHttpInvalidate } from '@comunica/bus-http-invalidate';\nimport type {\n IActionOptimizeQueryOperation,\n IActorOptimizeQueryOperationOutput,\n IActorOptimizeQueryOperationArgs,\n} from '@comunica/bus-optimize-query-operation';\nimport { ActorOptimizeQueryOperation } from '@comunica/bus-optimize-query-operation';\nimport type { MediatorQuerySourceIdentify } from '@comunica/bus-query-source-identify';\nimport { KeysInitQuery, KeysQueryOperation, KeysStatistics } from '@comunica/context-entries';\nimport type { TestResult, IActorTest } from '@comunica/core';\nimport { passTestVoid, ActionContext } from '@comunica/core';\nimport type {\n IActionContext,\n ILink,\n IQuerySourceUnidentifiedExpanded,\n IQuerySourceWrapper,\n IStatisticBase,\n QuerySourceUnidentified,\n QuerySourceUnidentifiedExpanded,\n} from '@comunica/types';\nimport { Algebra, algebraUtils } from '@comunica/utils-algebra';\nimport { passFullOperationToSource } from '@comunica/utils-query-operation';\nimport { LRUCache } from 'lru-cache';\n\n/**\n * A comunica Query Source Identify Optimize Query Operation Actor.\n */\nexport class ActorOptimizeQueryOperationQuerySourceIdentify extends ActorOptimizeQueryOperation {\n public readonly serviceForceSparqlEndpoint: boolean;\n public readonly cacheSize: number;\n public readonly httpInvalidator: ActorHttpInvalidateListenable;\n public readonly mediatorQuerySourceIdentify: MediatorQuerySourceIdentify;\n public readonly mediatorContextPreprocess: MediatorContextPreprocess;\n public readonly cache?: LRUCache<string, Promise<IQuerySourceWrapper>>;\n\n public constructor(args: IActorOptimizeQueryOperationQuerySourceIdentifyArgs) {\n super(args);\n this.serviceForceSparqlEndpoint = args.serviceForceSparqlEndpoint;\n this.cacheSize = args.cacheSize;\n this.httpInvalidator = args.httpInvalidator;\n this.mediatorQuerySourceIdentify = args.mediatorQuerySourceIdentify;\n this.mediatorContextPreprocess = args.mediatorContextPreprocess;\n this.cache = this.cacheSize ? new LRUCache<string, any>({ max: this.cacheSize }) : undefined;\n const cache = this.cache;\n if (cache) {\n this.httpInvalidator.addInvalidateListener(\n ({ url }: IActionHttpInvalidate) => url ? cache.delete(url) : cache.clear(),\n );\n }\n }\n\n public async test(_action: IActionOptimizeQueryOperation): Promise<TestResult<IActorTest>> {\n return passTestVoid();\n }\n\n public async run(action: IActionOptimizeQueryOperation): Promise<IActorOptimizeQueryOperationOutput> {\n let context = action.context;\n\n // Rewrite sources\n let querySources: IQuerySourceWrapper[] | undefined;\n if (context.has(KeysInitQuery.querySourcesUnidentified)) {\n const querySourcesUnidentified: QuerySourceUnidentified[] = action.context\n .get(KeysInitQuery.querySourcesUnidentified)!;\n const querySourcesUnidentifiedExpanded = await Promise.all(querySourcesUnidentified\n .map(querySource => this.expandSource(querySource)));\n querySources = await Promise.all(querySourcesUnidentifiedExpanded\n .map(async querySourceUnidentified => this.identifySource(querySourceUnidentified, action.context)));\n\n // When identifying sources in preprocess actor, we record this as a dereference seed document event\n const statisticDereferenceLinks: IStatisticBase<ILink> | undefined = action.context\n .get(KeysStatistics.dereferencedLinks);\n if (statisticDereferenceLinks) {\n for (const querySource of querySources) {\n statisticDereferenceLinks.updateStatistic({\n url: <string> querySource.source.referenceValue,\n metadata: {\n seed: true,\n },\n }, querySource.source);\n }\n }\n\n context = context\n .delete(KeysInitQuery.querySourcesUnidentified)\n .set(KeysQueryOperation.querySources, querySources);\n }\n\n // Identify sources of SERVICE targets, unless the whole query is passed to the source (e.g. for SPARQL endpoints)\n if (!await passFullOperationToSource(action.operation, querySources ?? [], context)) {\n const services: Set<string> = new Set();\n algebraUtils.visitOperation(action.operation, {\n [Algebra.Types.SERVICE]: {\n preVisitor: () => ({ continue: false }),\n visitor: (serviceOperation) => {\n if (serviceOperation.name.termType === 'NamedNode') {\n services.add(serviceOperation.name.value);\n }\n },\n },\n });\n const serviceSources: Record<string, IQuerySourceWrapper> = Object.fromEntries(await Promise.all([ ...services ]\n .map(async service => [ service, await this.identifySource({\n type: this.serviceForceSparqlEndpoint ? 'sparql' : undefined,\n value: service,\n }, context) ])));\n if (services.size > 0) {\n context = context.set(KeysQueryOperation.serviceSources, serviceSources);\n }\n }\n\n return { context, operation: action.operation };\n }\n\n public async expandSource(querySource: QuerySourceUnidentified): Promise<QuerySourceUnidentifiedExpanded> {\n if (typeof querySource === 'string' || 'match' in querySource) {\n return { value: querySource };\n }\n return {\n ...<Omit<IQuerySourceUnidentifiedExpanded, 'context'>>querySource,\n context: (await this.mediatorContextPreprocess.mediate({\n context: ActionContext.ensureActionContext(querySource.context ?? {}),\n })).context,\n };\n }\n\n public identifySource(\n querySourceUnidentified: QuerySourceUnidentifiedExpanded,\n context: IActionContext,\n ): Promise<IQuerySourceWrapper> {\n let sourcePromise: Promise<IQuerySourceWrapper> | undefined;\n\n // Try to read from cache\n // Only sources based on string values (e.g. URLs) are supported!\n if (typeof querySourceUnidentified.value === 'string' && this.cache) {\n sourcePromise = this.cache.get(querySourceUnidentified.value)!;\n }\n\n // If not in cache, identify the source\n if (!sourcePromise) {\n sourcePromise = this.mediatorQuerySourceIdentify.mediate({ querySourceUnidentified, context })\n .then(({ querySource }) => querySource);\n\n // Set in cache\n if (typeof querySourceUnidentified.value === 'string' && this.cache) {\n this.cache.set(querySourceUnidentified.value, sourcePromise);\n }\n }\n\n return sourcePromise;\n }\n}\n\nexport interface IActorOptimizeQueryOperationQuerySourceIdentifyArgs extends IActorOptimizeQueryOperationArgs {\n /**\n * If the SERVICE target should be assumed to be a SPARQL endpoint.\n * @default {false}\n */\n serviceForceSparqlEndpoint: boolean;\n /**\n * The maximum number of entries in the LRU cache, set to 0 to disable.\n * @range {integer}\n * @default {100}\n */\n cacheSize: number;\n /* eslint-disable max-len */\n /**\n * An actor that listens to HTTP invalidation events\n * @default {<default_invalidator> a <npmd:@comunica/bus-http-invalidate/^5.0.0/components/ActorHttpInvalidateListenable.jsonld#ActorHttpInvalidateListenable>}\n */\n httpInvalidator: ActorHttpInvalidateListenable;\n /* eslint-enable max-len */\n /**\n * Mediator for identifying query sources.\n */\n mediatorQuerySourceIdentify: MediatorQuerySourceIdentify;\n /**\n * The context processing combinator\n */\n mediatorContextPreprocess: MediatorContextPreprocess;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-optimize-query-operation-query-source-identify",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "A query-source-identify optimize-query-operation actor",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"license": "MIT",
|
|
@@ -41,14 +41,16 @@
|
|
|
41
41
|
"build:components": "componentsjs-generator"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@comunica/bus-context-preprocess": "
|
|
45
|
-
"@comunica/bus-http-invalidate": "
|
|
46
|
-
"@comunica/bus-optimize-query-operation": "
|
|
47
|
-
"@comunica/bus-query-source-identify": "
|
|
48
|
-
"@comunica/context-entries": "
|
|
49
|
-
"@comunica/core": "
|
|
50
|
-
"@comunica/types": "
|
|
51
|
-
"
|
|
44
|
+
"@comunica/bus-context-preprocess": "^5.0.0",
|
|
45
|
+
"@comunica/bus-http-invalidate": "^5.0.0",
|
|
46
|
+
"@comunica/bus-optimize-query-operation": "^5.0.0",
|
|
47
|
+
"@comunica/bus-query-source-identify": "^5.0.0",
|
|
48
|
+
"@comunica/context-entries": "^5.0.0",
|
|
49
|
+
"@comunica/core": "^5.0.0",
|
|
50
|
+
"@comunica/types": "^5.0.0",
|
|
51
|
+
"@comunica/utils-algebra": "^5.0.0",
|
|
52
|
+
"@comunica/utils-query-operation": "^5.0.0",
|
|
53
|
+
"lru-cache": "^11.2.2"
|
|
52
54
|
},
|
|
53
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "0b1756fdb9bef014133432489627c1bd71779bd0"
|
|
54
56
|
}
|