Skip to content

Commit

Permalink
Update algebra to match PATHS JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
balhoff committed Sep 18, 2024
1 parent 62fa9d9 commit 277590d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/algebra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export interface Paths extends BaseOperation {

export interface PathEndpoint {
variable: VariableTerm;
input?: IriTerm | P[];
input?: { type: 'NamedNode', value: IriTerm } | { type: 'Pattern', value: Operation };
}

export type PathVia =
Expand Down
4 changes: 2 additions & 2 deletions lib/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export default class Factory
}
createPaths(
startVar: VariableTerm,
startValue: IriTerm | Pattern[] | undefined,
startValue: { type: 'NamedNode', value: IriTerm } | { type: 'Pattern', value: A.Operation } | undefined,
endVar: VariableTerm,
endValue: IriTerm | Pattern[] | undefined,
endValue: { type: 'NamedNode', value: IriTerm } | { type: 'Pattern', value: A.Operation } | undefined,
via: A.PathVia,
shortest: boolean,
cyclic: boolean,
Expand Down
29 changes: 26 additions & 3 deletions lib/sparql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import {
Wildcard,
AskQuery,
DescribeQuery,
PathVia
PathVia,
PathEndpoint
} from 'sparqljs';

Check failure on line 39 in lib/sparql.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18.x)

Could not find a declaration file for module 'sparqljs'. '/home/runner/work/SPARQLAlgebra.js/SPARQLAlgebra.js/node_modules/sparqljs/sparql.js' implicitly has an 'any' type.

Check failure on line 39 in lib/sparql.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 16.x)

Could not find a declaration file for module 'sparqljs'. '/home/runner/work/SPARQLAlgebra.js/SPARQLAlgebra.js/node_modules/sparqljs/sparql.js' implicitly has an 'any' type.

Check failure on line 39 in lib/sparql.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20.x)

Could not find a declaration file for module 'sparqljs'. '/home/runner/work/SPARQLAlgebra.js/SPARQLAlgebra.js/node_modules/sparqljs/sparql.js' implicitly has an 'any' type.

Check failure on line 39 in lib/sparql.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18.x)

Could not find a declaration file for module 'sparqljs'. '/home/runner/work/SPARQLAlgebra.js/SPARQLAlgebra.js/node_modules/sparqljs/sparql.js' implicitly has an 'any' type.

Check failure on line 39 in lib/sparql.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20.x)

Could not find a declaration file for module 'sparqljs'. '/home/runner/work/SPARQLAlgebra.js/SPARQLAlgebra.js/node_modules/sparqljs/sparql.js' implicitly has an 'any' type.

Check failure on line 39 in lib/sparql.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 12.x)

Could not find a declaration file for module 'sparqljs'. '/home/runner/work/SPARQLAlgebra.js/SPARQLAlgebra.js/node_modules/sparqljs/sparql.js' implicitly has an 'any' type.

Check failure on line 39 in lib/sparql.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 14.x)

Could not find a declaration file for module 'sparqljs'. '/home/runner/work/SPARQLAlgebra.js/SPARQLAlgebra.js/node_modules/sparqljs/sparql.js' implicitly has an 'any' type.

Check failure on line 39 in lib/sparql.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 12.x)

Could not find a declaration file for module 'sparqljs'. '/home/runner/work/SPARQLAlgebra.js/SPARQLAlgebra.js/node_modules/sparqljs/sparql.js' implicitly has an 'any' type.

Check failure on line 39 in lib/sparql.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 14.x)

Could not find a declaration file for module 'sparqljs'. '/home/runner/work/SPARQLAlgebra.js/SPARQLAlgebra.js/node_modules/sparqljs/sparql.js' implicitly has an 'any' type.

Check failure on line 39 in lib/sparql.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 16.x)

Could not find a declaration file for module 'sparqljs'. '/home/runner/work/SPARQLAlgebra.js/SPARQLAlgebra.js/node_modules/sparqljs/sparql.js' implicitly has an 'any' type.
import * as Algebra from './algebra';
import Factory from './factory';
Expand Down Expand Up @@ -127,12 +128,34 @@ function translatePaths(op: Algebra.Paths): PathsQuery {
} else {
via = translateOperation(op.via.value);
}
let startInput: { type: 'NamedNode', value: IriTerm } | { type: 'Pattern', value: GroupPattern } | undefined = undefined;
if (op.start.input) {
if (op.start.input.type === 'NamedNode') {
startInput = { 'type': 'NamedNode', value: op.start.input.value };
} else {
startInput = { 'type': 'Pattern', value: translateOperation(op.start.input.value) };
}
}
let endInput: { type: 'NamedNode', value: IriTerm } | { type: 'Pattern', value: GroupPattern } | undefined = undefined;
if (op.end.input) {
if (op.end.input.type === 'NamedNode') {
endInput = { 'type': 'NamedNode', value: op.end.input.value };
} else {
endInput = { 'type': 'Pattern', value: translateOperation(op.end.input.value) };
}
}
return {
type: 'query',
queryType: 'PATHS',
prefixes: {},
start: op.start,
end: op.end,
start: {
variable: op.start.variable,
input: startInput
},
end: {
variable: op.end.variable,
input: endInput
},
via: via,
shortest: op.shortest,
cyclic: op.cyclic,
Expand Down
20 changes: 18 additions & 2 deletions lib/sparqlAlgebra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,27 @@ function translatePathsQuery(sparql: PathsQuery): Algebra.Paths
} else {
via = { type: 'Pattern', value: translateGraphPattern(sparql.via.value) };
}
let startInput: { type: 'NamedNode', value: IriTerm } | { type: 'Pattern', value: Algebra.Operation } | undefined;
if (sparql.start.input?.type === 'NamedNode') {
startInput = sparql.start.input;
} else if (sparql.start.input?.type === 'Pattern') {
startInput = { type: 'Pattern', value: translateGraphPattern(sparql.start.input.value) };
} else {
startInput = undefined;
}
let endInput: { type: 'NamedNode', value: IriTerm } | { type: 'Pattern', value: Algebra.Operation } | undefined;
if (sparql.end.input?.type === 'NamedNode') {
endInput = sparql.end.input;
} else if (sparql.end.input?.type === 'Pattern') {
endInput = { type: 'Pattern', value: translateGraphPattern(sparql.end.input.value) };
} else {
endInput = undefined;
}
return factory.createPaths(
sparql.start.variable,
sparql.start.input,
startInput,
sparql.end.variable,
sparql.end.input,
endInput,
via,
sparql.shortest,
sparql.cyclic,
Expand Down

0 comments on commit 277590d

Please sign in to comment.