forked from kxjdora/jsonld-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.0.js
70 lines (59 loc) · 2.07 KB
/
index.0.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict';
var shacler = require('./lib/shacler.js');
const utils = require('./lib/utils.js');
const express = require('express');
const path = require('path');
const bodyParser = require('body-parser');
const app = express();
const fs = require('fs');
const request = require('request');
const slnk = "https://localhost:3000/data/schema.ttl";
const dlnk = "https://localhost:3000/data/data.ttl";
const $rdf = require('rdflib');
const RDF = $rdf.Namespace('https://www.w3.org/1999/02/22-rdf-syntax-ns#')
const sh = $rdf.Namespace('https://www.w3.org/ns/shacl#');
const a = RDF('type')
app.use(express.static(path.join(__dirname, 'public')))
app.use(bodyParser.urlencoded({
extended: true
}));
//body parser
app.use(bodyParser.json());
function test_data(targetClass) {
//var kb = new $rdf.IndexedFormula();
var kb = new $rdf.graph();
request(dlnk, function (err, res, body) {
$rdf.parse(body, kb, dlnk, 'text/turtle');
kb.statementsMatching(null, a, targetClass)
.forEach(function (st) {
console.log(' Target classs member: ' + st.subject)
});
});
};
function test_schema() {
//var kb = new $rdf.IndexedFormula();
var kb = new $rdf.graph();
request(slnk, function (err, res, body) {
$rdf.parse(body, kb, slnk, 'text/turtle');
// console.log(JSON.stringify(kb));
console.log("=====Find targetClass in Schema file=======");
kb.statementsMatching(null, sh('targetClass'), null)
.forEach(function (st) {
var targetClass = st.object
var shape = st.subject
console.log(' Target class ' + targetClass + ' is Shape of ' + shape)
test_data(targetClass)
});
console.log("====================================");
});
};
//Test Shacl Validator
app.get('/t', function (req, res) {
// shacl_validate();
test_schema();
res.send("Test Shacl Validation!");
})
//Start web server
app.listen((process.env.PORT || 3000), function () {
console.log("Server up and listening");
});