Skip to content

Commit

Permalink
rename internal Evaluation function
Browse files Browse the repository at this point in the history
  • Loading branch information
jitsedesmet committed Apr 28, 2024
1 parent e698dc6 commit 7d5cae3
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ export class ExpressionEvaluator implements IExpressionEvaluator {
}

public async evaluate(mapping: RDF.Bindings): Promise<RDF.Term> {
const result = await this.internalEvaluator.internalEvaluation(this.expr, mapping);
const result = await this.internalEvaluator.evaluatorExpressionEvaluation(this.expr, mapping);
return result.toRDF();
}

public async evaluateAsEBV(mapping: RDF.Bindings): Promise<boolean> {
const result = await this.internalEvaluator.internalEvaluation(this.expr, mapping);
const result = await this.internalEvaluator.evaluatorExpressionEvaluation(this.expr, mapping);
return result.coerceEBV();
}

public evaluateAsInternal(mapping: RDF.Bindings): Promise<E.Expression> {
return this.internalEvaluation(this.expr, mapping);
public evaluateAsEvaluatorExpression(mapping: RDF.Bindings): Promise<E.Expression> {
return this.evaluatorExpressionEvaluation(this.expr, mapping);
}

public internalEvaluation(expr: E.Expression, mapping: RDF.Bindings): Promise<E.Term> {
return this.internalEvaluator.internalEvaluation(expr, mapping);
public evaluatorExpressionEvaluation(expr: E.Expression, mapping: RDF.Bindings): Promise<E.Term> {
return this.internalEvaluator.evaluatorExpressionEvaluation(expr, mapping);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class InternalEvaluator {
);
}

public async internalEvaluation(expr: E.Expression, mapping: RDF.Bindings): Promise<E.Term> {
public async evaluatorExpressionEvaluation(expr: E.Expression, mapping: RDF.Bindings): Promise<E.Term> {
const evaluator = this.subEvaluators[expr.expressionType];
return evaluator.bind(this)(expr, mapping);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class NamedExtension extends BaseFunctionDefinition {
}

public apply = async({ args, exprEval, mapping }: IEvalContext): Promise<E.TermExpression> => {
const evaluatedArgs: E.Term[] = await Promise.all(args.map(arg => exprEval.internalEvaluation(arg, mapping)));
const evaluatedArgs: E.Term[] = await Promise.all(args.map(arg => exprEval.evaluatorExpressionEvaluation(arg, mapping)));

Check failure on line 23 in packages/actor-functions-wrapper-all/lib/implementation/NamedExtension.ts

View workflow job for this annotation

GitHub Actions / lint

This line has a length of 125. Maximum allowed is 120
try {
return new TermTransformer(exprEval.context.getSafe(KeysExpressionEvaluator.superTypeProvider))
.transformRDFTermUnsafe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ class IfSPARQL extends BaseFunctionDefinition {
protected arity = 3;

public apply = async({ args, mapping, exprEval }: IEvalContext): Promise<E.TermExpression> => {
const valFirst = await exprEval.internalEvaluation(args[0], mapping);
const valFirst = await exprEval.evaluatorExpressionEvaluation(args[0], mapping);
const ebv = valFirst.coerceEBV();
return ebv ?
exprEval.internalEvaluation(args[1], mapping) :
exprEval.internalEvaluation(args[2], mapping);
exprEval.evaluatorExpressionEvaluation(args[1], mapping) :
exprEval.evaluatorExpressionEvaluation(args[2], mapping);
};
}

Expand All @@ -69,7 +69,7 @@ class Coalesce extends BaseFunctionDefinition {
const errors: Error[] = [];
for (const expr of args) {
try {
return await exprEval.internalEvaluation(expr, mapping);
return await exprEval.evaluatorExpressionEvaluation(expr, mapping);
} catch (error: unknown) {
errors.push(<Error> error);
}
Expand All @@ -89,16 +89,16 @@ class LogicalOr extends BaseFunctionDefinition {
public apply = async({ args, mapping, exprEval }: IEvalContext): Promise<E.TermExpression> => {
const [ leftExpr, rightExpr ] = args;
try {
const leftTerm = await exprEval.internalEvaluation(leftExpr, mapping);
const leftTerm = await exprEval.evaluatorExpressionEvaluation(leftExpr, mapping);
const left = leftTerm.coerceEBV();
if (left) {
return bool(true);
}
const rightTerm = await exprEval.internalEvaluation(rightExpr, mapping);
const rightTerm = await exprEval.evaluatorExpressionEvaluation(rightExpr, mapping);
const right = rightTerm.coerceEBV();
return bool(right);
} catch (error: unknown) {
const rightErrorTerm = await exprEval.internalEvaluation(rightExpr, mapping);
const rightErrorTerm = await exprEval.evaluatorExpressionEvaluation(rightExpr, mapping);
const rightError = rightErrorTerm.coerceEBV();
if (!rightError) {
throw error;
Expand All @@ -120,16 +120,16 @@ class LogicalAnd extends BaseFunctionDefinition {
public apply = async({ args, mapping, exprEval }: IEvalContext): Promise<E.TermExpression> => {
const [ leftExpr, rightExpr ] = args;
try {
const leftTerm = await exprEval.internalEvaluation(leftExpr, mapping);
const leftTerm = await exprEval.evaluatorExpressionEvaluation(leftExpr, mapping);
const left = leftTerm.coerceEBV();
if (!left) {
return bool(false);
}
const rightTerm = await exprEval.internalEvaluation(rightExpr, mapping);
const rightTerm = await exprEval.evaluatorExpressionEvaluation(rightExpr, mapping);
const right = rightTerm.coerceEBV();
return bool(right);
} catch (error: unknown) {
const rightErrorTerm = await exprEval.internalEvaluation(rightExpr, mapping);
const rightErrorTerm = await exprEval.evaluatorExpressionEvaluation(rightExpr, mapping);
const rightError = rightErrorTerm.coerceEBV();
if (rightError) {
throw error;
Expand All @@ -149,7 +149,7 @@ class LogicalAnd extends BaseFunctionDefinition {
class SameTerm extends BaseFunctionDefinition {
protected arity = 2;
public apply = async({ args, mapping, exprEval }: IEvalContext): Promise<E.TermExpression> => {
const [ leftExpr, rightExpr ] = args.map(arg => exprEval.internalEvaluation(arg, mapping));
const [ leftExpr, rightExpr ] = args.map(arg => exprEval.evaluatorExpressionEvaluation(arg, mapping));
const [ left, right ] = await Promise.all([ leftExpr, rightExpr ]);
return bool(left.toRDF().equals(right.toRDF()));
};
Expand All @@ -176,7 +176,7 @@ class InSPARQL extends BaseFunctionDefinition {
public apply = async(context: IEvalContext): Promise<E.TermExpression> => {
const { args, mapping, exprEval } = context;
const [ leftExpr, ...remaining ] = args;
const left = await exprEval.internalEvaluation(leftExpr, mapping);
const left = await exprEval.evaluatorExpressionEvaluation(leftExpr, mapping);
return await this.inRecursive(left, { ...context, args: remaining }, []);
};

Expand All @@ -194,7 +194,7 @@ class InSPARQL extends BaseFunctionDefinition {
try {
// We know this will not be undefined because we check args.length === 0
const nextExpression = args.shift()!;
const next = await exprEval.internalEvaluation(nextExpression, mapping);
const next = await exprEval.evaluatorExpressionEvaluation(nextExpression, mapping);
if ((<E.BooleanLiteral> this.equalityFunction.applyOnTerms([ needle, next ], exprEval)).typedValue) {
return bool(true);
}
Expand Down Expand Up @@ -246,7 +246,7 @@ class Concat extends BaseFunctionDefinition {
public apply = async(context: IEvalContext): Promise<E.TermExpression> => {
const { args, mapping, exprEval } = context;
const pLits: Promise<E.Literal<string>>[] = args
.map(async expr => exprEval.internalEvaluation(expr, mapping))
.map(async expr => exprEval.evaluatorExpressionEvaluation(expr, mapping))
.map(async pTerm => {
const operation = concatTree.search(
[ await pTerm ],
Expand Down Expand Up @@ -300,7 +300,7 @@ class BNode extends BaseFunctionDefinition {
public apply = async(context: IEvalContext): Promise<E.TermExpression> => {
const { args, mapping, exprEval } = context;
const input = args.length === 1 ?
await exprEval.internalEvaluation(args[0], mapping) :
await exprEval.evaluatorExpressionEvaluation(args[0], mapping) :
undefined;

let strInput: string | undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/bus-functions/lib/implementation/Core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export abstract class TermSparqlFunction<O extends C.RegularOperator | C.NamedOp
}

public apply = async({ args, exprEval, mapping }: IEvalContext): Promise<E.TermExpression> => this.applyOnTerms(
await Promise.all(args.map(arg => exprEval.internalEvaluation(arg, mapping))),
await Promise.all(args.map(arg => exprEval.evaluatorExpressionEvaluation(arg, mapping))),
exprEval,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export type ArgumentType = 'term' | E.TermType | C.TypeURL | C.TypeAlias;
export type SearchStack = OverloadTree[];

export interface IInternalEvaluator {
internalEvaluation: (expr: E.Expression, mapping: RDF.Bindings) => Promise<E.Term>;
evaluatorExpressionEvaluation: (expr: E.Expression, mapping: RDF.Bindings) => Promise<E.Term>;

context: IActionContext;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/expression-evaluator/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ export interface IExpressionEvaluator extends IInternalEvaluator {
*/
evaluateAsEBV: (mapping: RDF.Bindings) => Promise<boolean>;

evaluateAsInternal: (mapping: RDF.Bindings) => Promise<E.Expression>;
evaluateAsEvaluatorExpression: (mapping: RDF.Bindings) => Promise<E.Expression>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe('evaluators', () => {
context: actionContext,
});
expect(mediate.mock.calls.length).toBe(1);
expect(await evaluator.evaluateAsInternal(BF.bindings())).toEqual(new IntegerLiteral(2));
expect(await evaluator.evaluateAsEvaluatorExpression(BF.bindings())).toEqual(new IntegerLiteral(2));
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ describe('recursive evaluators', () => {
const evaluator = getMockInternalEvaluator();

it('is able to evaluate operator', async() => {
expect(await evaluator.internalEvaluation(new E.IntegerLiteral(1), BF.bindings()))
expect(await evaluator.evaluatorExpressionEvaluation(new E.IntegerLiteral(1), BF.bindings()))
.toEqual(new E.IntegerLiteral(1));
});

it('is not able to evaluate aggregates by default', async() => {
await expect(evaluator.internalEvaluation(new E.Aggregate('count', {
await expect(evaluator.evaluatorExpressionEvaluation(new E.Aggregate('count', {
type: types.EXPRESSION,
expressionType: expressionTypes.AGGREGATE,
aggregator: 'count',
Expand Down

0 comments on commit 7d5cae3

Please sign in to comment.