4

I'm using the Jena framework to manipulate RDF files, but I can't find a way to validate a RDF with your respective RDFSchema. I'm trying this method bellow:

Model mod1 = new ModelMem();
Model modSchema = new ModelMem();
String baseURI = "http://iec.ch/TC57/2007/network";

String rdfPath = "file:D:\\modelo.rdf";
InputStream model = FileManager.get().open(rdfPath);

String rdfPathSchema = "file:D:\\Schema.rdf";
InputStream modelSchema = FileManager.get().open(rdfPathSchema);

mod1.read(model, baseURI, "RDF/XML-ABBREV");
modSchema.read(modelSchema,baseURI,  "RDF/XML-ABBREV");
InfModel infmodel = ModelFactory.createRDFSModel(mod1, modSchema);
ValidityReport validity = infmodel.validate();
return validity.isValid();

But it always returns true.

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
awgustavo
  • 101
  • 1
  • 6

3 Answers3

1

Are you sure it isn't always returning true simply because all the inputs you've tried are valid? Have you tried creating input that is explicitly invalid with respect to the schema and tested that?

Regardless RDF Schema is not a strict schema in the same way that XML Schema is, you may want to take a look at Jena Eyeball which is another Jena based tool for checking RDF though not sure if it will do what you want.

If you still have problems try asking on the Jena mailing list - users@jena.apache.org

Edit

Note that validation would only return false if you used something in a way that is inconsistent with the schema. Typos and other user errors that create data that you might consider invalid may still be completely consistent with respect to the RDF Schema.

For example assume you have a simple RDF schema like so:

:ValidType a rdfs:Class .

:property a rdf:Property ;
          rdfs:domain :ValidType .

So this schema states you have a single class and a property which has a domain of that class.

The user then makes a typo and includes the following in their data:

:subj a :InvalidType .

This is not in of itself inconsistent because RDF has an open world assumption. Stating that something has a type not covered by your RDF schema does not make validation fail, from a validation standpoint it's simply spurious information.

However if the user then stated that the :subj used your defined property like so:

:subj a :InvalidType ;
      :property "value" .

Now validation should return false because the data would be inconsistent with the schema, you stated that the :property only has domain :ValidType but it was used with a resource of type :InvalidType thus this is inconsistent and validation should fail.

RobV
  • 28,022
  • 11
  • 77
  • 119
  • Hi RobV, that always return true, even if I put a Resource with a wrong name for example the validation returns true. – awgustavo Oct 19 '12 at 18:12
  • In Jena we have to create resource with a defiene type . When I said "wrong name" actually I wanted to say with the name of the type different the name of the type in the RDFSchema. In this case a the rdf validation should returns false. – awgustavo Oct 19 '12 at 19:40
  • Please see my expanded answer which hopefully addresses your comment – RobV Oct 19 '12 at 20:23
  • unfortunately no. My problem is: I have a Schema like this: Switch... If I create a node in my file rdf with using "Swtich" written wrong, the validation method must return false. But this never happens. – awgustavo Oct 22 '12 at 10:52
  • As I explained in my answer above just spelling "Switch" wrong doesn't make your data invalid, it just makes it outside your schema. It seems like you are assuming RDF Schema functions the same way as XML Schema in that it is a strict validation - believe me it doesn't!! – RobV Oct 22 '12 at 15:49
  • So tell me. What I need to do to test if my model is valid or not? – awgustavo Oct 22 '12 at 15:59
1

Not strictly a solution via Jena, or via RDFS for that matter, but the information about Pellet's ICV capabilities (ported to Stardog, described here) might be useful. But as Rob says, it really comes down to the open vs. closed world thing, it makes it a bit tricky.

Michael
  • 4,858
  • 19
  • 32
1

I found the solution for validate a RDF with a RDF Schema. Exists a tool called CIMValidation. We can use this in a application java, just add the .jar to the buildpath and use the RDFSValidator class. Thanks for all answer.

awgustavo
  • 101
  • 1
  • 6
  • thank you for this possibly useful library. I was so far under impression that leaving XML world into RDF I am loosing any kind of schema definition. – kensai Nov 18 '17 at 16:22