-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* can generate sparql query * parses constructs * generate each queryUnit * sparqlRule all rules * implement generatorBuilder * working basic generator * generation seperated by newlines * fix readme
- Loading branch information
1 parent
693f315
commit b062a6d
Showing
67 changed files
with
1,583 additions
and
454 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# TRAQULA SPARQL 1.1 generator | ||
|
||
TRAQULA Generator Sparql 1.1 is a [SPARQL 1.1](https://www.w3.org/TR/sparql11-query/#grammar) query generator for TypeScript. | ||
It can generate SPARQL given the AST created by [TRAQULA parser SPARQL 1-1](https://github.com/comunica/traqula/tree/main/engines/parser-sparql-1-1). | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install @traqula/generator-sparql-1-1 | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
yarn add @traqula/generator-sparql-1-1 | ||
``` | ||
|
||
## Import | ||
|
||
Either through ESM import: | ||
|
||
```javascript | ||
import {Parser} from 'engines/generator-sparql-1-1'; | ||
``` | ||
|
||
_or_ CJS require: | ||
|
||
```javascript | ||
const Parser = require('engines/generator-sparql-1-1').Parser; | ||
``` | ||
|
||
## Usage | ||
|
||
This package contains a `Generator` that is able to generate SPARQL 1.1 queries: | ||
|
||
```typescript | ||
const generator = new Generator(); | ||
const abstractSyntaxTree = generator.generate(abstractSyntaxTree); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { GeneratorBuilder } from '@traqula/core'; | ||
import { gram } from '@traqula/rules-sparql-1-1'; | ||
import type * as T11 from '@traqula/rules-sparql-1-1'; | ||
|
||
const sparql11GeneratorBuilder = GeneratorBuilder.createBuilder(<const> [ | ||
gram.query, | ||
gram.selectQuery, | ||
gram.constructQuery, | ||
gram.describeQuery, | ||
gram.askQuery, | ||
gram.valuesClause, | ||
gram.selectClause, | ||
gram.constructTemplate, | ||
]) | ||
.addMany( | ||
gram.update, | ||
gram.update1, | ||
gram.load, | ||
gram.clear, | ||
gram.drop, | ||
gram.create, | ||
gram.copy, | ||
gram.move, | ||
gram.add, | ||
gram.insertData, | ||
gram.deleteData, | ||
gram.deleteWhere, | ||
gram.modify, | ||
gram.graphOrDefault, | ||
gram.graphRef, | ||
gram.graphRefAll, | ||
gram.quadData, | ||
gram.quads, | ||
gram.quadsNotTriples, | ||
) | ||
.addRule(gram.aggregate) | ||
.addRule(gram.datasetClause) | ||
.addMany( | ||
gram.argList, | ||
gram.expression, | ||
gram.iriOrFunction, | ||
) | ||
.addMany( | ||
gram.prologue, | ||
gram.varOrTerm, | ||
gram.var_, | ||
gram.graphTerm, | ||
) | ||
.addMany( | ||
gram.rdfLiteral, | ||
gram.string, | ||
gram.iri, | ||
gram.blankNode, | ||
) | ||
.addRule(gram.path) | ||
.addMany( | ||
gram.solutionModifier, | ||
gram.groupClause, | ||
gram.groupCondition, | ||
gram.havingClause, | ||
gram.orderClause, | ||
gram.orderCondition, | ||
gram.limitOffsetClauses, | ||
) | ||
.addRule(gram.triplesBlock) | ||
.addMany( | ||
gram.groupGraphPattern, | ||
gram.graphPatternNotTriples, | ||
gram.optionalGraphPattern, | ||
gram.graphGraphPattern, | ||
gram.serviceGraphPattern, | ||
gram.bind, | ||
gram.inlineDataFull, | ||
gram.dataBlockValue, | ||
gram.minusGraphPattern, | ||
gram.groupOrUnionGraphPattern, | ||
gram.filter, | ||
); | ||
|
||
export class Generator { | ||
private readonly generator = sparql11GeneratorBuilder.build(); | ||
|
||
public generate(ast: T11.Query): string { | ||
return this.generator.query(ast, undefined, undefined); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"name": "@traqula/generator-sparql-1-1", | ||
"type": "module", | ||
"version": "0.0.0", | ||
"description": "SPARQL 1.1 generator", | ||
"lsd:module": true, | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/comunica/traqula.git", | ||
"directory": "engines/generator-sparql-1-1" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/comunica/traqula/issues" | ||
}, | ||
"sideEffects": false, | ||
"exports": { | ||
"import": "./lib/index.js", | ||
"require": "./lib/index.cjs" | ||
}, | ||
"main": "lib/index.js", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"files": [ | ||
"lib/**/*.cjs", | ||
"lib/**/*.d.ts", | ||
"lib/**/*.js", | ||
"lib/**/*.js.map" | ||
], | ||
"engines": { | ||
"node": ">=18.0" | ||
}, | ||
"typings": "lib/index", | ||
"scripts": { | ||
"build": "yarn build:ts && yarn build:transpile", | ||
"build:ts": "node \"../../node_modules/typescript/bin/tsc\"", | ||
"build:transpile": " node \"../../node_modules/esbuild/bin/esbuild\" --format=cjs --bundle --log-level=error --outfile=lib/index.cjs lib/index.ts" | ||
}, | ||
"dependencies": { | ||
"@traqula/core": "^0.0.0", | ||
"@traqula/rules-sparql-1-1": "^0.0.0" | ||
}, | ||
"devDependencies": { | ||
"@traqula/parser-sparql-1-1": "^0.0.0", | ||
"@traqula/rules-sparql-1-1": "^0.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Parser } from '@traqula/parser-sparql-1-1'; | ||
import type * as T11 from '@traqula/rules-sparql-1-1'; | ||
import { describe, it } from 'vitest'; | ||
import { Generator } from '../lib'; | ||
|
||
describe('a SPARQL 1.1 generator', () => { | ||
const generator = new Generator(); | ||
const parser = new Parser(); | ||
|
||
it ('should generate a simple query', ({ expect }) => { | ||
const query = 'SELECT * WHERE { ?s ?p ?o }'; | ||
const ast = <T11.Query> parser.parse(query); | ||
const result = generator.generate(ast); | ||
expect(result.replaceAll(/\s+/gu, ' ')).toBe(query); | ||
}); | ||
}); |
10 changes: 5 additions & 5 deletions
10
engines/engine-sparql-1-1-adjust/README.md β engines/parser-sparql-1-1-adjust/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...es/engine-sparql-1-1-adjust/lib/Parser.ts β ...es/parser-sparql-1-1-adjust/lib/Parser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.