/** * Run a datatype range check on all literal values of all properties with a range declaration. * @param report */ protected void performDatatypeRangeValidation(StandardValidityReport report) { HashMap<Node, List<RDFDatatype>> dtRange = getDTRange(); for ( Node prop : dtRange.keySet() ) { for ( Iterator<Triple> i = find( null, prop, null ); i.hasNext(); ) { Triple triple = i.next(); report.add( checkLiteral( prop, triple ) ); } } }
/** * Run a datatype range check on all literal values of all properties with a range declaration. * @param report */ protected void performDatatypeRangeValidation(StandardValidityReport report) { HashMap<Node, List<RDFDatatype>> dtRange = getDTRange(); for ( Node prop : dtRange.keySet() ) { for ( Iterator<Triple> i = find( null, prop, null ); i.hasNext(); ) { Triple triple = i.next(); report.add( checkLiteral( prop, triple ) ); } } }
/** * Check a given literal value for a property against the set of * known range constraints for it. * @param prop the property node whose range is under scrutiny * @param triple the statement whose object value is to be checked. * @return null if the range is legal, otherwise a ValidityReport.Report * which describes the problem. */ public ValidityReport.Report checkLiteral(Node prop, Triple triple) { Node value = triple.getObject(); List<RDFDatatype> range = getDTRange().get(prop); if (range != null) { if (value.isBlank()) return null; if (!value.isLiteral()) { return new ValidityReport.Report(true, "dtRange", "Property " + prop + " has a typed range but was given a non literal value " + value); } LiteralLabel ll = value.getLiteral(); for ( RDFDatatype dt : range ) { if ( !dt.isValidLiteral( ll ) ) { return new ValidityReport.Report( true, "dtRange", "Property " + prop + " has a typed range " + dt + "that is not compatible with " + value, triple ); } } } return null; }
/** * Check a given literal value for a property against the set of * known range constraints for it. * @param prop the property node whose range is under scrutiny * @param triple the statement whose object value is to be checked. * @return null if the range is legal, otherwise a ValidityReport.Report * which describes the problem. */ public ValidityReport.Report checkLiteral(Node prop, Triple triple) { Node value = triple.getObject(); List<RDFDatatype> range = getDTRange().get(prop); if (range != null) { if (value.isBlank()) return null; if (!value.isLiteral()) { return new ValidityReport.Report(true, "dtRange", "Property " + prop + " has a typed range but was given a non literal value " + value); } LiteralLabel ll = value.getLiteral(); for ( RDFDatatype dt : range ) { if ( !dt.isValidLiteral( ll ) ) { return new ValidityReport.Report( true, "dtRange", "Property " + prop + " has a typed range " + dt + "that is not compatible with " + value, triple ); } } } return null; }