Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
Remove old utility directory
Browse files Browse the repository at this point in the history
  • Loading branch information
wschella committed May 20, 2019
1 parent effe9eb commit 869ad98
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 118 deletions.
16 changes: 0 additions & 16 deletions test/misc/Errors.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion test/misc/Exists.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as RDFDM from '@rdfjs/data-model';
import { evaluate } from '../../util/Util';
import { evaluate } from '../util/utils';

describe.skip('exists', () => {
it('runs with mock existence hooks', () => {
Expand Down
7 changes: 0 additions & 7 deletions test/misc/nonlexicals.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions test/util/TruthTable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as RDF from 'rdf-js';

import { stringToTerm, termToString } from 'rdf-string';
import { evaluate } from '../../util/Util';
import { termToString } from 'rdf-string';
import { evaluate } from '../util/utils';

/*
* Maps short strings to longer RDF term-literals for easy use in making
Expand Down
24 changes: 21 additions & 3 deletions test/util/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { literal } from '@rdfjs/data-model';
import * as RDF from 'rdf-js';

import { literal } from '@rdfjs/data-model';
import { stringToTerm, termToString } from 'rdf-string';
import { translate } from 'sparqlalgebrajs';

import { AsyncEvaluator, AsyncEvaluatorConfig } from '../../lib/evaluators/AsyncEvaluator';
import { Bindings } from '../../lib/Types';
import { ExpressionError } from '../../lib/util/Errors';
import { parse } from '../../util/Util';

export function testAll(exprs: string[], config?: AsyncEvaluatorConfig) {
exprs.forEach((_expr) => {
Expand Down Expand Up @@ -38,8 +39,25 @@ export function testAllErrors(exprs: string[], config?: AsyncEvaluatorConfig) {
});
}

function template(expr: string) {
return `
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX fn: <https://www.w3.org/TR/xpath-functions#>
PREFIX err: <http://www.w3.org/2005/xqt-errors#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT * WHERE { ?s ?p ?o FILTER (${expr})}
`;
}

function parse(query: string) {
const sparqlQuery = translate(query);
// Extract filter expression from complete query
return sparqlQuery.input.expression;
}

export function evaluate(expr: string, config?: AsyncEvaluatorConfig): Promise<RDF.Term> {
const evaluator = new AsyncEvaluator(parse(expr), config);
const evaluator = new AsyncEvaluator(parse(template(expr)), config);
return evaluator.evaluate(Bindings({}));
}

Expand Down
89 changes: 0 additions & 89 deletions util/Util.ts

This file was deleted.

0 comments on commit 869ad98

Please sign in to comment.