Skip to content

SWRLAPISWRLSyntax

Martin O'Connor edited this page Jun 26, 2017 · 13 revisions

This FAQ describes the presentation syntax for SWRL supported by the SWRLAPI. A general introduction to the SWRL language can be found here.

Table of Contents

How are conjunction and implication symbols represented?

The conjunction symbol is represented by the ^ character. The implication symbol can be entered using the -> character pair.

How are rule variables represented?

A variable is written as an identifier preceded by a ? character. Example variables are:

    ?myVariable
    
    ?x2

In the SWRLAPI, a variable name may not be the same as the name of an OWL class, property, individual or datatype in the same ontology.

Only variables that occur in the antecedent of a rule may occur in the consequent (a condition usually referred to as "safety").

A variable is scoped to its rule only so variable names are only required to be unique per rule. So two variable with the same name in different rules will not be related.

How are OWL classes, properties, and individuals referred to?

By default, OWL classes, properties, and individuals are referred to directly using the short form of their underlying OWL name (as stored in the rdf:ID or rdf:About attributes in OWL's RDF serialization, for example).

Example classes are:

    Person
    careers:Pilot

Properties could be:

    hasBrother
    books:hasAuthor

hasSibling

Example individuals are:

    Fred
    collaborators:Mary

In many OWL ontologies, however, the underlying OWL name is not meaningful and instead the value of an annotation property (e.g., rdf:label) contains a user-friendly name for a particular entity. These annotation values can be used in rules by enclosing them in single quotes.

For example, if the class Person has a selected annotation property value of 'a Person' the Person class would then be referred to in rules as follows:

    'a Person'

The approach is the same when referring to both properties and individuals using annotation values.

A description of how to specify annotation values for OWL entities in Protege-OWL can be found here.

Note that annotation-based references are not supported in the current release of the SWRLAPI.

How are literals represented?

Numeric literals are simply typed as is. Basic types such as integers, longs, floats and doubles are supported in addition to a selection of XML Schema datatypes. The Boolean values true and false are represented using the values "true" and "false". Case is not significant for Boolean values. All other literals must be enclosed in quotation marks. Example literals include:

    34
    4.45
    -34
    True
    false
    ""
    "a literal"

Literals may also be qualified by their XML Schema datatypes. All such datatypes must be preceded by the namespace qualifier ```xsd:```.

Example datatypes include:

    xsd:unsignedInt
    xsd:string

A literal can be qualified by a datatype by enclosing the literal in quotes and following it by the the character pair "^^" and the datatype name. Example qualified literals include:

    "34"^^xsd:unsignedInt
    "a literal"^^xsd:string

How are SWRL class atoms represented?

Class atoms are constructed from an OWL class name followed by one variable or individual name in parenthesis. Example class atoms are:

    Man(?x)
    Woman(Mary)

If used in the antecedent of a rule, a class atom is used to determine if the variable or individual parameter is a member of the specified OWL class. If used in a rule consequent, it is used to classify individuals to be members of the specified class.

The SWRL Submission also allows arbitrary OWL expressions to be used instead of a class name in class atoms. The SWRL Editor does not currently support use of these expressions.

How are SWRL individual property atoms represented?

Individual property atoms are constructed from an OWL object property name followed by two arguments in parenthesis. Each parameter is either a variable or individual name. An example individual property atom is:

    hasChild(?x, ?y)

Other example individual property atoms are:

    hasParent(Fred, ?x2)
    hasNephew(?x1, ?x3)

How are SWRL datavalued property atoms represented?

Datavalued property atoms are represented in the same way as individual property atoms. They are constructed from a OWL datatype property name followed by two arguments in parenthesis. The second argument is either a variable representing a data value or a literal value itself. Example data valued property atoms are:

    hasAge(Mary, 10)
    hasName(?x1, ?x2)  
    hasName(?x1, "Freddy")

How are SWRL different individuals and same individual atoms represented?

These atoms are constructed from the tokens differentFrom and sameAs followed by two arguments in parenthesis. Example atoms are:

sameAs(?x, ?y)

differentFrom(?x, Mary)

For example, a rule that indicates that individuals are cooperators if they are co-authors on a paper can be written as follows:

    Publication(?a) ^ hasAuthor(?x, ?y) ^ hasAuthor(?x, ?z) ^ differentFrom(?y, ?z) 
    -> cooperatedWith(?y, ?z)

How are SWRL built-in atoms represented?

SWRL built-ins are predicates that accept one or more data valued arguments. A number of core built-ins for mathematical and string operations are contained in the SWRL Built-in Proposal. These built-ins are defined in the file swrlb.owl, which has the namespace http://www.w3.org/2003/11/swrlb.

By convention, all core SWRL built-ins are preceded by the namespace qualifier swrlb.

Example built-in atoms include:

    swrlb:lessThan(?x, 10)
    swrlb:equals(?x, ?y)

An example SWRL rule using a built-in to indicate that a person with an age of greater than 17 is an adult is:

    Person(?p) ^ hasAge(?p, ?age) ^ swrlb:greaterThan(?age, 17) -> Adult(?p)

When executed, this rule would classify individuals of class Person with an hasAge property value of greater than 17 as members of the class Adult.

How are OWL class descriptions represented?

OWL class descriptions are not supported in the current release of the SWRLAPI.

OWL class descriptions as represented by writing the OWL class description in parenthesis followed by a single individual argument.

For example, a rule that classifies an individuals as a parent if it is a member of a class with a hasChild property defined on it with a minimum cardinality is one can be written as follows:

    (hasChild >= 1)(?x) -> Parent(?x)

How are data range atom represented?

Data range atoms are not supported in the current release of the SWRLAPI.

Data range atoms have two forms: (1) a datatype name followed by a variable or literal in parenthesis, and (2) a list of brackets-enclosed comma-separated literals followed by a variable or literal in parenthesis.

An example of the first form is:

    xsd:unsignedInt(?x)

which asserts that variable x must be a literal with type unsigned integer.

Other examples of this form are:

    xsd:double("3.3"^^xsd:double)
    
    xsd:string(?y)
    
    xsd:normalizedString("a string")

An example of the second form of a data range atom is:

    ["34.4"^^xsd:double, "32.1"^^xsd:double, "44.5"^^xsd:double](?x)

which asserts that variable x must be a literal of type xsd:double with value 34.4, 32.1 or 44.5.

Other examples of this form are:

    ["red", "green", "blue"](?x)
    
    ["red"^^xsd:string, "green"^^xsd:string, "blue"^^xsd:string](?x)
    
    ["34.4"^^xsd:double, "32.1"^^xsd:double, "44.5"^^xsd:double](?x)