Skip to content

Commit adc823d

Browse files
committed
Polish shacled turtle README and package
1 parent 524a12c commit adc823d

File tree

6 files changed

+68
-33
lines changed

6 files changed

+68
-33
lines changed

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shacled-turtle/README.md

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
# Shacled Turtle
1+
# Shacled Turtle 🐢
22

33
A [Code Mirror 6](https://codemirror.net/6/) Turtle language support that
4-
provides autocompletion based of the content of an RDFS/SHACL graph.
4+
provides autocompletion based on the content of a schema graph. Schemas can be
5+
written by using either RDFS, SHACL or a mix of both (= your usual ontology
6+
and validation RDF graphs).
57

68
## How to use
79

810
You can use this extension like any other Code Mirror 6 extension.
911

12+
For example, by using parcel:
13+
14+
- Start a new project: `npm init`
15+
- Install the dependencies: `npm install @codemirror/basic-setup @codemirror/state @codemirror/view shacled-turtle n3`
16+
- Install parcel and n3 types `npm install --save-dev parcel @types/n3`
17+
18+
- Make a file named `index.ts` with the following content:
1019
```typescript
1120
import { basicSetup } from "@codemirror/basic-setup";
1221
import { EditorState } from "@codemirror/state";
@@ -23,6 +32,7 @@ const prefixes =
2332
@prefix ex: <http://example.com/ns#> .
2433
@prefix s: <http://schema.org/> .`;
2534

35+
// Build a CodeMirror editor with the Shacled Turtle extension
2636
const editor = new EditorView({
2737
parent: document.getElementById("editorparent")!,
2838
state: EditorState.create({
@@ -31,32 +41,40 @@ const editor = new EditorView({
3141
})
3242
});
3343

44+
// Write the corresponding schema with SHACL
3445
const shapeGraph = prefixes + `
3546
ex:PersonShape a sh:NodeShape ;
3647
sh:targetClass s:Person ;
3748
sh:property [ sh:path s:name ] .
3849
`;
3950

51+
// Tell the editor that the schema used to provide autocompletion is
52+
// the schema graph described in variable shapeGraph.
4053
changeSchema(editor.state, new n3.Parser().parse(shapeGraph));
4154
```
4255

43-
On the code editor, copy the prefixes
44-
```
45-
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
46-
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
47-
prefix sh: <http://www.w3.org/ns/shacl#>
48-
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
49-
prefix owl: <http://www.w3.org/2002/07/owl#>
50-
prefix ex: <http://example.com/ns#>
51-
prefix s: <http://schema.org/>
56+
- Make a file named `index.html` with the following content
57+
```html
58+
<html>
59+
<body>
60+
<h1>Shacled Turtle Basic example</h1>
61+
<div id="editorparent"></div>
62+
<script src="index.ts" type="module"></script>
63+
</body>
64+
</html>
5265
```
5366

54-
Now, type `ex:Alice r`, the editor suggests `rdf:type` then `s:Person`.
67+
- Run `npx parcel ./index.html -p 8080`
68+
69+
- Open on your favorite broswer http://localhost:8080
70+
71+
On the code editor, type `ex:Alice r`, the editor suggests `rdf:type` then
72+
`s:Person`.
5573

5674
After `ex:Alice rdf:type s:Person . `, write `ex:alice s` and the engine
5775
will suggest `s:name` because it knows Alice is a person.
5876

5977

6078
## License
6179

62-
Published under either the CeCCIL-B license or the MIT License by Julian Bruyat / INSA Lyon.
80+
Published under either the CeCCIL-B license or the MIT License by INSA Lyon / Julian Bruyat.

shacled-turtle/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@rdfjs/term-set": "^1.1.0",
4747
"@types/rdfjs__term-map": "^1.0.2",
4848
"@types/rdfjs__term-set": "^1.0.3",
49+
"axios": "^0.26.1",
4950
"mnemonist": "^0.39.0",
5051
"n3": "^1.14.0",
5152
"rdf-string": "^1.6.0"

shacled-turtle/src/autocompletion-solving.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { CompletionContext, CompletionResult } from "@codemirror/autocomplete";
22
import { syntaxTree } from "@codemirror/language";
33
import { SyntaxNode, TreeCursor } from "@lezer/common";
44
import rdfNamespace from '@rdfjs/namespace';
5-
import { ns } from "./namespaces";
65
import DebugInformation from "./DebugInformation";
76
import { tripleAutocompletion } from "./triples-autocompletion";
87
import { ShacledTurtleOptions } from "..";
@@ -48,7 +47,7 @@ export default function autocompletionSolve(options: ShacledTurtleOptions) {
4847
let retval: CompletionResult | null = null;
4948
if (typeOfStatement === TypeOfStatement.Directive) {
5049
situation.autoCompletionType = 'directive';
51-
retval = directiveAutocompletion(context, cursor.node, theNode, prefixes);
50+
retval = directiveAutocompletion(context, cursor.node, prefixes);
5251
} else if (typeOfStatement === TypeOfStatement.Triple) {
5352
situation.autoCompletionType = 'triples';
5453
retval = tripleAutocompletion(context, tree, theNode, situation);
@@ -73,7 +72,7 @@ export default function autocompletionSolve(options: ShacledTurtleOptions) {
7372
*/
7473
function directiveAutocompletion(
7574
context: CompletionContext, directiveSyntaxNode: SyntaxNode,
76-
currentlyFilledNode: SyntaxNode, prefixes: ExistingPrefixes
75+
prefixes: ExistingPrefixes
7776
): CompletionResult | null {
7877
const firstChild = directiveSyntaxNode.firstChild;
7978
if (firstChild === null) return null;

shacled-turtle/test/index.test.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

shacled-turtle/tsconfig.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
1212

1313
/* Language and Environment */
14-
"target": "es2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
14+
"target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1515
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
1717
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
@@ -42,7 +42,7 @@
4242
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
4343

4444
/* Emit */
45-
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
45+
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
4646
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
4747
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
4848
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
@@ -75,21 +75,21 @@
7575

7676
/* Type Checking */
7777
"strict": true, /* Enable all strict type-checking options. */
78-
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
79-
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
80-
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
81-
// "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
82-
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
83-
// "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
78+
"noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
79+
"strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
80+
"strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
81+
"strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
82+
"strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
83+
"noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
8484
// "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
85-
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
86-
// "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
87-
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
85+
"alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
86+
"noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
87+
"noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
8888
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
89-
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
90-
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
89+
"noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
90+
"noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
9191
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
92-
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
92+
"noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
9393
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
9494
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
9595
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */

0 commit comments

Comments
 (0)