@comunica/actor-query-operation-path-zero-or-one 2.6.11-alpha.41.0 → 2.7.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.
|
@@ -4,6 +4,7 @@ exports.ActorQueryOperationPathZeroOrOne = void 0;
|
|
|
4
4
|
const actor_abstract_path_1 = require("@comunica/actor-abstract-path");
|
|
5
5
|
const bindings_factory_1 = require("@comunica/bindings-factory");
|
|
6
6
|
const bus_query_operation_1 = require("@comunica/bus-query-operation");
|
|
7
|
+
const metadata_1 = require("@comunica/metadata");
|
|
7
8
|
const asynciterator_1 = require("asynciterator");
|
|
8
9
|
const sparqlalgebrajs_1 = require("sparqlalgebrajs");
|
|
9
10
|
const BF = new bindings_factory_1.BindingsFactory();
|
|
@@ -16,45 +17,73 @@ class ActorQueryOperationPathZeroOrOne extends actor_abstract_path_1.ActorAbstra
|
|
|
16
17
|
}
|
|
17
18
|
async runOperation(operation, context) {
|
|
18
19
|
const predicate = operation.predicate;
|
|
19
|
-
const sVar = operation.subject.termType === 'Variable';
|
|
20
|
-
const oVar = operation.object.termType === 'Variable';
|
|
21
20
|
const extra = [];
|
|
22
21
|
// Both subject and object non-variables
|
|
23
|
-
if (
|
|
22
|
+
if (operation.subject.termType !== 'Variable' &&
|
|
23
|
+
operation.object.termType !== 'Variable' &&
|
|
24
|
+
operation.subject.equals(operation.object)) {
|
|
24
25
|
return {
|
|
25
26
|
type: 'bindings',
|
|
26
27
|
bindingsStream: new asynciterator_1.SingletonIterator(BF.bindings()),
|
|
27
28
|
metadata: () => Promise.resolve({
|
|
29
|
+
state: new metadata_1.MetadataValidationState(),
|
|
28
30
|
cardinality: { type: 'exact', value: 1 },
|
|
29
31
|
canContainUndefs: false,
|
|
30
32
|
variables: [],
|
|
31
33
|
}),
|
|
32
34
|
};
|
|
33
35
|
}
|
|
34
|
-
if
|
|
35
|
-
throw new Error('ZeroOrOne path expressions with 2 variables not supported yet');
|
|
36
|
-
}
|
|
36
|
+
// Check if we require a distinct path operation
|
|
37
37
|
const distinct = await this.isPathArbitraryLengthDistinct(context, operation);
|
|
38
38
|
if (distinct.operation) {
|
|
39
39
|
return distinct.operation;
|
|
40
40
|
}
|
|
41
41
|
context = distinct.context;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
if (operation.object.termType === 'Variable') {
|
|
46
|
-
extra.push(BF.bindings([[operation.object, operation.subject]]));
|
|
47
|
-
}
|
|
48
|
-
const single = bus_query_operation_1.ActorQueryOperation.getSafeBindings(await this.mediatorQueryOperation.mediate({
|
|
42
|
+
// Create an operator that resolve to the "One" part
|
|
43
|
+
const bindingsOne = bus_query_operation_1.ActorQueryOperation.getSafeBindings(await this.mediatorQueryOperation.mediate({
|
|
49
44
|
context,
|
|
50
45
|
operation: actor_abstract_path_1.ActorAbstractPath.FACTORY
|
|
51
46
|
.createPath(operation.subject, predicate.path, operation.object, operation.graph),
|
|
52
47
|
}));
|
|
53
|
-
|
|
48
|
+
// Determine the bindings stream based on the variable-ness of subject and object
|
|
49
|
+
let bindingsStream;
|
|
50
|
+
if (operation.subject.termType === 'Variable' && operation.object.termType === 'Variable') {
|
|
51
|
+
// Both subject and object are variables
|
|
52
|
+
// To determine the "Zero" part, we
|
|
53
|
+
// query ?s ?p ?o. FILTER ?s = ?0, to get all possible namedNodes in de the db
|
|
54
|
+
const varP = this.generateVariable(operation);
|
|
55
|
+
const bindingsZero = bus_query_operation_1.ActorQueryOperation.getSafeBindings(await this.mediatorQueryOperation.mediate({
|
|
56
|
+
context,
|
|
57
|
+
operation: actor_abstract_path_1.ActorAbstractPath.FACTORY.createFilter(actor_abstract_path_1.ActorAbstractPath.FACTORY
|
|
58
|
+
.createPattern(operation.subject, varP, operation.object, operation.graph), actor_abstract_path_1.ActorAbstractPath.FACTORY.createOperatorExpression('=', [
|
|
59
|
+
actor_abstract_path_1.ActorAbstractPath.FACTORY.createTermExpression(operation.subject),
|
|
60
|
+
actor_abstract_path_1.ActorAbstractPath.FACTORY.createTermExpression(operation.object),
|
|
61
|
+
])),
|
|
62
|
+
})).bindingsStream.transform({
|
|
63
|
+
map(bindings) {
|
|
64
|
+
return bindings.delete(varP);
|
|
65
|
+
},
|
|
66
|
+
autoStart: false,
|
|
67
|
+
});
|
|
68
|
+
bindingsStream = new asynciterator_1.UnionIterator([
|
|
69
|
+
bindingsZero,
|
|
70
|
+
bindingsOne.bindingsStream,
|
|
71
|
+
], { autoStart: false });
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
// If subject or object is not a variable, then determining the "Zero" part is simple.
|
|
75
|
+
if (operation.subject.termType === 'Variable') {
|
|
76
|
+
extra.push(BF.bindings([[operation.subject, operation.object]]));
|
|
77
|
+
}
|
|
78
|
+
if (operation.object.termType === 'Variable') {
|
|
79
|
+
extra.push(BF.bindings([[operation.object, operation.subject]]));
|
|
80
|
+
}
|
|
81
|
+
bindingsStream = bindingsOne.bindingsStream.prepend(extra);
|
|
82
|
+
}
|
|
54
83
|
return {
|
|
55
84
|
type: 'bindings',
|
|
56
85
|
bindingsStream,
|
|
57
|
-
metadata:
|
|
86
|
+
metadata: bindingsOne.metadata,
|
|
58
87
|
};
|
|
59
88
|
}
|
|
60
89
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorQueryOperationPathZeroOrOne.js","sourceRoot":"","sources":["ActorQueryOperationPathZeroOrOne.ts"],"names":[],"mappings":";;;AAAA,uEAAkE;AAClE,iEAA6D;AAE7D,uEAAoE;
|
|
1
|
+
{"version":3,"file":"ActorQueryOperationPathZeroOrOne.js","sourceRoot":"","sources":["ActorQueryOperationPathZeroOrOne.ts"],"names":[],"mappings":";;;AAAA,uEAAkE;AAClE,iEAA6D;AAE7D,uEAAoE;AACpE,iDAA6D;AAE7D,iDAEuB;AACvB,qDAA0C;AAE1C,MAAM,EAAE,GAAG,IAAI,kCAAe,EAAE,CAAC;AAEjC;;GAEG;AACH,MAAa,gCAAiC,SAAQ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YACtF,IAAI,SAAS,CAAC,OAAO,CAAC,QAAQ,KAAK,UAAU,EAAE;gBAC7C,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAE,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,MAAM,CAAE,CAAC,CAAC,CAAC,CAAC;aACpE;YACD,IAAI,SAAS,CAAC,MAAM,CAAC,QAAQ,KAAK,UAAU,EAAE;gBAC5C,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAE,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,OAAO,CAAE,CAAC,CAAC,CAAC,CAAC;aACpE;YAED,cAAc,GAAG,WAAW,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;SAC5D;QAED,OAAO;YACL,IAAI,EAAE,UAAU;YAChB,cAAc;YACd,QAAQ,EAAE,WAAW,CAAC,QAAQ;SAC/B,CAAC;IACJ,CAAC;CACF;AA1FD,4EA0FC","sourcesContent":["import { ActorAbstractPath } from '@comunica/actor-abstract-path';\nimport { BindingsFactory } from '@comunica/bindings-factory';\nimport type { IActorQueryOperationTypedMediatedArgs } from '@comunica/bus-query-operation';\nimport { ActorQueryOperation } from '@comunica/bus-query-operation';\nimport { MetadataValidationState } from '@comunica/metadata';\nimport type { Bindings, IQueryOperationResult, IActionContext, BindingsStream } from '@comunica/types';\nimport {\n SingletonIterator, UnionIterator,\n} from 'asynciterator';\nimport { Algebra } from 'sparqlalgebrajs';\n\nconst BF = new BindingsFactory();\n\n/**\n * A comunica Path ZeroOrOne Query Operation Actor.\n */\nexport class ActorQueryOperationPathZeroOrOne extends ActorAbstractPath {\n public constructor(args: IActorQueryOperationTypedMediatedArgs) {\n super(args, Algebra.types.ZERO_OR_ONE_PATH);\n }\n\n public async runOperation(\n operation: Algebra.Path,\n context: IActionContext,\n ): Promise<IQueryOperationResult> {\n const predicate = <Algebra.ZeroOrOnePath> operation.predicate;\n\n const extra: Bindings[] = [];\n\n // Both subject and object non-variables\n if (operation.subject.termType !== 'Variable' &&\n operation.object.termType !== 'Variable' &&\n operation.subject.equals(operation.object)) {\n return {\n type: 'bindings',\n bindingsStream: new SingletonIterator(BF.bindings()),\n metadata: () => Promise.resolve({\n state: new MetadataValidationState(),\n cardinality: { type: 'exact', value: 1 },\n canContainUndefs: false,\n variables: [],\n }),\n };\n }\n\n // Check if we require a distinct path operation\n const distinct = await this.isPathArbitraryLengthDistinct(context, operation);\n if (distinct.operation) {\n return distinct.operation;\n }\n context = distinct.context;\n\n // Create an operator that resolve to the \"One\" part\n const bindingsOne = ActorQueryOperation.getSafeBindings(await this.mediatorQueryOperation.mediate({\n context,\n operation: ActorAbstractPath.FACTORY\n .createPath(operation.subject, predicate.path, operation.object, operation.graph),\n }));\n\n // Determine the bindings stream based on the variable-ness of subject and object\n let bindingsStream: BindingsStream;\n if (operation.subject.termType === 'Variable' && operation.object.termType === 'Variable') {\n // Both subject and object are variables\n // To determine the \"Zero\" part, we\n // query ?s ?p ?o. FILTER ?s = ?0, to get all possible namedNodes in de the db\n const varP = this.generateVariable(operation);\n const bindingsZero = ActorQueryOperation.getSafeBindings(\n await this.mediatorQueryOperation.mediate({\n context,\n operation: ActorAbstractPath.FACTORY.createFilter(\n ActorAbstractPath.FACTORY\n .createPattern(operation.subject, varP, operation.object, operation.graph),\n ActorAbstractPath.FACTORY.createOperatorExpression('=', [\n ActorAbstractPath.FACTORY.createTermExpression(operation.subject),\n ActorAbstractPath.FACTORY.createTermExpression(operation.object),\n ]),\n ),\n }),\n ).bindingsStream.transform({\n map(bindings) {\n return bindings.delete(varP);\n },\n autoStart: false,\n });\n bindingsStream = new UnionIterator([\n bindingsZero,\n bindingsOne.bindingsStream,\n ], { autoStart: false });\n } else {\n // If subject or object is not a variable, then determining the \"Zero\" part is simple.\n if (operation.subject.termType === 'Variable') {\n extra.push(BF.bindings([[ operation.subject, operation.object ]]));\n }\n if (operation.object.termType === 'Variable') {\n extra.push(BF.bindings([[ operation.object, operation.subject ]]));\n }\n\n bindingsStream = bindingsOne.bindingsStream.prepend(extra);\n }\n\n return {\n type: 'bindings',\n bindingsStream,\n metadata: bindingsOne.metadata,\n };\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-query-operation-path-zero-or-one",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "A path-zero-or-one query-operation actor",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -32,10 +32,11 @@
|
|
|
32
32
|
"lib/**/*.js.map"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@comunica/actor-abstract-path": "2.
|
|
36
|
-
"@comunica/bindings-factory": "2.
|
|
37
|
-
"@comunica/bus-query-operation": "2.
|
|
38
|
-
"@comunica/
|
|
35
|
+
"@comunica/actor-abstract-path": "^2.7.0",
|
|
36
|
+
"@comunica/bindings-factory": "^2.7.0",
|
|
37
|
+
"@comunica/bus-query-operation": "^2.7.0",
|
|
38
|
+
"@comunica/metadata": "^2.7.0",
|
|
39
|
+
"@comunica/types": "^2.7.0",
|
|
39
40
|
"asynciterator": "^3.8.0",
|
|
40
41
|
"sparqlalgebrajs": "^4.0.5"
|
|
41
42
|
},
|
|
@@ -44,5 +45,5 @@
|
|
|
44
45
|
"build:ts": "node \"../../node_modules/typescript/bin/tsc\"",
|
|
45
46
|
"build:components": "componentsjs-generator"
|
|
46
47
|
},
|
|
47
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "3de278d67a7c21c7887a1b0ea908a0ca4c52de91"
|
|
48
49
|
}
|