@comunica/actor-term-comparator-factory-expression-evaluator 5.3.0 → 5.5.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 +13 -10
- package/lib/ActorTermComparatorFactoryExpressionEvaluator.js +5 -3
- package/lib/ActorTermComparatorFactoryExpressionEvaluator.js.map +1 -1
- package/lib/TermComparatorExpressionEvaluator.d.ts +7 -4
- package/lib/TermComparatorExpressionEvaluator.js +53 -59
- package/lib/TermComparatorExpressionEvaluator.js.map +1 -1
- package/package.json +10 -9
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
# Comunica
|
|
1
|
+
# Comunica Expression Evaluator Term Comparator Factory Actor
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@comunica/actor-term-comparator-factory-expression-evaluator)
|
|
4
4
|
|
|
5
|
-
A [term comparator factory](https://github.com/comunica/comunica/tree/master/packages/bus-
|
|
6
|
-
that
|
|
5
|
+
A [term comparator factory](https://github.com/comunica/comunica/tree/master/packages/bus-term-comparator-factory) actor
|
|
6
|
+
that orders terms by evaluating the `<` function of the expression evaluator in both directions.
|
|
7
7
|
|
|
8
8
|
This module is part of the [Comunica framework](https://github.com/comunica/comunica),
|
|
9
9
|
and should only be used by [developers that want to build their own query engine](https://comunica.dev/docs/modify/).
|
|
@@ -13,7 +13,7 @@ and should only be used by [developers that want to build their own query engine
|
|
|
13
13
|
## Install
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
$ yarn add @comunica/actor-term-comparator-factory-
|
|
16
|
+
$ yarn add @comunica/actor-term-comparator-factory-expression-evaluator
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Configure
|
|
@@ -23,13 +23,16 @@ After installing, this package can be added to your engine's configuration as fo
|
|
|
23
23
|
{
|
|
24
24
|
"@context": [
|
|
25
25
|
...
|
|
26
|
-
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-term-comparator-factory-expression-evaluator/^
|
|
26
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@comunica/actor-term-comparator-factory-expression-evaluator/^5.0.0/components/context.jsonld"
|
|
27
27
|
],
|
|
28
28
|
"actors": [
|
|
29
29
|
...
|
|
30
30
|
{
|
|
31
|
-
"@id": "urn:comunica:default:term-comparator-factory/actors#
|
|
32
|
-
"@type": "ActorTermComparatorFactoryExpressionEvaluator"
|
|
31
|
+
"@id": "urn:comunica:default:term-comparator-factory/actors#expression-evaluator",
|
|
32
|
+
"@type": "ActorTermComparatorFactoryExpressionEvaluator",
|
|
33
|
+
"mediatorQueryOperation": { "@id": "urn:comunica:default:query-operation/mediators#main" },
|
|
34
|
+
"mediatorFunctionFactory": { "@id": "urn:comunica:default:function-factory/mediators#main" },
|
|
35
|
+
"mediatorMergeBindingsContext": { "@id": "urn:comunica:default:merge-bindings-context/mediators#main" }
|
|
33
36
|
}
|
|
34
37
|
]
|
|
35
38
|
}
|
|
@@ -37,6 +40,6 @@ After installing, this package can be added to your engine's configuration as fo
|
|
|
37
40
|
|
|
38
41
|
### Config Parameters
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
* `
|
|
43
|
+
* `mediatorQueryOperation`: A mediator over the [query operation bus](https://github.com/comunica/comunica/tree/master/packages/bus-query-operation).
|
|
44
|
+
* `mediatorFunctionFactory`: A mediator over the [function factory bus](https://github.com/comunica/comunica/tree/master/packages/bus-function-factory), required to evaluate the comparison functions.
|
|
45
|
+
* `mediatorMergeBindingsContext`: A mediator over the [merge bindings context bus](https://github.com/comunica/comunica/tree/master/packages/bus-merge-bindings-context).
|
|
@@ -34,7 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.ActorTermComparatorFactoryExpressionEvaluator = void 0;
|
|
37
|
-
const
|
|
37
|
+
const actor_expression_evaluator_factory_default_1 = require("@comunica/actor-expression-evaluator-factory-default");
|
|
38
38
|
const bus_term_comparator_factory_1 = require("@comunica/bus-term-comparator-factory");
|
|
39
39
|
const context_entries_1 = require("@comunica/context-entries");
|
|
40
40
|
const core_1 = require("@comunica/core");
|
|
@@ -54,8 +54,10 @@ class ActorTermComparatorFactoryExpressionEvaluator extends bus_term_comparator_
|
|
|
54
54
|
* @param context.context IActionContext
|
|
55
55
|
*/
|
|
56
56
|
async run({ context }) {
|
|
57
|
-
context = Eval.prepareEvaluatorActionContext(context)
|
|
58
|
-
|
|
57
|
+
context = Eval.prepareEvaluatorActionContext(context)
|
|
58
|
+
.set(context_entries_1.KeysExpressionEvaluator.nonLexicalComparison, true)
|
|
59
|
+
.set(context_entries_1.KeysExpressionEvaluator.fullTermComparison, true);
|
|
60
|
+
return new TermComparatorExpressionEvaluator_1.TermComparatorExpressionEvaluator(new actor_expression_evaluator_factory_default_1.InternalEvaluator(context, this.mediatorFunctionFactory, this.mediatorQueryOperation, await utils_bindings_factory_1.BindingsFactory.create(this.mediatorMergeBindingsContext, context, context.getSafe(context_entries_1.KeysInitQuery.dataFactory))), await this.mediatorFunctionFactory
|
|
59
61
|
.mediate({ functionName: Eval.SparqlOperator.EQUAL, context, requireTermExpression: true }), await this.mediatorFunctionFactory
|
|
60
62
|
.mediate({ functionName: Eval.SparqlOperator.LT, context, requireTermExpression: true }));
|
|
61
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActorTermComparatorFactoryExpressionEvaluator.js","sourceRoot":"","sources":["ActorTermComparatorFactoryExpressionEvaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"ActorTermComparatorFactoryExpressionEvaluator.js","sourceRoot":"","sources":["ActorTermComparatorFactoryExpressionEvaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qHAAyF;AAKzF,uFAAmF;AACnF,+DAAmF;AAEnF,yCAA8C;AAC9C,6EAAmE;AACnE,2EAA6D;AAC7D,2FAAwF;AAExF;;GAEG;AACH,MAAa,6CAA8C,SAAQ,wDAA0B;IACpF,KAAK,CAAC,IAAI,CAAC,OAAqC;QACrD,OAAO,IAAA,mBAAY,GAAE,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAgC;QACxD,OAAO,GAAG,IAAI,CAAC,6BAA6B,CAAC,OAAO,CAAC;aAClD,GAAG,CAAC,yCAAuB,CAAC,oBAAoB,EAAE,IAAI,CAAC;aACvD,GAAG,CAAC,yCAAuB,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;QACzD,OAAO,IAAI,qEAAiC,CAC1C,IAAI,8DAAiB,CACnB,OAAO,EACP,IAAI,CAAC,uBAAuB,EAC5B,IAAI,CAAC,sBAAsB,EAC3B,MAAM,wCAAe,CAAC,MAAM,CAC1B,IAAI,CAAC,4BAA4B,EACjC,OAAO,EACP,OAAO,CAAC,OAAO,CAAC,+BAAa,CAAC,WAAW,CAAC,CAC3C,CACF,EACD,MAAM,IAAI,CAAC,uBAAuB;aAC/B,OAAO,CAAC,EAAE,YAAY,EAAE,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,OAAO,EAAE,qBAAqB,EAAE,IAAI,EAAE,CAAC,EAC7F,MAAM,IAAI,CAAC,uBAAuB;aAC/B,OAAO,CAAC,EAAE,YAAY,EAAE,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE,OAAO,EAAE,qBAAqB,EAAE,IAAI,EAAE,CAAC,CAC3F,CAAC;IACJ,CAAC;CACF;AA/BD,sGA+BC","sourcesContent":["import { InternalEvaluator } from '@comunica/actor-expression-evaluator-factory-default';\nimport type {\n IActionTermComparatorFactory,\n IActorTermComparatorFactoryOutput,\n} from '@comunica/bus-term-comparator-factory';\nimport { ActorTermComparatorFactory } from '@comunica/bus-term-comparator-factory';\nimport { KeysExpressionEvaluator, KeysInitQuery } from '@comunica/context-entries';\nimport type { IActorTest, TestResult } from '@comunica/core';\nimport { passTestVoid } from '@comunica/core';\nimport { BindingsFactory } from '@comunica/utils-bindings-factory';\nimport * as Eval from '@comunica/utils-expression-evaluator';\nimport { TermComparatorExpressionEvaluator } from './TermComparatorExpressionEvaluator';\n\n/**\n * A comunica Expression Evaluator Based Term Comparator Factory Actor.\n */\nexport class ActorTermComparatorFactoryExpressionEvaluator extends ActorTermComparatorFactory {\n public async test(_action: IActionTermComparatorFactory): Promise<TestResult<IActorTest>> {\n return passTestVoid();\n }\n\n /**\n * Context item superTypeProvider can be expected here\n * @param context IActionTermComparatorFactory\n * @param context.context IActionContext\n */\n public async run({ context }: IActionTermComparatorFactory): Promise<IActorTermComparatorFactoryOutput> {\n context = Eval.prepareEvaluatorActionContext(context)\n .set(KeysExpressionEvaluator.nonLexicalComparison, true)\n .set(KeysExpressionEvaluator.fullTermComparison, true);\n return new TermComparatorExpressionEvaluator(\n new InternalEvaluator(\n context,\n this.mediatorFunctionFactory,\n this.mediatorQueryOperation,\n await BindingsFactory.create(\n this.mediatorMergeBindingsContext,\n context,\n context.getSafe(KeysInitQuery.dataFactory),\n ),\n ),\n await this.mediatorFunctionFactory\n .mediate({ functionName: Eval.SparqlOperator.EQUAL, context, requireTermExpression: true }),\n await this.mediatorFunctionFactory\n .mediate({ functionName: Eval.SparqlOperator.LT, context, requireTermExpression: true }),\n );\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { InternalEvaluator } from '@comunica/actor-expression-evaluator-factory-default
|
|
1
|
+
import type { InternalEvaluator } from '@comunica/actor-expression-evaluator-factory-default';
|
|
2
2
|
import type { ITermFunction } from '@comunica/bus-function-factory';
|
|
3
3
|
import type { ITermComparator } from '@comunica/bus-term-comparator-factory';
|
|
4
4
|
import type * as RDF from '@rdfjs/types';
|
|
@@ -8,7 +8,10 @@ export declare class TermComparatorExpressionEvaluator implements ITermComparato
|
|
|
8
8
|
private readonly lessThanFunction;
|
|
9
9
|
constructor(internalEvaluator: InternalEvaluator, equalityFunction: ITermFunction, lessThanFunction: ITermFunction);
|
|
10
10
|
orderTypes(termA: RDF.Term | undefined, termB: RDF.Term | undefined): -1 | 0 | 1;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Order two defined terms by evaluating the SPARQL `<` operator in both directions.
|
|
13
|
+
* @param termA the first term
|
|
14
|
+
* @param termB the second term
|
|
15
|
+
*/
|
|
16
|
+
private orderTypesGeneral;
|
|
14
17
|
}
|
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TermComparatorExpressionEvaluator = void 0;
|
|
4
|
+
const actor_function_factory_term_lesser_than_1 = require("@comunica/actor-function-factory-term-lesser-than");
|
|
5
|
+
/**
|
|
6
|
+
* The name the expression evaluator gives each RDF/JS term type.
|
|
7
|
+
*
|
|
8
|
+
* Only needed to look a term up in {@link TermFunctionLesserThan.TERM_ORDERING_PRIORITY}, which is keyed
|
|
9
|
+
* by the evaluator's names. A term type that is absent here, such as a variable, is not one this
|
|
10
|
+
* comparator short-circuits, and falls through to the operator itself.
|
|
11
|
+
*/
|
|
12
|
+
const EVALUATOR_TERM_TYPES = {
|
|
13
|
+
BlankNode: 'blankNode',
|
|
14
|
+
NamedNode: 'namedNode',
|
|
15
|
+
Literal: 'literal',
|
|
16
|
+
Quad: 'quad',
|
|
17
|
+
DefaultGraph: 'defaultGraph',
|
|
18
|
+
};
|
|
4
19
|
class TermComparatorExpressionEvaluator {
|
|
5
20
|
internalEvaluator;
|
|
6
21
|
equalityFunction;
|
|
7
22
|
lessThanFunction;
|
|
8
|
-
constructor(
|
|
23
|
+
constructor(
|
|
24
|
+
// The internal evaluator is expected to have a context with nonLexicalComparison and fullTermComparison set to true
|
|
25
|
+
internalEvaluator,
|
|
26
|
+
// TODO: remove in next major, as it's unused
|
|
27
|
+
equalityFunction, lessThanFunction) {
|
|
9
28
|
this.internalEvaluator = internalEvaluator;
|
|
10
29
|
this.equalityFunction = equalityFunction;
|
|
11
30
|
this.lessThanFunction = lessThanFunction;
|
|
@@ -24,71 +43,46 @@ class TermComparatorExpressionEvaluator {
|
|
|
24
43
|
if (termB === undefined) {
|
|
25
44
|
return 1;
|
|
26
45
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
// Handle quoted triples
|
|
36
|
-
if (termA.termType === 'Quad' && termB.termType === 'Quad') {
|
|
37
|
-
const orderSubject = this.orderTypes(termA.subject, termB.subject);
|
|
38
|
-
if (orderSubject !== 0) {
|
|
39
|
-
return orderSubject;
|
|
40
|
-
}
|
|
41
|
-
const orderPredicate = this.orderTypes(termA.predicate, termB.predicate);
|
|
42
|
-
if (orderPredicate !== 0) {
|
|
43
|
-
return orderPredicate;
|
|
46
|
+
if (termA.termType === termB.termType) {
|
|
47
|
+
// Fast path to order two IRIs or two blank nodes by their value.
|
|
48
|
+
if (termA.termType === 'NamedNode' || termA.termType === 'BlankNode') {
|
|
49
|
+
if (termA.value === termB.value) {
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
return termA.value < termB.value ? -1 : 1;
|
|
44
53
|
}
|
|
45
|
-
const orderObject = this.orderTypes(termA.object, termB.object);
|
|
46
|
-
if (orderObject !== 0) {
|
|
47
|
-
return orderObject;
|
|
48
|
-
}
|
|
49
|
-
return this.orderTypes(termA.graph, termB.graph);
|
|
50
54
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
else {
|
|
56
|
+
// Fast path to order terms of differing types.
|
|
57
|
+
const priorityA = EVALUATOR_TERM_TYPES[termA.termType];
|
|
58
|
+
const priorityB = EVALUATOR_TERM_TYPES[termB.termType];
|
|
59
|
+
if (priorityA !== undefined && priorityB !== undefined) {
|
|
60
|
+
return actor_function_factory_term_lesser_than_1.TermFunctionLesserThan.TERM_ORDERING_PRIORITY[priorityA] <
|
|
61
|
+
actor_function_factory_term_lesser_than_1.TermFunctionLesserThan.TERM_ORDERING_PRIORITY[priorityB] ?
|
|
62
|
+
-1 :
|
|
63
|
+
1;
|
|
64
|
+
}
|
|
54
65
|
}
|
|
55
|
-
return this.
|
|
66
|
+
return this.orderTypesGeneral(termA, termB);
|
|
56
67
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
return 1;
|
|
68
|
+
/**
|
|
69
|
+
* Order two defined terms by evaluating the SPARQL `<` operator in both directions.
|
|
70
|
+
* @param termA the first term
|
|
71
|
+
* @param termB the second term
|
|
72
|
+
*/
|
|
73
|
+
orderTypesGeneral(termA, termB) {
|
|
74
|
+
const myTermA = this.internalEvaluator.transformer.transformRDFTermUnsafe(termA);
|
|
75
|
+
const myTermB = this.internalEvaluator.transformer.transformRDFTermUnsafe(termB);
|
|
76
|
+
if (this.lessThanFunction.applyOnTerms([myTermA, myTermB], this.internalEvaluator)
|
|
77
|
+
.typedValue) {
|
|
78
|
+
return -1;
|
|
70
79
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (compareType !== 0) {
|
|
75
|
-
return compareType;
|
|
76
|
-
}
|
|
77
|
-
return this.comparePrimitives(myLitA.str(), myLitB.str());
|
|
80
|
+
if (this.lessThanFunction.applyOnTerms([myTermB, myTermA], this.internalEvaluator)
|
|
81
|
+
.typedValue) {
|
|
82
|
+
return 1;
|
|
78
83
|
}
|
|
84
|
+
return 0;
|
|
79
85
|
}
|
|
80
|
-
comparePrimitives(valueA, valueB) {
|
|
81
|
-
return valueA === valueB ? 0 : (valueA < valueB ? -1 : 1);
|
|
82
|
-
}
|
|
83
|
-
// SPARQL specifies that blankNode < namedNode < literal. Sparql star expands with < quads and we say < defaultGraph
|
|
84
|
-
_TERM_ORDERING_PRIORITY = {
|
|
85
|
-
Variable: 0,
|
|
86
|
-
BlankNode: 1,
|
|
87
|
-
NamedNode: 2,
|
|
88
|
-
Literal: 3,
|
|
89
|
-
Quad: 4,
|
|
90
|
-
DefaultGraph: 5,
|
|
91
|
-
};
|
|
92
86
|
}
|
|
93
87
|
exports.TermComparatorExpressionEvaluator = TermComparatorExpressionEvaluator;
|
|
94
88
|
//# sourceMappingURL=TermComparatorExpressionEvaluator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TermComparatorExpressionEvaluator.js","sourceRoot":"","sources":["TermComparatorExpressionEvaluator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"TermComparatorExpressionEvaluator.js","sourceRoot":"","sources":["TermComparatorExpressionEvaluator.ts"],"names":[],"mappings":";;;AACA,+GAA2F;AAM3F;;;;;;GAMG;AACH,MAAM,oBAAoB,GAGrB;IACH,SAAS,EAAE,WAAW;IACtB,SAAS,EAAE,WAAW;IACtB,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,YAAY,EAAE,cAAc;CAC7B,CAAC;AAEF,MAAa,iCAAiC;IAGzB;IAEA;IACA;IALnB;IACE,oHAAoH;IACnG,iBAAoC;IACrD,6CAA6C;IAC5B,gBAA+B,EAC/B,gBAA+B;QAH/B,sBAAiB,GAAjB,iBAAiB,CAAmB;QAEpC,qBAAgB,GAAhB,gBAAgB,CAAe;QAC/B,qBAAgB,GAAhB,gBAAgB,CAAe;IAC/C,CAAC;IAEJ,iEAAiE;IACjE,sEAAsE;IAC/D,UAAU,CAAC,KAA2B,EAAE,KAA2B;QACxE,2CAA2C;QAC3C,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YACpB,OAAO,CAAC,CAAC;QACX,CAAC;QAED,0DAA0D;QAC1D,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,CAAC,CAAC,CAAC;QACZ,CAAC;QACD,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,OAAO,CAAC,CAAC;QACX,CAAC;QAED,IAAI,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ,EAAE,CAAC;YACtC,iEAAiE;YACjE,IAAI,KAAK,CAAC,QAAQ,KAAK,WAAW,IAAI,KAAK,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;gBACrE,IAAI,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC;oBAChC,OAAO,CAAC,CAAC;gBACX,CAAC;gBACD,OAAO,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;aAAM,CAAC;YACN,+CAA+C;YAC/C,MAAM,SAAS,GAAG,oBAAoB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACvD,MAAM,SAAS,GAAG,oBAAoB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACvD,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;gBACvD,OAAO,gEAAsB,CAAC,sBAAsB,CAAC,SAAS,CAAC;oBAC7D,gEAAsB,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC,CAAC;oBACxD,CAAC,CAAC,CAAC,CAAC;oBACN,CAAC,CAAC;YACN,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACK,iBAAiB,CAAC,KAAe,EAAE,KAAe;QACxD,MAAM,OAAO,GAAc,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;QAC5F,MAAM,OAAO,GAAc,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;QAE5F,IAA2B,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAE,OAAO,EAAE,OAAO,CAAE,EAAE,IAAI,CAAC,iBAAiB,CAAE;aACzG,UAAU,EAAE,CAAC;YACd,OAAO,CAAC,CAAC,CAAC;QACZ,CAAC;QACD,IAA2B,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAE,OAAO,EAAE,OAAO,CAAE,EAAE,IAAI,CAAC,iBAAiB,CAAE;aACzG,UAAU,EAAE,CAAC;YACd,OAAO,CAAC,CAAC;QACX,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AAnED,8EAmEC","sourcesContent":["import type { InternalEvaluator } from '@comunica/actor-expression-evaluator-factory-default';\nimport { TermFunctionLesserThan } from '@comunica/actor-function-factory-term-lesser-than';\nimport type { ITermFunction } from '@comunica/bus-function-factory';\nimport type { ITermComparator } from '@comunica/bus-term-comparator-factory';\nimport type * as Eval from '@comunica/utils-expression-evaluator';\nimport type * as RDF from '@rdfjs/types';\n\n/**\n * The name the expression evaluator gives each RDF/JS term type.\n *\n * Only needed to look a term up in {@link TermFunctionLesserThan.TERM_ORDERING_PRIORITY}, which is keyed\n * by the evaluator's names. A term type that is absent here, such as a variable, is not one this\n * comparator short-circuits, and falls through to the operator itself.\n */\nconst EVALUATOR_TERM_TYPES: Partial<Record<\n RDF.Term['termType'],\nkeyof typeof TermFunctionLesserThan.TERM_ORDERING_PRIORITY\n>> = {\n BlankNode: 'blankNode',\n NamedNode: 'namedNode',\n Literal: 'literal',\n Quad: 'quad',\n DefaultGraph: 'defaultGraph',\n};\n\nexport class TermComparatorExpressionEvaluator implements ITermComparator {\n public constructor(\n // The internal evaluator is expected to have a context with nonLexicalComparison and fullTermComparison set to true\n private readonly internalEvaluator: InternalEvaluator,\n // TODO: remove in next major, as it's unused\n private readonly equalityFunction: ITermFunction,\n private readonly lessThanFunction: ITermFunction,\n ) {}\n\n // Determine the relative numerical order of the two given terms.\n // In accordance with https://www.w3.org/TR/sparql11-query/#modOrderBy\n public orderTypes(termA: RDF.Term | undefined, termB: RDF.Term | undefined): -1 | 0 | 1 {\n // Check if terms are the same by reference\n if (termA === termB) {\n return 0;\n }\n\n // We handle undefined that is lower than everything else.\n if (termA === undefined) {\n return -1;\n }\n if (termB === undefined) {\n return 1;\n }\n\n if (termA.termType === termB.termType) {\n // Fast path to order two IRIs or two blank nodes by their value.\n if (termA.termType === 'NamedNode' || termA.termType === 'BlankNode') {\n if (termA.value === termB.value) {\n return 0;\n }\n return termA.value < termB.value ? -1 : 1;\n }\n } else {\n // Fast path to order terms of differing types.\n const priorityA = EVALUATOR_TERM_TYPES[termA.termType];\n const priorityB = EVALUATOR_TERM_TYPES[termB.termType];\n if (priorityA !== undefined && priorityB !== undefined) {\n return TermFunctionLesserThan.TERM_ORDERING_PRIORITY[priorityA] <\n TermFunctionLesserThan.TERM_ORDERING_PRIORITY[priorityB] ?\n -1 :\n 1;\n }\n }\n\n return this.orderTypesGeneral(termA, termB);\n }\n\n /**\n * Order two defined terms by evaluating the SPARQL `<` operator in both directions.\n * @param termA the first term\n * @param termB the second term\n */\n private orderTypesGeneral(termA: RDF.Term, termB: RDF.Term): -1 | 0 | 1 {\n const myTermA: Eval.Term = this.internalEvaluator.transformer.transformRDFTermUnsafe(termA);\n const myTermB: Eval.Term = this.internalEvaluator.transformer.transformRDFTermUnsafe(termB);\n\n if ((<Eval.BooleanLiteral> this.lessThanFunction.applyOnTerms([ myTermA, myTermB ], this.internalEvaluator))\n .typedValue) {\n return -1;\n }\n if ((<Eval.BooleanLiteral> this.lessThanFunction.applyOnTerms([ myTermB, myTermA ], this.internalEvaluator))\n .typedValue) {\n return 1;\n }\n return 0;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@comunica/actor-term-comparator-factory-expression-evaluator",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"description": "A expression-evaluator term-comparator-factory actor",
|
|
5
5
|
"lsd:module": true,
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,14 +37,15 @@
|
|
|
37
37
|
"build:components": "componentsjs-generator"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@comunica/actor-expression-evaluator-factory-default": "^5.
|
|
41
|
-
"@comunica/
|
|
42
|
-
"@comunica/bus-
|
|
43
|
-
"@comunica/
|
|
44
|
-
"@comunica/
|
|
45
|
-
"@comunica/
|
|
46
|
-
"@comunica/utils-
|
|
40
|
+
"@comunica/actor-expression-evaluator-factory-default": "^5.5.0",
|
|
41
|
+
"@comunica/actor-function-factory-term-lesser-than": "^5.5.0",
|
|
42
|
+
"@comunica/bus-function-factory": "^5.5.0",
|
|
43
|
+
"@comunica/bus-term-comparator-factory": "^5.5.0",
|
|
44
|
+
"@comunica/context-entries": "^5.5.0",
|
|
45
|
+
"@comunica/core": "^5.5.0",
|
|
46
|
+
"@comunica/utils-bindings-factory": "^5.5.0",
|
|
47
|
+
"@comunica/utils-expression-evaluator": "^5.5.0",
|
|
47
48
|
"@rdfjs/types": "*"
|
|
48
49
|
},
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "3a258e018a9c5f0b03f531b30ee1cdc659b5b7c9"
|
|
50
51
|
}
|