This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
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.
- Loading branch information
1 parent
4047971
commit 871107d
Showing
5 changed files
with
103 additions
and
0 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,13 @@ | ||
# CKG CLI | ||
|
||
## Setup | ||
|
||
```sh | ||
npm install | ||
``` | ||
|
||
## Run | ||
|
||
```sh | ||
npm start run-query-on-profile solar-funding user-a | ||
``` |
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,46 @@ | ||
const fs = require("fs") | ||
const path = require("path") | ||
|
||
async function importDependencies() { | ||
const [{ default: rdfExt }, { default: ParserN3 }, { default: SHACLValidator }] = await Promise.all([ | ||
import("rdf-ext"), | ||
import("@rdfjs/parser-n3"), | ||
import("rdf-validate-shacl") | ||
]) | ||
return { factory: rdfExt, ParserN3, SHACLValidator } | ||
} | ||
|
||
const profilesDir = path.join(__dirname, "profiles") | ||
const queriesDir = path.join(__dirname, "queries") | ||
|
||
async function loadDataset(filePath) { | ||
const { factory, ParserN3 } = await importDependencies() | ||
const stream = fs.createReadStream(filePath) | ||
const parser = new ParserN3() | ||
return factory.dataset().import(parser.import(stream)) | ||
} | ||
|
||
async function runQueryOnProfile(queryName, profileName) { | ||
const { factory, SHACLValidator } = await importDependencies() | ||
const shapes = await loadDataset(path.join(queriesDir, `${queryName}.ttl`)) | ||
const data = await loadDataset(path.join(profilesDir, `${profileName}.ttl`)) | ||
|
||
const validator = new SHACLValidator(shapes, { factory }) | ||
const report = await validator.validate(data) | ||
|
||
// get report details: https://github.com/zazuko/rdf-validate-shacl#usage | ||
|
||
console.log("--> " + profileName + " is" + (report.conforms ? " " : " not ") + "eligible for " + queryName) | ||
} | ||
|
||
const commands = { | ||
"run-query-on-profile": runQueryOnProfile, | ||
} | ||
|
||
const [, , command, ...args] = process.argv | ||
|
||
if (commands[command]) { | ||
commands[command](...args) | ||
} else { | ||
console.error("Unknown command:", command) | ||
} |
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 @@ | ||
{ | ||
"name": "ckg-cli", | ||
"version": "0.0.1", | ||
"bin": { | ||
"ckg": "./ckg.js" | ||
}, | ||
"scripts": { | ||
"start": "node ckg.js" | ||
}, | ||
"main": "ckg.js", | ||
"dependencies": { | ||
"@rdfjs/parser-n3": "^2.0.1", | ||
"rdf-ext": "^2.4.0", | ||
"rdf-validate-shacl": "^0.5.1" | ||
} | ||
} |
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,7 @@ | ||
@prefix ckg: <http://ckg.de/default#> . | ||
|
||
ckg:House1 a ckg:House; | ||
ckg:roofArea 110; | ||
ckg:houseAge 35 . | ||
|
||
ckg:mainPerson ckg:owns ckg:House1 . |
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,21 @@ | ||
@prefix ckg: <http://ckg.de/default#> . | ||
@prefix sh: <http://www.w3.org/ns/shacl#> . | ||
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . | ||
|
||
ckg:metadata ckg:author ckg:benjaminaaron . | ||
|
||
ckg:RoofAreaPropertyShape a sh:PropertyShape ; | ||
sh:path ckg:roofArea ; | ||
sh:datatype xsd:integer ; | ||
sh:minInclusive 100 ; | ||
sh:message "Roof area is below the minimum required" . | ||
|
||
ckg:HouseAgePropertyShape a sh:PropertyShape ; | ||
sh:path ckg:houseAge ; | ||
sh:datatype xsd:integer ; | ||
sh:minInclusive 30 ; | ||
sh:message "House age is below the minimum required" . | ||
|
||
ckg:EligibleHouseShape a sh:NodeShape ; | ||
sh:targetClass ckg:House ; | ||
sh:property ckg:RoofAreaPropertyShape, ckg:HouseAgePropertyShape . |