Updated N3.js
This commit is contained in:
parent
df0755da80
commit
e701af4433
|
@ -1,11 +1,9 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/*! @license ©2014 Miel Vander Sande - Multimedia Lab / iMinds / Ghent University */
|
/*! @license ©2014 Miel Vander Sande - IDLab / imec / Ghent University */
|
||||||
/* Command-line utility to validate Turtle files. */
|
/* Command-line utility to validate Turtle files. */
|
||||||
|
|
||||||
var N3 = require('n3'),
|
var fs = require('fs'),
|
||||||
fs = require('fs'),
|
|
||||||
N3Util = N3.Util,
|
|
||||||
http = require('http');
|
http = require('http');
|
||||||
url = require('url'),
|
url = require('url'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
|
@ -14,7 +12,7 @@ var N3 = require('n3'),
|
||||||
var help = function () {
|
var help = function () {
|
||||||
// In all other cases, let's help the user and return some help
|
// In all other cases, let's help the user and return some help
|
||||||
console.log('RDF NTriples/Turtle validator using Ruben Verborgh\'s N3 nodejs library');
|
console.log('RDF NTriples/Turtle validator using Ruben Verborgh\'s N3 nodejs library');
|
||||||
console.log('© 2014 - MMLab - Ghent University - iMinds');
|
console.log('© 2014 - IDLab - Ghent University - imec');
|
||||||
console.log('Source code: https://github.com/MMLab/TurtleValidator');
|
console.log('Source code: https://github.com/MMLab/TurtleValidator');
|
||||||
console.log('');
|
console.log('');
|
||||||
console.log('Examples:');
|
console.log('Examples:');
|
||||||
|
@ -60,10 +58,10 @@ function validateArgument(arg) {
|
||||||
// Use stdio as an input stream
|
// Use stdio as an input stream
|
||||||
function showValidation(feedback) {
|
function showValidation(feedback) {
|
||||||
feedback.errors.forEach(function (error) {
|
feedback.errors.forEach(function (error) {
|
||||||
console.log(error);
|
console.log('ERROR: ' + error);
|
||||||
});
|
});
|
||||||
feedback.warnings.forEach(function (warning) {
|
feedback.warnings.forEach(function (warning) {
|
||||||
console.log(warning);
|
console.log('WARNING: ' + warning);
|
||||||
});
|
});
|
||||||
console.log("Validator finished with " + feedback.warnings.length + " warnings and " + feedback.errors.length + " errors.");
|
console.log("Validator finished with " + feedback.warnings.length + " warnings and " + feedback.errors.length + " errors.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
var N3 = require('n3'),
|
var N3 = require('n3');
|
||||||
N3Util = N3.Util;
|
|
||||||
|
|
||||||
var validate = function (turtleStream, callback) {
|
var validate = function (turtleStream, callback) {
|
||||||
var parser = N3.Parser();
|
var parser = N3.Parser({ format: 'text/turtle' });
|
||||||
var errorCount = 0, warningCount = 0;
|
var errorCount = 0, warningCount = 0;
|
||||||
var regexp = {
|
var regexp = {
|
||||||
'dateTime' : /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])?T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)??(Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?$/,
|
'dateTime' : /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])?T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)??(Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?$/,
|
||||||
|
@ -12,20 +11,20 @@ var validate = function (turtleStream, callback) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var feedback = { warnings : [], errors : []};
|
var feedback = { warnings : [], errors : []};
|
||||||
|
|
||||||
parser.parse(turtleStream, function(error, triple, prefixes) {
|
parser.parse(turtleStream, function(error, triple, prefixes) {
|
||||||
if (error) {
|
if (error) {
|
||||||
feedback.errors.push(error);
|
feedback.errors.push(error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (triple) {
|
if (triple) {
|
||||||
if (N3Util.isLiteral(triple.object)) {
|
if (triple.object.termType === 'literal') {
|
||||||
var value = N3Util.getLiteralValue(triple.object);
|
var value = triple.object.value;
|
||||||
var type = N3Util.getLiteralType(triple.object);
|
var type = triple.object.datatype;
|
||||||
|
|
||||||
type = type.replace('http://www.w3.org/2001/XMLSchema#', '');
|
type = type.replace('http://www.w3.org/2001/XMLSchema#', '');
|
||||||
if (regexp[type] && !regexp[type].test(value)) {
|
if (regexp[type] && !regexp[type].test(value)) {
|
||||||
feedback.warnings.push('WARNING: xsd:', type, 'does not validate for literal. {', triple.subject, triple.predicate, triple.object, '}');
|
feedback.warnings.push('xsd:', type, 'does not validate for literal. {', triple.subject.value, triple.predicate.value, triple.object.value, '}');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
{
|
{
|
||||||
"name": "turtle-validator",
|
"name": "turtle-validator",
|
||||||
"version": "1.0.1",
|
"version": "1.1.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"n3": {
|
"n3": {
|
||||||
"version": "0.11.2",
|
"version": "1.0.0-beta.1",
|
||||||
"resolved": "https://registry.npmjs.org/n3/-/n3-0.11.2.tgz",
|
"resolved": "https://registry.npmjs.org/n3/-/n3-1.0.0-beta.1.tgz",
|
||||||
"integrity": "sha512-ICSiOmFLbZ4gI35+4H3e2vYGHDC944WZkCa1iVNRAx/mRZESEevQNFhfHaui/lhqynoZYvBVDNjM/2Tfd3TICQ=="
|
"integrity": "sha512-A9SAvNIkqxNEsZBjxnEwL7pacqGR4zbE25MfXkdZiroqo/2wnsiqx1eQFDsbQXgyxcDtwATaaMf+VT2I474uWA=="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
{
|
{
|
||||||
"name": "turtle-validator",
|
"name": "turtle-validator",
|
||||||
"version": "1.0.2",
|
"version": "1.1.0",
|
||||||
"description": "This command line tool validates Turtle documents and does XSD datatype checks",
|
"description": "This command line tool validates Turtle documents and does XSD datatype checks",
|
||||||
"main": "lib/validator.js",
|
"main": "lib/validator.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"ttl": "./TurtleValidator.js"
|
"ttl": "./TurtleValidator.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"n3": "0.11.3"
|
"n3": "1.0.0-beta.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.0"
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "browserify lib/validator.js -o public/js/ttl.js",
|
"build": "browserify lib/validator.js -o public/js/ttl.js",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
Loading…
Reference in New Issue