The Semantic Web Rule Language (SWRL) is an expressive
OWL-based rule language. SWRL extends OWL syntax which allows users to
write rules with more powerful deductive reasoning capabilities than OWL alone.
SWRL built-ins are one of SWRL’s powerful features, which are predicates to be used
to manipulate data values in SWRL rules.

From the latest version, Fluent Editor supports a number of
core SWRL built-ins defined in SWRL Built-in Submission. In this post, we will introduce two examples
of applying some of SWRL core built-ins to your CNL ontology.

### Using Simple Built-in Comparison

Here, we will use a short ontology template which uses a couple of built-ins to express simple rent comparison. To open it, go to New page and type 'Rent Comparison'. A green template icon will appear. Click it.

Then let's take a look at the template. First, we define a tenant has three data values....

Then let's take a look at the template. First, we define a tenant has three data values....

Every tenant pays-monthly-rent (some integer value).

Every tenant has-rental-flat-size (some integer value).

Every tenant lives-in-area (some string value).

... and some tenant instances.

Tom is a tenant and has-rental-flat-size equal-to 65 and pays-monthly-rent equal-to 2000 and lives-in-area equal-to

*'New York'*.
John is a tenant and has-rental-flat-size equal-to 60 and pays-monthly-rent equal-to 2500 and lives-in-area equal-to

*'New York'*.
Mary is a tenant and has-rental-flat-size equal-to 85 and pays-monthly-rent equal-to 2500 and lives-in-area equal-to

*'Florida'*.
Anna is a
tenant and has-rental-flat-size equal-to 60 and pays-monthly-rent equal-to 1800 and
lives-in-area equal-to

*'Georgia'*.
Then we add three rules defined for comparing rent using those data values. Each of the rules contains different built-ins as follows :

The first rule describes how to calculate rental price per flat size, which simply means: rental price per apartment size = total monthly rental price / flat sizeIf a tenant pays-monthly-rent equal-to the value(1) and the tenant has-rental-flat-size equal-to the value(2) and the value(1) divided-by the value(2) = the value (3) then the tenant pays-monthly-rent-per-size equal-to the value (3).If a tenant(1) pays-monthly-rent-per-size equal-to the value(1) and a tenant(2) pays-monthly-rent-per-size equal-to the value(2) and the value (1) < the value (2) then the tenant(1) lives-in-a-cheaper-flat-than the tenant(2).If a tenant(1) lives-in-a-cheaper-flat-than the tenant(2) and the tenant(1) lives-in-area equal-to the value(3) and the tenant(2) lives-in-area equal-to the value(4) and the value(3) <> the value(4) then the tenant(1) lives-in-a-cheaper-area-than the tenant(2).

Here you can see that an SWRL built-in swrlb:divide is represented as a keyword divided-by, taking two operands : the value (1) and the value (2). The result value is assigned to the new value, the value (3) . Once you assign some data to this new value, you can apply it to some other properties, such as pays-monthly-rent-per-size.

The second rule is a straightforward comparison of rental price between tenants, which is expressed by using a keyword '< ', an equivalent of built-in swrlb:lessThan.

The last one is comparing both rental price per flat size and the area where tenants live, to calculate which area is more expensive. A keyword '<>' is used that represents swrlb:notEqual to check that the area names are different.

To check how these rules with built-ins work, you can get back the full results in three ways as follows:

1. Querying on Materialized Graph.

1. Querying on Materialized Graph.

2. Querying on SPARQL window.

### Expressing Solar System Data Using Built-ins

The next ontology is expressing solar system data on the orbits of the planets and moons along with some historical data. To express the data we can also make use of SWRL built-ins. First we can open the template 'Solar System' and take a look at the rules there.

For example, this rule involves several math built-ins. It calculates orbits which are elliptic.

The built-in keywords here look exactly the same as mathematical signs. '+' is equivalent to swrlb:add, '-' to swrlb:subtract, and '*' to swrlb:multiply, If you break down the rule as below...If a thing has-semimajor-axis-1000-km equal-to the value(1) and the thing has-eccentricity equal-to the value(2) and 1.0 - the value(2) = the value(3) and 1.0 + the value(2) = the value(4) and the value(1) * the value(3) = the value(5) and the value(1) * the value(4) = the value(6) then the thing has-peryhelium-1000-km equal-to the value(5) and the thing has-aphelium-1000-km equal-to the value(6).

value(1) = has-semimajor-axis-1000-km

value(2) = eccentricity

value(3) = 1.0 - eccentricity

value(4) = 1.0 + eccentricity

value(5) = has-semimajor-axis-1000-km * (1.0 - eccentricity)

value(6) = has-semimajor-axis-1000-km * (1.0 + eccentricity)

...it concludes that this rule is defining two equations.

peryhelium = (1 - eccentricity) * semimajor-axis

aphelium = (1 +
eccentricity) * semimajor-axis

Here is another rule comparing orbit sizes (ellipse) of two different planets that orbit the same thing.

It compares if planetA's value of peryhelium-1000-km is less than planetB's value of aphelium-1000-km, to conclude that if one makes a bigger ellipse then it covers the other.If a thing(2) orbits the thing(1) and a thing(3) orbits the thing(1) and the thing(2) is-not-the-same-as the thing(3) and the thing(2) has-peryhelium-1000-km equal-to the value(1) and the thing(3) has-aphelium-1000-km equal-to the value(2) and the value(1) < the value(2) then the thing(2) is covered by the thing(3).

Let's add a couple of planet instances to see how the rules would work.

Then query on Materialized Graph.Sun is a star.Mercury has-index equal-to'I'and orbits Sun and has-semimajor-axis-1000-km equal-to 57910 and has-period equal-to 87.97 and has-eccentricity equal-to 0.21.Venus has-index equal-to'II'and orbits Sun andhas-semimajor-axis-1000-km equal-to 108200 and has-period equal-to 224.70 and has-eccentricity equal-to 0.01.

Among the results you will find the derived knowledge that Mercury is covered by Venus.

### More Resources:

```
```

```
```

## No comments:

## Post a comment