Referencing RDF, RDFS, and OWL Concepts in Expressions

Last revised 7/30/2021. Contact us.

The SADL grammar includes controlled-English syntax to represent certain concepts from the RDF, RDFS, and OWL models. For example, the following SADL statements result in RDF/XML statements that include the highlighted concepts from the RDF, RDFS, or OWL ontologies.

However, in some circumstances it may be desirable to be able to reference a concept from an ontology such as RDF, RDFS, or OWL directly. This happens when using such a concept as an argument to a function or in an expression in a rule, test, or query. For example, the function countMatches takes the subjects, predicates, and objects of triple patterns as arguments. Suppose one wanted to count the number of instances of Cat in a model. One could do so with a rule1:

     Rule CountCats: if x is a Cat1 and nc = countMatches(y, rdf:type, Cat)
                   then print("There are ", nc, " cats in the model.").

Note, however, that "rdf:type" is a variable, as indicated by its color, and that it is unbound. Hence the rule will not fire. The model needs to resolve "rdf:type" to a property in the "http://www.w3.org/1999/02/22-rdf-syntax-ns" namespace. One could download the RDF ontology and import it into the model containing the CountCats rule. One could also create a subset of RDF and import that. Taking this approach, we create this simple model. Note that the namespace and prefix of the model correspond exactly to those expected for the RDF ontology.

uri "http://www.w3.org/1999/02/22-rdf-syntax-ns" alias rdf.

^type is a property.

Now we can add an import to our model containing the rule:

uri "http://sadl.org/examples.sadl" alias examples.

import "http://www.w3.org/1999/02/22-rdf-syntax-ns" .

Cat is a class.

Rule CountCats: if x is a Cat1 and nc = countMatches(y, rdf:type, Cat)
                then print("There are ", nc, " cats in the model.").

Note that now the argument "rdf:type" is known to be an RDF property, as indicated by its coloring, and the rule will work as expected. A similar approach can be adopted to use selected concepts from RDF, RDFS, OWL, or any other ontology commonly referenced in semantic models.

1Note that this rule has the apparently unrelated body pattern "x is a Cat". Without some kind of non-function rule body statement, the inferred graph on which the function operates will not be populated. This seems to be a characteristic of the Jena Reasoner.