Added dateTime validation and corrected double validation. Shortened code.
This commit is contained in:
parent
24c554ed6d
commit
af9abe3f2d
|
@ -8,10 +8,16 @@ if (!process.argv[2]){
|
||||||
|
|
||||||
console.log('Validating ' + process.argv[2]);
|
console.log('Validating ' + process.argv[2]);
|
||||||
|
|
||||||
var parser = N3.Parser(),
|
var parser = N3.Parser(), turtleStream = fs.createReadStream(process.argv[2]);
|
||||||
turtleStream = fs.createReadStream(process.argv[2]);
|
|
||||||
|
|
||||||
var errorCount = 0;
|
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])?$/,
|
||||||
|
'double' : /[-+]?\d*([.]\d+)?/,
|
||||||
|
'float' : /[-+]?\d*[.]\d+/,
|
||||||
|
'int' : /^[-+]?(0|[1-9]\d*)$/
|
||||||
|
};
|
||||||
|
|
||||||
parser.parse(turtleStream, function(error, triple, prefixes) {
|
parser.parse(turtleStream, function(error, triple, prefixes) {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -26,24 +32,12 @@ parser.parse(turtleStream, function (error, triple, prefixes){
|
||||||
|
|
||||||
type = type.replace('http://www.w3.org/2001/XMLSchema#', '');
|
type = type.replace('http://www.w3.org/2001/XMLSchema#', '');
|
||||||
|
|
||||||
switch(type) {
|
if (regexp[type] && !regexp[type].test(value)) {
|
||||||
case 'float':
|
console.log('WARNING: xsd:', type, 'does not validate for literal. {', triple.subject, triple.predicate, triple.object, '}');
|
||||||
case 'double':
|
warningCount++;
|
||||||
if (!(/[-+]?\d*[.]\d+/.test(value))){
|
|
||||||
console.log('WARNING: datatype does not validate for value ' + value);
|
|
||||||
console.log(triple.subject, triple.predicate, triple.object, '.');
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case 'int':
|
|
||||||
if (!(/^\+?(0|[1-9]\d*)$/.test(value))){
|
|
||||||
console.log('WARNING: int does not validate for value ' + value);
|
|
||||||
console.log(triple.subject, triple.predicate, triple.object, '.');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("Validation done: "+ errorCount + " errors found.");
|
console.log('Validation done:', errorCount, 'errors and', warningCount ,'warnings found.');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue