mulgara - semantic store

skip navigation

SHOW SITE NAV
fixed
fluid
straight

Consistency Checking

Consistency checking operations check that instances of data are consistent with a given schema.

 

Restricting Data Types

The owl:allValuesFrom and owl:someVauesFrom operations allow you to restrict the data types that a property refers to, for a given class.

 
owl:allValuesFrom

The owl:AllValuesFrom declaration restricts the use of a predicate (also called a property) on a particular class so that it can only refer to a given type of value. This is similar to the way that rdfs:range restricts a property to only refer to a given type. The difference is that rdfs:range applies whenever the property is used, while the owl:allValuesFrom restriction on a class only applies to properties of that particular class.

The camera ontology declares the following:

<owl:Class rdf:ID="Simple-Large-Format">
<rdfs:subClassOf rdf:resource="#Camera"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#body"/>
<owl:allValuesFrom rdf:resource="#BodyWithNonAdjustableShutterSpeed"/>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>

This means that Simple-Large-Format is a type of camera with an owl:allValuesFrom restriction placed upon it. Whenever this type of camera declares its body, then that body must be of type BodyWithNonAdjustableShutterSpeed.

An invalid camera might be defined as:

<rdf:Description rdf:about="&camera;badBody">
<rdf:type rdf:resource="#Simple-Large-Format"/>
<body>
<Body>
<shutter-speed rdf:parseType="Resource">
<min>0.01</min>
<max>1.0</max>
</shutter-speed>
</Body>
</body>
</rdf:Description>

