## New API

I am working on a new release of Bossam. The upcoming release features a newly designed API. The new API exposes more interfaces for accessing the knowledge object model. You’ll be able to create and manipulate fact and rule objects, which will open better support for programming in rules.

The new Bossam operates in push model, like SAX. It pushes derivations and inconsistencies to the listeners that listen to the events generated from the reasoner. Creating a reasoner and executing a reasoning session looks as follows.

// Create a reasoner with the OWL reasoning capability
IReasonerFactory f = ReasonerFactory.getInstance();
IReasoner r = f.createReasoner(ModelType.OWL);
// Read an OWL document specified in N3 from a URL
"http://someplace.com/sample.n3");
// Set a listener for events from the reasoner
IReasonerListener l = new MyReasonerListener();
r.setReasonerListener(l);
// Execute a reasoning session.
// Derivations are pushed to the listener
r.run();

The reasoner listener interface has three methods:

• void onDerivation(IFact f): called when a new fact is derived.
• void onDerivation(IRule r): called when a new rule is derived.
• void onInconsistency(IExplanation e): called when an inconsistency is encountered.

As seen in the example code, it’s possible to specify the syntax and the content model when reading in knowledge. For example, if an OWL document specified in RDF/XML is given, it’s possible to read in the document in two ways: either as a plain RDF document or as an OWL document, as shown below.

• Read the document as a plain RDF document:
reasoner.read(ModelType.RDF, Syntax.RDFXML, "http://.....");
• Read the document as an OWL document:
reasoner.read(ModelType.OWL, Syntax.RDFXML, "http://....");

As such, the new Bossam release will come with new API set, which will not be compatible with the previous releases. Any opinions on the new API and the compatibility issue are welcomed.

The new release will also feature user-defined builtin functions and (limited but working) forgetting.

Stay tuned and let me know if you have any idea to be accompanied to the new release. Thanks!

Categories: bossam

## Be sure to add all the JAR files to your project.

When you build a Java application that uses bossam, you need to include all the JAR files distributed with bossam to the classpath of the Java application. You can find the JAR files under bin directory of the bossam release.

Categories: bossam

## An error in the code sample for RDF/OWL Ontology Querying fixed

I’ve just realized that the sample code I presented in my previous post has some error. The base namespace of the wine ontology is not correct in the code. I’ve just fixed it and the code correctly works!

Categories: bossam

## an exercise with math equations…

February 21, 2007 1 comment

I’ve just found out that I can write complex math equations using Latex syntax on WP. Here’s my first try:
$(K_{i}\varphi \wedge K_{i}(\varphi \Longrightarrow \psi)) \Longrightarrow K_{i}\psi$
Wow! Great! Learned this from this blog post.

Categories: rambling

## Representing and Processing Time & Dates

### Time Data Types

(Some of the features explained in this post are available in the next Bossam release.)

With Bossam, time data can be represented and processed. The following time types supported.

#### Date (corresponds to xsd:date)

• Syntax: yyyy-MM-dd
• Example: 2004-10-09

#### Time (corresponds to xsd:time)

• Syntax: HH:mm:ss
• Example: 22:10:30

#### DateTime (corresponds to xsd:dateTime)

• Syntax: yyyy-MM-dd'T'HH:mm:ss
• Example: 2004-10-09T22:10:30

#### Time Duration (corresponds to xsd:duration)

(refer to XSD Duration on how to write time durations)

• ex1) P10Y9M8DT10H9M8S represents 10 years 9 months 8 days 10 hours 9 minutes 8 seconds.
• ex2) P10Y8DT10H represents 10 years 8 days 10 hours.
• ex1) P10Y9M8D represents 10 years 9 months 8 days.
• ex1) PT10H9S represents 10 hours 9 seconds.

### Getting the Current Time/Date

Three builtin functions are available for getting the current time, current date, and current dateTime, as follows.
The namespace URI, http://www.etri.re.kr/2003/10/bossam-builtin#, is the reserved namespace for designating Bossam’s builtin functions. Let’s assume func corresponds to http://www.etri.re.kr/2003/10/bossam-builtin#.

• func:thisTime(): returns the current time
• func:thisDate(): returns the current date
• func:thisDateTime(): returns the current date-time

### Builtin Functions for Comparing Date/Time

There are three builtin functions for processing time data.

• func:after(time-const1,time-const2)
• returns true if time-const1 follows time-const2
• func:before(time-const1,time-const2)
• returns true if time-const1 precedes time-const2
• func:containedIn(time-const1,time-begin,time-end)
• returns true if time-const1 is in the duration formed by time-begin and time-end

A sample rulebase utilizing time constants is shown below.

