You can test consistency of RDF data wrt an ontology by combining the ontology and the data together and using a reasoner on this. There are different approaches for this: load everything into the reasoner's data structure and test for consistency from there, or use a database where you materialise inferred data and look for contradicting facts.
For instance, if you have an ontology that says:
onto:date a owl:DatatypeProperty;
rdfs:range xsd:date .
and your data has:
ex:aaa onto:date "2004"^^xsd:integer .
then the merge of the two will be inconsistent according to an OWL reasoner, or even an RDFS reasoner that supports datatypes xsd:date
and xsd:integer
. If you are using materialisation, the contradiction becomes apparent because the data entails:
ex:aaa onto:date _:bnode .
_:bnode rdf:type xsd:integer .
and the combination of this data with the ontology entails:
_:bnode rdf:type xsd:date .
We thus have a node that belongs to two incompatible datatypes, which is a direct contradiction.
If you know you are only dealing with certain kinds of inconsistencies, such as datatype inconsistencies, then using a full-fledged reasoner is not the most efficient option. Also, from your question, it is not clear whether you want to test logical consistency or some kind of integrity constraints, because the case of datatypes is special. A lot of people confuse axioms and constraints. This is why both Henriette Hamrse in her comment, and Thomas in his answer are referring to ShEx and SHACL, which would be much more appropriate for testing constraints.