The camera declared is named badBody (including the full &camera; namespace, its complete name is http://www.xfront.com/owl/ontologies/camera/#badBody), and it is a Simple-Large-Format camera. The problem is that it declares a body of type Body, but the ontology says that cameras of this type can only declare a body of type BodyWithNonAdjustableShutterSpeed.

To check for inconsistencies on this constraint, you can perform the following query:

select $s $p $x count (
select $object
from <rmi://mysite.com/server1#camera>
where $s $p $object
and $object <rdf:type> $type
and exclude($object $p2 $x )
)
from <rmi://mysite.com/server1#camera>
where $r <rdf:type> <owl:Restriction>
and $r <owl:onProperty> $p
and $r <owl:allValuesFrom> $x
and $c <rdfs:subClassOf> $r and $s <rdf:type> $c and $s $p $o2
having $k0 <mulgara:occursMoreThan> '0.0'^^<xsd:double>
order by $s;

This finds restrictions $r, which apply to a predicate $p, and restrict a subject to only have objects of type $x when this predicate is used. In the OWL example above, $r matches the restriction, while $p matches the body predicate, and $x is BodyWithNonAdjustableShutterSpeed.

Next, the query finds classes $c, which subclass this restriction. A more complete example can use walk($c <owl:subClassOf> $r) to be more thorough in finding all classes which ultimately inherit this restriction. Since restrictions are rarely removed any further than by a single sub-class relationship, a simple constraint like this finds the Simple-Large-Format class and places it in $c.

The last two constraints in the outer query find all instances of $c, and finds statements where these $s instances use the $p predicate defined in the restriction. The instance $s, the predicate $p, and the type $x that the restriction refers to, are all passed into the subquery.

The subquery looks for all statements where the instance of the required class uses the predicate to refer to an object, which it binds to $object. It then finds all statements which define the type for these objects, and excludes those objects whose type is the correct type for the restriction ($x). Unfortunately, excludes here is giving all statements in the camera model that do not match $object as a subject, and the type as the object. This is almost what is needed here, but there are some statements which should be excluded, that this constraint might allow through. This is a deficiency in iTQL that will be fixed in future versions of TKS. For now, it does finds all inconsistent statements, with only specialized cases being erroneously reported as inconsistent.

Any remaining statements have objects of the incorrect type, and violate the constraint. These remaining statements are counted, and the having clause checks to see if the number of violating rows is greater than 0. If so, this data gets returned from the query.

Any data returned from the query indicates an inconsistency in the data, according to the owl:allValuesFrom constraint.

For the invalid camera above, the result of the query is:

[ http://www.xfront.com/owl/ontologies/camera/#badBody, http://www.xfront.com/owl/ontologies/camera/#body,
http://www.xfront.com/owl/ontologies/camera/#BodyWithNonAdjustableShutterSpeed, 1.0 ]

This result indicates that the &camera;badBody object used the &camera;body predicate on a body that was not a &camera;BodyWithNonAdjustableShutterSpeed a total of 1 time. This showed up because the restriction required that &camera;body never be used to refer to the wrong type of body.

 
owl:someValuesFrom

The owl:someValuesFrom declaration restricts the use of a predicate (also called a property) on a particular class so that it must make at least one reference to a given type of value. This is similar to owl:allValuesFrom, but with the weaker requirement that only a single object be of the required type.

The camera ontology declares the following:

<owl:Class rdf:ID="Camera">
<rdfs:subClassOf rdf:resource="#PurchaseableItem"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#part"/>
<owl:someValuesFrom rdf:resource="#PurchaseableItem"/>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>
<owl:Class rdf:ID="CarryStrap">
<rdfs:subClassOf rdf:resource="#NonPurchaseableItem"/>
</owl:Class>

This means that if a camera has any parts, then at least one of those parts must be a PurchaseableItem. Note that this does not mean that a camera is forced to have any parts. The rule only applies when the part predicate is used on a camera.

The second class is a CarryStrap and is a type of NonPurchaseableItem. While a camera can have a carry strap as a part, this is not adequate on its own to meet the restriction on the Camera class.

An invalid camera would declare one or more parts, with none of them being PurchaseableItems. For example:

<rdf:Description rdf:about="&camera;badParts">
<rdf:type rdf:resource="#Camera"/>
<rdf:type rdf:resource="#Digital"/>
<part>
<CarryStrap/>
</part>
</rdf:Description>

This declares badParts as a digital camera. This camera has a single part, which is a carry strap. Since a part is declared, then at least one part must be a PurchaseableItem. Therefore, this camera violates the restriction.

Note that badParts is explicitly declared to be of type Camera. In a fully inferenced system, this declaration would be redundant, as it can be inferred from the fact that Digital is a sub-class of Camera. Since badParts is a type of Digital then it follows that it is also a type of Camera. Given that this documentation is describing a system that does not yet do automatic inferencing, it is necessary to include inferable statements like this.

 

To check for inconsistencies on this constraint, you can perform the following query:

select $s $p $x count(
select $o
from <rmi://mysite.com/server1#camera>
where $s $p $o
and $o <rdf:type> $x
)
from <rmi://mysite.com/server1#camera>
where $r <rdf:type> <owl:Restriction>
and $r <owl:onProperty> $p
and $r <owl:someValuesFrom> $x
and $c <rdfs:subClassOf> $r
and $s <rdf:type> $c
and $s $p $obj
having $k0 <mulgara:occursLessThan> '1.0'^^<xsd:double>;

This finds restrictions $r, which apply to a predicate $p, and restricts a subject to only have objects of type $x when this predicate is used. In the OWL example above, $r matches the restriction, while $p matches the part predicate, and $x is PurchaseableItem.

Next, the query finds classes $c, which subclass this restriction. A more complete example can use walk($c <owl:subClassOf> $r) to be more thorough in finding all classes which ultimately inherit this restriction, but this simpler form is adequate for most cases, including this example.

The last two constraints in the outer query find all instances of $c, and find statements where these $s instances use the $p predicate defined in the restriction. The instance $s, the predicate $p, and the type $x that the restriction refers to, are all passed into the subquery.

The subquery looks for all statements where the instance of the required class uses the predicate to refer to an object, which it binds to $o. It then finds all statements that define these objects to be of type $x, which is the required type in the restriction. The objects of the correct type are counted, and the having clause confirms that there is at least 1 of each. For any subjects of the restricted type (the type is Camera in this example), the restricted predicate is confirmed to be used correctly at least once. If not, then the count is 0, and the query returns the subject, predicate and missing type of the violated restriction.

Using this on data containing the badParts object, the result of the query is:

[ http://www.xfront.com/owl/ontologies/camera/#badParts, http://www.xfront.com/owl/ontologies/camera/#part,
http://www.xfront.com/owl/ontologies/camera/#PurchaseableItem, 0.0 ]

This shows that the &camera;badParts object had the &camera;part predicate used to refer to a &camera;PurchaseableItem 0 times. It showed up because the restriction required it to be used on &camera;PurchaseableItems at least once.

 

Cardinality Operations

The owl:cardinality, owl:minimumCardinality and owl:maximumCardinality declarations allow you to ensure that a given property occurs on an instance of a class. OWL-Lite provides the ability to express these three types of cardinality, but only with the values 0 and 1.

 
owl:cardinality

The camera ontology declares the following:

<owl:Class rdf:ID="BodyWithNonAdjustableShutterSpeed">
<rdfs:subClassOf rdf:resource="#Body"/>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#shutter-speed"/>
<owl:cardinality>0</owl:cardinality>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>

That is, if a camera's body has a non-adjustable shutter speed, it must not have a shutter speed.

So an invalid camera would be:

<rdf:Description rdf:about="&camera;brokenShutterCamera">
<rdf:type rdf:resource="#Large-Format"/>
<body>
<BodyWithNonAdjustableShutterSpeed>
<shutter-speed rdf:parseType="Resource">
<min>0.001</min>
<max>1.0</max>
</shutter-speed>
</BodyWithNonAdjustableShutterSpeed>
</body>
</rdf:Description>

This camera, &camera;brokenShutterCamera, has two values, min and max, for the shutter speed. The number of values is irrelevant. It is the fact that shutter-speed exists that is incorrect. The ontology specifies that the predicate, shutter-speed, is not allowed.

To check that this constraint is enforced, you can perform the following query:

select $s3 $s2 $p2 $v count (
select $o2
from <rmi://mysite.com/server1#camera>
where $s2 $p2 $o2 )
from <rmi://mysite.com/server1#camera>
where $s <rdf:type> <owl:Class>
and $s <rdfs:subClassOf> $r
and $r <rdf:type> <owl:Restriction>
and $r <owl:cardinality> $v
and $r <owl:onProperty> $p2
and $s2 $p3 $o2
and $s2 <rdf:type> $s
and $s3 $p4 $s2
having $k0 <mulgara:notOccurs> $v
order by $s3 ;

This finds all cardinality restrictions with a given cardinality value, $v, on a given property, $p2. This is then projected into the count where the number of predicates of a given subject are counted, and if this count is not equal to $v, then it displays the name of that camera, $s3.

The result of the query is:

[ http://www.xfront.com/owl/ontologies/camera/brokenShutter, _node281,
http://www.xfront.com/owl/ontologies/camera/#shutter-speed, 0, 1.0 ]

The first element in the result points to the name of the instance, the next two values, $s2 and $p2, are required in the subquery. The $v variable is required to put the variable value into the having constraint. The last value is how many times that predicate exists.

This can be used to display an error message such as:

"Error in cardinality constraint: http://www.xfront.com/owl/ontologies/camera/brokenShutter instance required 0
shutter-speed but was 1.0"

If a second camera instance exists, for example:

<rdf:Description rdf:about="&camera;shutterStutter">
<rdf:type rdf:resource="#Large-Format"/>
<body>
<BodyWithNonAdjustableShutterSpeed>
<shutter-speed rdf:parseType="Resource">
<min>0.01</min>
</shutter-speed>
<shutter-speed rdf:parseType="Resource">
<min>0.01</min>
</shutter-speed>
</BodyWithNonAdjustableShutterSpeed>
</body>
</rdf:Description>

The result of the query is:

[ http://www.xfront.com/owl/ontologies/camera/brokenShutter, _node158,
http://www.xfront.com/owl/ontologies/camera/#shutter-speed, 0, 1.0 ]
[ http://www.xfront.com/owl/ontologies/camera/shutterStutter, _node190,
http://www.xfront.com/owl/ontologies/camera/#shutter-speed, 0, 2.0 ]

 
owl:minimumCardinality

The following restriction, SLR, defines a camera that has a maximum cardinality on the property body of 1 and a minimum cardinality on the property lens:

<owl:Class rdf:ID="SLR">
<owl:subClassOf rdf:about="#Camera"/>
...
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#body"/>
<owl:maximumCardinality rdf:datatype="&xsd;double">1</owl:maximumCardinality>
</owl:Restriction>
</rdfs:subClassOf>
<rdfs:subClassOf>
<owl:Restriction>
<owl:onProperty rdf:resource="#lens"/>
<owl:minimumCardinality rdf:datatype="&xsd;double">1</owl:minimumCardinality>
</owl:Restriction>
</rdfs:subClassOf>
</owl:Class>

Considering each constraint separately, the minimum cardinality constraint indicates that there must be at least one lens for a camera. This allows multiple lenses but there must be at least one. An example of an instance of a camera that breaks this constraint is one that does not have a lens, for example:

<rdf:Description rdf:about="&camera;noLensSLR">
<rdf:type rdf:resource="#SLR"/>
<body>
<Body>
<shutter-speed rdf:parseType="Resource">
<min>0.01</min>
<max>1.0</max>
</shutter-speed>
</Body>
</body>
</rdf:Description>

To find the illegally constructed camera, you can perform the following query:

select $s2 $p2 $v count (
select $o2
from <rmi://mysite.com/server1#camera>
where $s2 $p2 $o2)
from <rmi://mysite.com/server1#camera>
where $s <rdf:type> <owl:Class>
and $s <rdfs:rdfs:subClassOf> $r
and $r <rdf:type> <owl:Restriction>
and $r <owl:minimumCardinality> $v
and $r <owl:onProperty> $p2
and $s2 $p3 $o2
and $s2 <rdf:type> $s
having $k0 <mulgara:occursLessThan> $v
order by $s2 ;

This finds all minimum cardinality restrictions with a given cardinality value, $v, on a given property, $p2. The joining of $s2 $p3 $o2 and $s2 <rdf:type> $s restricts what is projected into the count, to only the statements that are of the correct type, $s, and appear in the graph in order. When this is projected into the subquery, the number of predicates of a given subject are counted, and if this count is less than $v, then it is displayed with the value in $s2.

The result of the query is:

[ http://www.xfront.com/owl/ontologies/camera/noLensSLR, http://www.xfront.com/owl/ontologies/camera/#lens,
1.0, 0.0 ]

This shows the instance, http://www.xfront.com/owl/ontologies/camera/noLensSLR, has 0.0 counts for the predicate http://www.xfront.com/owl/ontologies/camera/#lens, which requires a value of at least 1.0.

 
owl:maximumCardinality

Using the same SLR example restriction definition given for owl:minimumCardinality, we are now only interested in the maximum cardinality restriction:

<owl:Class rdf:ID="SLR">
<owl:subClassOf rdf:about="#Camera"/>
...
<owl:Restriction>
<owl:onProperty rdf:resource="#body"/>
<owl:maximumCardinality rdf:datatype="&xsd;double">1</owl:maximumCardinality>
</owl:Restriction>
</rdfs:subClassOf>
...
</owl:Class>

This means that an SLR camera must have only one body. An example of an instance of a camera that breaks this restriction is as follows:

<rdf:Description rdf:about="urn:camera:binocularSLR">
<rdf:type rdf:resource="#SLR"/>
<body>
<Body>
<shutter-speed rdf:parseType="Resource">
<min>0.01</min>
<max>1.0</max>
<units>seconds</units>
</shutter-speed>
</Body>
</body>
<body>
<Body>
<shutter-speed rdf:parseType="Resource">
<min>0.01</min>
<max>1.0</max>
<units>seconds</units>
</shutter-speed>
</Body>
</body>
...
</rdf:Description>

To find this illegally constructed camera, you can perform the following query:

select $s2 $p2 $v count (
select $o2
from <rmi://mysite.com/server1#camera>
where $s2 $p2 $o2 )
from <rmi://mysite.com/server1#camera>
where $s <rdf:type> <owl:Class>
and $s <rdfs:subClassOf> $r
and $r <rdf:type> <owl:Restriction>
and $r <owl:maximumCardinality> $v
and $r <owl:onProperty> $p2
and $s2 $p3 $o2
and $s2 <rdf:type> $s
having $k0 <mulgara:occursMoreThan> $v
order by $s2 ;

This finds all maximum cardinality restrictions with a given cardinality value, $v, on a given property, $p2. Each of these results, such as 1 and #body respectively, are used to constrain the count. The predicate value, $p2, is used to query the graph and pass into the count $s2, $p2, $o2 triples. The count produces a value and this is constrained by the variable $v, 1 in this case by the having clause. If the predicate, #body appears more than once for any subject then it is displayed.

The result of the query is:

[ http://www.xfront.com/owl/ontologies/camera/binocularSLR, http://www.xfront.com/owl/ontologies/camera/#body,
1.0, 2.0 ]

This indicates that instance, http://www.xfront.com/owl/ontologies/camera/binocularSLR, is illegal as it has two predicates called body instead of one.

 

owl:Nothing

Available in next release.

 

owl:Restriction

Available in next release.

 

owl:Thing

Available in next release.

Valid XHTML 1.0 TransitionalValid CSS 3.0!