Question

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.

Était-ce utile?

La solution 3

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.

Autres conseils

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.

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top