prefix xsd = http://www.w3.org/2001/XMLSchema#;
prefix rdfs = http://www.w3.org/2000/01/rdf-schema#;
prefix func = http://www.etri.re.kr/2003/10/bossam-builtin#;
namespace is http://etri.re.kr/2003/10/Bossam#;
rulebase TimeConstants
{
class Person;
property birthdate for Person is xsd:date;
individual John is Person and birthdate = 1970-10-05;
individual Sam is Person and birthdate = 1970-05-05;

rule r1 is
if
birthdate(?x,?date1) and birthdate(?y,?date2)
and [func:after(?date1,?date2) = true]
then
isYoungerThan(?x,?y);

rule r2 is
if
birthdate(?x,?date1) and birthdate(?y,?date2)
and [func:before(?date1,?date2) = true]
then
isOlderThan(?x,?y);

fact f01 is beginsAt(MeetingA,2005-10-04T12:00:00);
fact f02 is endsAt(MeetingA,2005-10-04T15:00:00);
fact f03 is beginsAt(MeetingB,2005-10-04T14:00:00);
fact f04 is endsAt(MeetingB,2005-10-04T17:00:00);
fact f05 is beginsAt(MeetingC,2005-10-04T16:00:00);
fact f06 is endsAt(MeetingC,2005-10-04T17:00:00);

rule CompatibleMeetings is
if
endsAt(?m1,?t1) and beginsAt(?m2,?t2)
and [func:after(?t2,?t1) = true]
then
Compatible(?m1,?m2);
}

### Expressions on Time Data

Simple addition and subtraction on time and duration can be processed.

#### Calculating Time Difference

By subtracting a time from another time, it’s possible to calculate the difference between the two time points. Some examples follow:

• 2005-10-20 - 2005-09-10 gives P0Y0M40DT0H0M0S which is 40 days.
• 23:10:20 - 10:30:40 gives P0Y0M0DT12H39M40S which is 12 hours 39 minutes 40 seconds.
• 2007-12-31T24:00:00 - 2007-02-20T10:48:18 gives P0Y0M314DT13H11M42S which is 314 days 13 hours 11 minutes 42 seconds.

As such, it’s possible to get a time difference between two points in time.

#### Forwarding and Backwarding Times

By adding a duration to a time, we get a forwarded time. By subtracting a duration from a time, we get a bacwarded time. Addition examples follow:

• 0003-12-10 + P1Y1M1D gives 0005-01-11.
• 0003-12-10 + P13M9D gives 0005-01-19.
• 12:10:20 + PT1H1M1S gives 13:11:21.
• 12:10:20 + PT13H20M30S gives 01:30:50.
• 0003-12-10T12:10:20 + P1Y1M1DT1H1M1S gives 0005-01-11T13:11:21.
• 0003-12-10T12:10:20 + P1Y13M2DT13H20M30S gives 0006-01-13T01:30:50.

Subtraction examples follow:

• 0003-12-10 - P1Y1M1D gives 0002-11-09.
• 0003-12-10 - P13M9D gives 0002-11-01.
• 12:10:20 - PT1H1M1S gives 11:09:19.
• 12:10:20 - PT13H20M30S gives 22:49:50.
• 0003-12-10T12:10:20 - P1Y1M1DT1H1M1S gives 0002-11-09T11:09:19.
• 0003-12-10T12:10:20 - P1Y13M2DT13H20M30S gives 0001-11-07T22:49:50.

Some rule examples are as follows.

fact f is time(2002-10-10);
fact g is time(2002-12-31);
rule r is
if time(?t1) and time(?t2)
then result([?t1 - ?t2]);

fact f is time(2002-10-10);
fact g is duration(P10Y3M);
rule r is
if time(?t) and duration(?d)
then result([?t - ?d]);

fact f is time(12:30:00);
fact g is duration(PT1H30M);
rule r is
if time(?t) and duration(?d)
then result([?t + ?d]);

fact f is time(2002-10-10T12:30:00);
fact g is duration(P10DT1H30M);
rule r is
if time(?t) and duration(?d)
then result([?t - ?d]);
Categories: bossam, manual

## Creating OwlTrMReasoner

OwlTrMReasoner is a new OWL-DL reasoner added to Bossam. This reasoner is the most recommended OWL reasoner among the reasoners provided by Bossam. The following is the sample codes for creating and utilizing the reasoner.

// Create a reasoner
IReasonerFactory factory = ReasonerFactory.getInstance();
IReasoner r = factory.createOwlDlTrMReasoner();
// Perform a silent reasoning session,
//  which does not return conclusions
r.silentRun();
Categories: bossam, manual

## Rule Generating Rules

Bossam supports asserting rules at the consequent of rules. Here’s a simple example.

rule r is
if father(?x,?y)
then
assert if Man(?x) then hasChild(?x);

The pattern at the consequent part is called the rule template. Instead of deriving facts, RGRs generate rule instances from the rule templates.

I believe that RGR will be very useful for encoding dynamic & complex knowledge. Also, RGR is an essential tool for performance optimization because it’s possible to reduce the number of facts by utilizing RGRs.

Hope RGRs be of a useful toy for Bossam users!

Categories: bossam, manual