Skip to content

Commit

Permalink
Updated N3.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Miel Vander Sande committed Jun 14, 2018
1 parent df0755d commit e701af4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
12 changes: 5 additions & 7 deletions TurtleValidator.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/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. */

var N3 = require('n3'),
fs = require('fs'),
N3Util = N3.Util,
var fs = require('fs'),
http = require('http');
url = require('url'),
fs = require('fs'),
Expand All @@ -14,7 +12,7 @@ var N3 = require('n3'),
var help = function () {
// 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('© 2014 - MMLab - Ghent University - iMinds');
console.log('© 2014 - IDLab - Ghent University - imec');
console.log('Source code: https://github.com/MMLab/TurtleValidator');
console.log('');
console.log('Examples:');
Expand Down Expand Up @@ -60,10 +58,10 @@ function validateArgument(arg) {
// Use stdio as an input stream
function showValidation(feedback) {
feedback.errors.forEach(function (error) {
console.log(error);
console.log('ERROR: ' + error);
});
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.");
}
17 changes: 8 additions & 9 deletions lib/validator.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var N3 = require('n3'),
N3Util = N3.Util;
var N3 = require('n3');

var validate = function (turtleStream, callback) {
var parser = N3.Parser();
var parser = N3.Parser({ format: 'text/turtle' });
var errorCount = 0, warningCount = 0;
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])?$/,
Expand All @@ -12,20 +11,20 @@ var validate = function (turtleStream, callback) {
};

var feedback = { warnings : [], errors : []};

parser.parse(turtleStream, function(error, triple, prefixes) {
if (error) {
feedback.errors.push(error);
feedback.errors.push(error.message);
}

if (triple) {
if (N3Util.isLiteral(triple.object)) {
var value = N3Util.getLiteralValue(triple.object);
var type = N3Util.getLiteralType(triple.object);
if (triple.object.termType === 'literal') {
var value = triple.object.value;
var type = triple.object.datatype;

type = type.replace('http://www.w3.org/2001/XMLSchema#', '');
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 {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"name": "turtle-validator",
"version": "1.0.2",
"version": "1.1.0",
"description": "This command line tool validates Turtle documents and does XSD datatype checks",
"main": "lib/validator.js",
"bin": {
"ttl": "./TurtleValidator.js"
},
"dependencies": {
"n3": "0.11.3"
"n3": "1.0.0-beta.1"
},
"devDependencies": {},
"engines": {
"node": ">=4.0"
},
"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"
},
"repository": {
Expand Down

0 comments on commit e701af4

Please sign in to comment.