2014-04-28 11:51:16 +02:00
|
|
|
#!/usr/bin/env node
|
|
|
|
|
2014-04-28 15:08:22 +02:00
|
|
|
var N3 = require('n3'),
|
|
|
|
fs = require('fs'),
|
|
|
|
N3Util = N3.Util,
|
|
|
|
http = require('http'),
|
2015-07-14 18:16:11 +02:00
|
|
|
fs = require('fs'),
|
|
|
|
validate = require('./lib/validator.js');
|
2014-04-18 17:11:43 +02:00
|
|
|
|
2014-04-28 15:08:22 +02:00
|
|
|
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('Source code: https://github.com/MMLab/TurtleValidator');
|
|
|
|
console.log('');
|
|
|
|
console.log('Examples:');
|
|
|
|
console.log('');
|
|
|
|
console.log(' $ ttl <path-to-file>');
|
|
|
|
console.log(' $ curl http://data.linkeddatafragments.org/dbpedia -H "accept: text/turtle" | ttl');
|
|
|
|
console.log(' $ ttl http://triples.demo.thedatatank.com/demo.ttl');
|
2014-04-22 11:53:53 +02:00
|
|
|
};
|
|
|
|
|
2014-04-28 15:08:22 +02:00
|
|
|
if (process.argv[2] && (process.argv[2] === "-h" || process.argv[2] === "--help") ) {
|
|
|
|
help();
|
|
|
|
} else if (process.argv.length === 2) {
|
|
|
|
// Use stdio as an input stream
|
2015-07-14 18:16:11 +02:00
|
|
|
validate(process.stdin, function (feedback) {
|
|
|
|
feedback.errors.forEach(function (error) {
|
|
|
|
console.log(error);
|
|
|
|
});
|
|
|
|
feedback.warnings.forEach(function (warning) {
|
|
|
|
console.log(warning);
|
|
|
|
});
|
|
|
|
console.log("Validator finished with " + feedback.warnings.length + " warnings and " + feedback.errors.length + " errors.");
|
|
|
|
});
|
2014-04-28 15:08:22 +02:00
|
|
|
} else if (process.argv.length === 3 ) {
|
|
|
|
// Create a stream from the file, whether it is a local file or a http stream
|
|
|
|
var filename = process.argv[2];
|
|
|
|
fs.exists(filename, function (exists) {
|
|
|
|
if (exists) {
|
|
|
|
try{
|
|
|
|
validateStream(fs.createReadStream(filename));
|
|
|
|
} catch ( e ) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
try{
|
|
|
|
validateStream(http.get(process.argv[2]));
|
|
|
|
} catch ( e ) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
} else {
|
|
|
|
help();
|
|
|
|
}
|
|
|
|
|
|
|
|
|