Reading restriction constraints using Jena

368 Views Asked by At

I have some object restrictions like

hasVendor some Vendor
hasYear some integer[minLength 2, maxLength 4, >=1995, <=2012]
hasPrice only string[pattern "/^[0-9]+(\.[0-9]{2})?$/"]

where Vendor is a Class. I followed the instructions from this link : https://stackoverflow.com/a/7805455/1138148 to read the restrictions. I need to get the constraint values from each of these restrictions using Jena. I was able to get 'Vendor' as the constraint in the first case, but for 2nd and 3rd I am getting some garbage like values like :

7cbf42c2:137784f42b4:-7d1f and 7cbf42c2:137784f42b4:-7d29 resp. What are these values? How can I retrieve the pattern as such and the values minLength, 1995 etc.

1

There are 1 best solutions below

2
On

Those are the bnode identifiers for the intermediate nodes in those restrictions. There's a lot more 'stuff' in the resulting data than is shown when it's serialized in Manchester syntax. You'll want to check out the OWL to RDF mappings document at the w3c to learn more about how that happens.

I don't suggest doing the validation yourself. If you're going to represent this stuff in OWL, you can use a reasoner to tell you when something has violated a restriction. That will work for the most part, but there are some pitfalls around open-world vs closed-world that you'll need to be aware of to really make this work. You can also look at something like Integrity Constraint Validation as offered by Pellet which lets you write constraints in OWL and applies closed-world semantics to them which gives a more natural (especially if you're coming from an RDBMS world) way of working with them.

But if you must handle the restrictions by hand, you're going to need to delve a little further into the underlying RDF structure of the restrictions to get the bits you're looking for, or use an API that's actually designed for working with OWL, such as OWLAPI.